Skip to content

Commit 8e9552d

Browse files
committed
refactor: change fetching check runs module to not depend on inputs
1 parent 5127621 commit 8e9552d

4 files changed

Lines changed: 71 additions & 37 deletions

File tree

dist/index.js

Lines changed: 29 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/fetch-check-runs.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
import * as github from "@actions/github";
22
import type { components } from "@octokit/openapi-types";
3-
import { inputs } from "./inputs";
43
import { RelevantCheckRuns } from "./relevant-check-runs";
4+
import { GitHub } from "@actions/github/lib/utils";
55

66
export type CheckRun = components["schemas"]["check-run"];
77

8-
const octokit = github.getOctokit(inputs.token);
8+
export class CheckRunFetcher {
9+
private octokit: InstanceType<typeof GitHub> | null = null;
910

10-
export const fetchCheckRuns = async (): Promise<RelevantCheckRuns> => {
11-
const iterator = octokit.paginate.iterator(octokit.rest.checks.listForRef, {
12-
...github.context.repo,
13-
ref: inputs.ref,
14-
per_page: 100,
15-
});
11+
constructor(
12+
private token: string,
13+
private ref: string,
14+
private ownName: string,
15+
private ignoredChecks: Set<string>,
16+
) {}
1617

17-
let runs: CheckRun[] = [];
18+
async fetch(): Promise<RelevantCheckRuns> {
19+
this.octokit ??= github.getOctokit(this.token);
1820

19-
for await (const { data } of iterator) {
20-
runs = runs.concat(data);
21-
}
21+
const iterator = this.octokit.paginate.iterator(
22+
this.octokit.rest.checks.listForRef,
23+
{
24+
...github.context.repo,
25+
ref: this.ref,
26+
per_page: 100,
27+
},
28+
);
29+
30+
let runs: CheckRun[] = [];
2231

23-
return new RelevantCheckRuns(
24-
runs.filter(
25-
(run) => run.name !== inputs.name && !inputs.ignored.has(run.name),
26-
),
27-
);
28-
};
32+
for await (const { data } of iterator) {
33+
runs = runs.concat(data);
34+
}
35+
36+
return new RelevantCheckRuns(
37+
runs.filter(
38+
(run) => run.name !== this.ownName && !this.ignoredChecks.has(run.name),
39+
),
40+
);
41+
}
42+
}

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from "@actions/core";
22
import { delay } from "./delay";
3-
import { fetchCheckRuns } from "./fetch-check-runs";
3+
import { CheckRunFetcher } from "./fetch-check-runs";
44
import { inputs } from "./inputs";
55
import { Display } from "./display";
66

@@ -17,10 +17,17 @@ Display.ignoredCheckNames(inputs.ignored);
1717

1818
const waitForCheckRuns = async (): Promise<void> => {
1919
try {
20+
const checkRunFetcher = new CheckRunFetcher(
21+
inputs.token,
22+
inputs.ref,
23+
inputs.name,
24+
inputs.ignored,
25+
);
26+
2027
while (!shouldTimeOut()) {
2128
Display.startingIteration();
2229

23-
const checkRuns = await fetchCheckRuns();
30+
const checkRuns = await checkRunFetcher.fetch();
2431

2532
if (checkRuns.total() === 0) {
2633
Display.delaying(inputs.interval);

0 commit comments

Comments
 (0)