Skip to content

Commit

Permalink
Refactor internal function names (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger authored Feb 6, 2025
1 parent 097d525 commit a7b1296
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
14 changes: 7 additions & 7 deletions dist/ruff-action/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/ruff-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
version,
versionFile as versionFileInput,
} from "./utils/inputs";
import { getRuffVersionFromPyproject } from "./utils/pyproject";
import { getRuffVersionFromRequirementsFile } from "./utils/pyproject";
import * as fs from "node:fs";

async function run(): Promise<void> {
Expand Down Expand Up @@ -93,7 +93,8 @@ async function determineVersion(): Promise<string> {
return await resolveVersion(version, githubToken);
}
if (versionFileInput !== "") {
const versionFromPyproject = getRuffVersionFromPyproject(versionFileInput);
const versionFromPyproject =
getRuffVersionFromRequirementsFile(versionFileInput);
if (versionFromPyproject === undefined) {
core.warning(
`Could not parse version from ${versionFileInput}. Using latest version.`,
Expand All @@ -106,7 +107,8 @@ async function determineVersion(): Promise<string> {
core.info(`Could not find ${pyProjectPath}. Using latest version.`);
return await resolveVersion("latest", githubToken);
}
const versionFromPyproject = getRuffVersionFromPyproject(pyProjectPath);
const versionFromPyproject =
getRuffVersionFromRequirementsFile(pyProjectPath);
if (versionFromPyproject === undefined) {
core.warning(
`Could not parse version from ${pyProjectPath}. Using latest version.`,
Expand Down
10 changes: 6 additions & 4 deletions src/utils/pyproject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as fs from "node:fs";
import * as core from "@actions/core";
import * as toml from "smol-toml";

function parseRequirements(allDependencies: string[]): string | undefined {
function getRuffVersionFromAllDependencies(
allDependencies: string[],
): string | undefined {
const ruffVersionDefinition = allDependencies.find((dep: string) =>
dep.startsWith("ruff"),
);
Expand Down Expand Up @@ -38,12 +40,12 @@ function parsePyproject(pyprojectContent: string): string | undefined {
)
.flat()
.filter((item: string | object) => typeof item === "string");
return parseRequirements(
return getRuffVersionFromAllDependencies(
dependencies.concat(optionalDependencies, devDependencies),
);
}

export function getRuffVersionFromPyproject(
export function getRuffVersionFromRequirementsFile(
filePath: string,
): string | undefined {
if (!fs.existsSync(filePath)) {
Expand All @@ -52,7 +54,7 @@ export function getRuffVersionFromPyproject(
}
const pyprojectContent = fs.readFileSync(filePath, "utf-8");
if (filePath.endsWith(".txt")) {
return parseRequirements(pyprojectContent.split("\n"));
return getRuffVersionFromAllDependencies(pyprojectContent.split("\n"));
}
try {
return parsePyproject(pyprojectContent);
Expand Down

0 comments on commit a7b1296

Please sign in to comment.