Turn on upper-snake-string-unions and convert profile types, failure reasons and anchor sides at their boundaries

This commit is contained in:
Danny Kim
2026-10-19 19:46:31 +09:00
parent 71150900ff
commit c783935936
13 changed files with 144 additions and 113 deletions
+9 -9
View File
@@ -16,7 +16,7 @@ export interface PostContext {
interface Anchor {
path: string;
line: number;
side: "new" | "old";
side: "NEW" | "OLD";
body: string;
}
@@ -26,8 +26,8 @@ const VERDICTS = new Map<string, [event: string, mark: string]>([
["Approved", ["APPROVED", "✅"]],
["Changes requested", ["REQUEST_CHANGES", "🛑"]],
]);
const PROFILE_TYPES = new Set<unknown>(["claude", "codex", "opencode"]);
const FAILURE_REASONS = new Set<unknown>(["sign-in failed", "usage exhausted", "failed"]);
const PROFILE_TYPES = new Set<unknown>(["CLAUDE", "CODEX", "OPENCODE"]);
const FAILURE_REASONS = new Set<unknown>(["SIGN_IN_FAILED", "USAGE_EXHAUSTED", "FAILED"]);
const isProfileType = (value: unknown): value is ProfileFailure["type"] => PROFILE_TYPES.has(value);
const isFailureReason = (value: unknown): value is FailureReason => FAILURE_REASONS.has(value);
const failureComment = (failures: ProfileFailure[]): string =>
@@ -56,7 +56,7 @@ function parseAnchors(text: string, sourcePath: string): Anchor[] {
const path = field(entry, "path");
const line = field(entry, "line");
const givenSide = field(entry, "side");
const side = givenSide === undefined ? "new" : givenSide;
const side = givenSide === undefined ? "NEW" : givenSide;
const body = field(entry, "body");
if (typeof path !== "string" || path === "") {
throw new TypeError(`${at}.path: expected a repository path`);
@@ -64,8 +64,8 @@ function parseAnchors(text: string, sourcePath: string): Anchor[] {
if (typeof line !== "number" || !Number.isInteger(line) || line < 1) {
throw new TypeError(`${at}.line: expected a line number`);
}
if (side !== "new" && side !== "old") {
throw new Error(`${at}.side: expected "new" or "old"`);
if (side !== "NEW" && side !== "OLD") {
throw new Error(`${at}.side: expected "NEW" or "OLD"`);
}
if (typeof body !== "string" || body.trim() === "") {
throw new TypeError(`${at}.body: expected the finding`);
@@ -216,8 +216,8 @@ export async function postRuntime(
comments: entries.map(({ path, line, side, body }) => ({
path,
body: stripAnsi(withProfile(body, outcome.profile)),
new_position: side === "new" ? line : 0,
old_position: side === "old" ? line : 0,
new_position: side === "NEW" ? line : 0,
old_position: side === "OLD" ? line : 0,
})),
});
};
@@ -234,7 +234,7 @@ export async function postRuntime(
if (error instanceof GiteaRequestError) {
throw error;
}
await postComment(failureComment([{ ...outcome.profile, reason: "failed" }]));
await postComment(failureComment([{ ...outcome.profile, reason: "FAILED" }]));
throw error;
}
} finally {