Refactor internal function names (#76)

This commit is contained in:
Kevin Stillhammer
2025-02-06 17:51:03 +01:00
committed by GitHub
parent 097d5252c8
commit a7b1296fb5
3 changed files with 18 additions and 14 deletions
+5 -3
View File
@@ -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> {
@@ -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.`,
@@ -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.`,
+6 -4
View File
@@ -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"),
);
@@ -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)) {
@@ -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);