Skip to content

Commit 63b0049

Browse files
committed
[github.js] Remove check, status, and workflow helpers
1 parent 601180f commit 63b0049

File tree

2 files changed

+2
-262
lines changed

2 files changed

+2
-262
lines changed

.github/workflows/src/github.js

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { PER_PAGE_MAX } from "../../shared/src/github.js";
21
import { toPercent } from "../../shared/src/math.js";
3-
import { byDate, invert } from "../../shared/src/sort.js";
42
import { Duration, formatDuration, getDuration, subtract } from "../../shared/src/time.js";
53

64
/**
@@ -24,83 +22,6 @@ export async function writeToActionsSummary(content, core) {
2422
}
2523
}
2624

27-
/**
28-
* Returns the check with the given checkRunName for the given ref.
29-
* @param {import('@actions/github-script').AsyncFunctionArguments['github']} github
30-
* @param {import('@actions/github-script').AsyncFunctionArguments['context']} context
31-
* @param {string} checkRunName
32-
* @param {string} ref
33-
* @returns {Promise<CheckRuns>}
34-
*/
35-
export async function getCheckRuns(github, context, checkRunName, ref) {
36-
const result = await github.paginate(github.rest.checks.listForRef, {
37-
...context.repo,
38-
ref: ref,
39-
check_name: checkRunName,
40-
status: "completed",
41-
per_page: PER_PAGE_MAX,
42-
});
43-
44-
/* v8 ignore next */
45-
return result.sort(
46-
invert(
47-
byDate((run) => {
48-
if (run.completed_at === null) {
49-
// completed_at should never be null because status is "completed"
50-
throw new Error(`Unexpected value of run.completed_at: '${run.completed_at}'`);
51-
} else {
52-
return run.completed_at;
53-
}
54-
}),
55-
),
56-
);
57-
}
58-
59-
/**
60-
* Returns the check with the given checkRunName for the given ref.
61-
* @param {import('@actions/github-script').AsyncFunctionArguments['github']} github
62-
* @param {import('@actions/github-script').AsyncFunctionArguments['context']} context
63-
* @param {string} commitStatusName
64-
* @param {string} ref
65-
* @returns {Promise<CommitStatuses>}
66-
*/
67-
export async function getCommitStatuses(github, context, commitStatusName, ref) {
68-
const result = await github.paginate(github.rest.repos.listCommitStatusesForRef, {
69-
...context.repo,
70-
ref: ref,
71-
per_page: PER_PAGE_MAX,
72-
});
73-
74-
return result
75-
.filter(
76-
(status) =>
77-
// Property "context" is case-insensitive
78-
status.context.toLowerCase() === commitStatusName.toLowerCase(),
79-
)
80-
.sort(invert(byDate((status) => status.updated_at)));
81-
}
82-
83-
/**
84-
* Returns the workflow run with the given workflowName for the given ref.
85-
* @param {import('@actions/github-script').AsyncFunctionArguments['github']} github
86-
* @param {import('@actions/github-script').AsyncFunctionArguments['context']} context
87-
* @param {string} workflowName
88-
* @param {string} ref
89-
* @returns {Promise<WorkflowRuns>}
90-
*/
91-
export async function getWorkflowRuns(github, context, workflowName, ref) {
92-
const result = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
93-
...context.repo,
94-
head_sha: ref,
95-
status: "completed",
96-
per_page: PER_PAGE_MAX,
97-
});
98-
99-
return result
100-
.filter((run) => run.name === workflowName)
101-
.sort(invert(byDate((run) => run.updated_at)));
102-
}
103-
10425
/**
10526
* @param {import("@octokit/endpoint").endpoint} endpoint
10627
* @param {import('../../shared/src/logger.js').ILogger} logger

.github/workflows/test/github.test.js

Lines changed: 2 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,11 @@
11
import { afterEach } from "node:test";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
33
import { add, Duration } from "../../shared/src/time.js";
4-
import {
5-
createLogHook,
6-
createRateLimitHook,
7-
getCheckRuns,
8-
getWorkflowRuns,
9-
writeToActionsSummary,
10-
} from "../src/github.js";
11-
import { createMockContext, createMockCore, createMockGithub, createMockLogger } from "./mocks.js";
4+
import { createLogHook, createRateLimitHook, writeToActionsSummary } from "../src/github.js";
5+
import { createMockCore, createMockLogger } from "./mocks.js";
126

137
const mockCore = createMockCore();
148

15-
describe("getCheckRuns", () => {
16-
it("returns matching check_run", async () => {
17-
const githubMock = createMockGithub();
18-
githubMock.rest.checks.listForRef.mockResolvedValue({
19-
data: {
20-
check_runs: [
21-
{
22-
name: "checkRunName",
23-
status: "completed",
24-
conclusion: "success",
25-
},
26-
],
27-
},
28-
});
29-
30-
const actual = await getCheckRuns(githubMock, createMockContext(), "checkRunName", "head_sha");
31-
32-
expect(actual).toEqual([
33-
expect.objectContaining({
34-
name: "checkRunName",
35-
status: "completed",
36-
conclusion: "success",
37-
}),
38-
]);
39-
});
40-
41-
it("returns null when no check matches", async () => {
42-
const githubMock = createMockGithub();
43-
githubMock.rest.checks.listForRef.mockResolvedValue({
44-
data: {
45-
check_runs: [],
46-
},
47-
});
48-
49-
const actual = await getCheckRuns(githubMock, createMockContext(), "checkRunName", "head_sha");
50-
51-
expect(actual).toEqual([]);
52-
});
53-
54-
it("throws when multiple checks match", async () => {
55-
const githubMock = createMockGithub();
56-
const earlierDate = "2025-04-01T00:00:00Z";
57-
const laterDate = "2025-04-02T00:00:00Z";
58-
githubMock.rest.checks.listForRef.mockResolvedValue({
59-
data: {
60-
check_runs: [
61-
{
62-
name: "checkRunName",
63-
status: "completed",
64-
conclusion: "success",
65-
completed_at: earlierDate,
66-
},
67-
{
68-
name: "checkRunName",
69-
status: "completed",
70-
conclusion: "success",
71-
completed_at: laterDate,
72-
},
73-
],
74-
},
75-
});
76-
77-
const actual = await getCheckRuns(githubMock, createMockContext(), "checkRunName", "head_sha");
78-
79-
expect(actual).toEqual([
80-
expect.objectContaining({
81-
name: "checkRunName",
82-
status: "completed",
83-
conclusion: "success",
84-
completed_at: laterDate,
85-
}),
86-
expect.objectContaining({
87-
name: "checkRunName",
88-
status: "completed",
89-
conclusion: "success",
90-
completed_at: earlierDate,
91-
}),
92-
]);
93-
});
94-
});
95-
96-
describe("getWorkflowRuns", () => {
97-
it("returns matching workflow_run", async () => {
98-
const githubMock = createMockGithub();
99-
githubMock.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({
100-
data: {
101-
workflow_runs: [
102-
{
103-
name: "workflowName",
104-
status: "completed",
105-
conclusion: "success",
106-
},
107-
],
108-
},
109-
});
110-
111-
const actual = await getWorkflowRuns(
112-
githubMock,
113-
createMockContext(),
114-
"workflowName",
115-
"head_sha",
116-
);
117-
118-
expect(actual).toEqual([
119-
expect.objectContaining({
120-
name: "workflowName",
121-
status: "completed",
122-
conclusion: "success",
123-
}),
124-
]);
125-
});
126-
127-
it("returns null when no workflow matches", async () => {
128-
const githubMock = createMockGithub();
129-
githubMock.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({
130-
data: {
131-
workflow_runs: [
132-
{
133-
name: "otherWorkflowName",
134-
},
135-
],
136-
},
137-
});
138-
139-
const actual = await getWorkflowRuns(
140-
githubMock,
141-
createMockContext(),
142-
"workflowName",
143-
"head_sha",
144-
);
145-
146-
expect(actual).toEqual([]);
147-
});
148-
149-
it("returns latest when multiple workflows match", async () => {
150-
const githubMock = createMockGithub();
151-
const earlyDate = "2025-04-01T00:00:00Z";
152-
const laterDate = "2025-04-02T00:00:00Z";
153-
githubMock.rest.actions.listWorkflowRunsForRepo.mockResolvedValue({
154-
data: {
155-
workflow_runs: [
156-
{
157-
name: "workflowName",
158-
status: "completed",
159-
conclusion: "success",
160-
updated_at: earlyDate,
161-
},
162-
{
163-
name: "workflowName",
164-
status: "completed",
165-
conclusion: "success",
166-
updated_at: laterDate,
167-
},
168-
],
169-
},
170-
});
171-
172-
const actual = await getWorkflowRuns(
173-
githubMock,
174-
createMockContext(),
175-
"workflowName",
176-
"head_sha",
177-
);
178-
179-
expect(actual).toEqual([
180-
expect.objectContaining({
181-
updated_at: laterDate,
182-
}),
183-
expect.objectContaining({
184-
updated_at: earlyDate,
185-
}),
186-
]);
187-
});
188-
});
189-
1909
describe("writeToActionsSummary function", () => {
19110
it("should add content to the summary and write it", async () => {
19211
// Call function

0 commit comments

Comments
 (0)