Skip to content

Commit 208bb6d

Browse files
authored
fix(notify-pipeline-complete): merge queue statuses (#684)
1 parent fb42cce commit 208bb6d

File tree

8 files changed

+72
-76
lines changed

8 files changed

+72
-76
lines changed

dist/264.index.js

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

dist/264.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.

dist/467.index.js

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

dist/467.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/helpers/initiate-deployment.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,17 @@ export const initiateDeployment = async ({
5858
...GITHUB_OPTIONS
5959
});
6060

61-
if (githubContext.eventName === 'merge_group') {
62-
const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();
63-
await map(commitHashesForMergeQueueBranches, async sha =>
64-
octokit.repos.createCommitStatus({
65-
sha,
66-
context,
67-
state: 'pending',
68-
description,
69-
target_url,
70-
...githubContext.repo
71-
})
72-
);
73-
}
61+
const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();
62+
await map(commitHashesForMergeQueueBranches, async sha =>
63+
octokit.repos.createCommitStatus({
64+
sha,
65+
context,
66+
state: 'pending',
67+
description,
68+
target_url,
69+
...githubContext.repo
70+
})
71+
);
7472

7573
return deployment_id;
7674
};

src/helpers/notify-pipeline-complete.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const notifyPipelineComplete = async ({
3737
...githubContext.repo
3838
});
3939
const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);
40-
const commitHashes = githubContext.eventName === 'merge_group' ? await getMergeQueueCommitHashes() : commitHashesForOpenPullRequests;
40+
const mergeQueueCommitHashes = await getMergeQueueCommitHashes();
41+
const commitHashes = mergeQueueCommitHashes.length ? mergeQueueCommitHashes : commitHashesForOpenPullRequests;
4142
await map(commitHashes, async sha =>
4243
octokit.repos.createCommitStatus({
4344
sha,

test/helpers/initiate-deployment.test.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,7 @@ jest.mock('@actions/github', () => ({
2626
createCommitStatus: jest.fn(),
2727
createDeployment: jest.fn(),
2828
createDeploymentStatus: jest.fn(),
29-
listBranches: jest.fn(({ page }) =>
30-
page > 1
31-
? { data: [] }
32-
: {
33-
data: [
34-
{
35-
name: 'some-branch',
36-
commit: { sha: 'normal sha 1' }
37-
},
38-
{
39-
name: 'gh-readonly-queue/merge-queue/pr-123-79a5ad2b1a46f6b5d77e02573937667979635f27',
40-
commit: { sha: 'merge queue sha 1' }
41-
},
42-
{
43-
name: 'gh-readonly-queue/merge-queue/pr-456-79a5ad2b1a46f6b5d77e02573937667979635f27',
44-
commit: { sha: 'merge queue sha 2' }
45-
}
46-
]
47-
}
48-
)
29+
listBranches: jest.fn(() => ({ data: [] }))
4930
}
5031
}
5132
}))
@@ -100,8 +81,7 @@ describe('initiateDeployment', () => {
10081
});
10182
});
10283

103-
it('should call createCommitStatus with correct params on non merge_group event', async () => {
104-
context.eventName = 'some_event';
84+
it('should call createCommitStatus with correct params', async () => {
10585
await initiateDeployment({
10686
sha,
10787
environment,
@@ -134,8 +114,27 @@ describe('initiateDeployment', () => {
134114
});
135115
});
136116

137-
it('should call createCommitStatus with correct params on merge_group event', async () => {
138-
context.eventName = 'merge_group';
117+
it('should call createCommitStatus with correct params when merge queue branches are present', async () => {
118+
(octokit.repos.listBranches as unknown as Mocktokit).mockImplementation(async ({ page }) =>
119+
page > 1
120+
? { data: [] }
121+
: {
122+
data: [
123+
{
124+
name: 'some-branch',
125+
commit: { sha: 'normal sha 1' }
126+
},
127+
{
128+
name: 'gh-readonly-queue/merge-queue/pr-123-79a5ad2b1a46f6b5d77e02573937667979635f27',
129+
commit: { sha: 'merge queue sha 1' }
130+
},
131+
{
132+
name: 'gh-readonly-queue/merge-queue/pr-456-79a5ad2b1a46f6b5d77e02573937667979635f27',
133+
commit: { sha: 'merge queue sha 2' }
134+
}
135+
]
136+
}
137+
);
139138
await initiateDeployment({
140139
sha,
141140
environment,

test/helpers/notify-pipeline-complete.test.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,7 @@ jest.mock('@actions/github', () => ({
2727
createCommitStatus: jest.fn(),
2828
createDeploymentStatus: jest.fn(),
2929
listDeployments: jest.fn(() => ({ data: [{ id: 123 }] })),
30-
listBranches: jest.fn(({ page }) =>
31-
page > 1
32-
? { data: [] }
33-
: {
34-
data: [
35-
{
36-
name: 'some-branch',
37-
commit: { sha: 'normal sha 1' }
38-
},
39-
{
40-
name: 'gh-readonly-queue/merge-queue/pr-123-79a5ad2b1a46f6b5d77e02573937667979635f27',
41-
commit: { sha: 'merge queue sha 1' }
42-
},
43-
{
44-
name: 'gh-readonly-queue/merge-queue/pr-456-79a5ad2b1a46f6b5d77e02573937667979635f27',
45-
commit: { sha: 'merge queue sha 2' }
46-
}
47-
]
48-
}
49-
)
30+
listBranches: jest.fn(() => ({ data: [] }))
5031
}
5132
}
5233
}))
@@ -60,8 +41,7 @@ jest.mock('../../src/helpers/set-deployment-status');
6041
describe('notify-pipeline-complete', () => {
6142
const description = 'Pipeline clear.';
6243

63-
it('should notify that the pipeline is clear on non merge_group event', async () => {
64-
context.eventName = 'some_event';
44+
it('should notify that the pipeline is clear', async () => {
6545
await notifyPipelineComplete({});
6646

6747
expect(octokit.pulls.list).toHaveBeenCalledWith({
@@ -123,8 +103,27 @@ describe('notify-pipeline-complete', () => {
123103
});
124104
});
125105

126-
it('should notify that the pipeline is clear on merge_group event', async () => {
127-
context.eventName = 'merge_group';
106+
it('should notify that the pipeline is clear when merge queue branches are present', async () => {
107+
(octokit.repos.listBranches as unknown as Mocktokit).mockImplementation(async ({ page }) =>
108+
page > 1
109+
? { data: [] }
110+
: {
111+
data: [
112+
{
113+
name: 'some-branch',
114+
commit: { sha: 'normal sha 1' }
115+
},
116+
{
117+
name: 'gh-readonly-queue/merge-queue/pr-123-79a5ad2b1a46f6b5d77e02573937667979635f27',
118+
commit: { sha: 'merge queue sha 1' }
119+
},
120+
{
121+
name: 'gh-readonly-queue/merge-queue/pr-456-79a5ad2b1a46f6b5d77e02573937667979635f27',
122+
commit: { sha: 'merge queue sha 2' }
123+
}
124+
]
125+
}
126+
);
128127
await notifyPipelineComplete({});
129128

130129
expect(octokit.pulls.list).toHaveBeenCalledWith({

0 commit comments

Comments
 (0)