All files / infrastructure/scripts/src/ci-failures/adapters gh.ts

0% Statements 0/12
0% Branches 0/4
0% Functions 0/5
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                                                                     
import { assertNotFlagLike } from "../../shared/adapters/exec.ts";
import { gh } from "../../shared/adapters/gh.ts";
import { detailOf } from "../../shared/domain/cli.ts";
import { ExpectedError } from "../../shared/errors.ts";
import type { Check } from "../domain/checks.ts";
 
/** No PR argument means the current branch's PR, which is how `gh` itself defaults. */
const prArgs = (pr: string | undefined): string[] => (pr ? [assertNotFlagLike(pr, "PR")] : []);
 
const ask = (args: string[]): string => {
    try {
        return gh(...args);
    } catch (error) {
        throw new ExpectedError(detailOf(error) ?? String(error));
    }
};
 
export const prTitle = (pr: string | undefined): string =>
    ask([
        "pr",
        "view",
        ...prArgs(pr),
        "--json",
        "number,title",
        "--jq",
        String.raw`"#\(.number) \(.title)"`,
    ]);
 
/** With `--json`, `gh pr checks` exits 0 whatever the checks concluded. */
export const prChecks = (pr: string | undefined): Check[] =>
    JSON.parse(
        ask([
            "pr",
            "checks",
            ...prArgs(pr),
            "--json",
            "name,bucket,state,link,workflow,description",
        ]),
    ) as Check[];
 
export const failedLog = (run: string, job: string): string =>
    ask(["run", "view", run, "--job", job, "--log-failed"]);