Skip to content

Commit fb42cce

Browse files
authored
fix(notify-pipeline-complete): only set merge queue statuses on merge_group event (#683)
1 parent cab8117 commit fb42cce

File tree

8 files changed

+130
-35
lines changed

8 files changed

+130
-35
lines changed

dist/264.index.js

Lines changed: 11 additions & 9 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: 1 addition & 2 deletions
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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,19 @@ export const initiateDeployment = async ({
5858
...GITHUB_OPTIONS
5959
});
6060

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-
);
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+
}
7274

7375
return deployment_id;
7476
};

src/helpers/notify-pipeline-complete.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export const notifyPipelineComplete = async ({
3737
...githubContext.repo
3838
});
3939
const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);
40-
const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();
41-
const commitHashes = commitHashesForOpenPullRequests.concat(commitHashesForMergeQueueBranches);
40+
const commitHashes = githubContext.eventName === 'merge_group' ? await getMergeQueueCommitHashes() : commitHashesForOpenPullRequests;
4241
await map(commitHashes, async sha =>
4342
octokit.repos.createCommitStatus({
4443
sha,

test/helpers/initiate-deployment.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,42 @@ describe('initiateDeployment', () => {
100100
});
101101
});
102102

103-
it('should call createCommitStatus with correct params', async () => {
103+
it('should call createCommitStatus with correct params on non merge_group event', async () => {
104+
context.eventName = 'some_event';
105+
await initiateDeployment({
106+
sha,
107+
environment,
108+
description,
109+
target_url
110+
});
111+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
112+
sha: 'normal sha 1',
113+
context: DEFAULT_PIPELINE_STATUS,
114+
state: 'pending',
115+
description,
116+
target_url,
117+
...context.repo
118+
});
119+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
120+
sha: 'merge queue sha 1',
121+
context: DEFAULT_PIPELINE_STATUS,
122+
state: 'pending',
123+
description,
124+
target_url,
125+
...context.repo
126+
});
127+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
128+
sha: 'merge queue sha 2',
129+
context: DEFAULT_PIPELINE_STATUS,
130+
state: 'pending',
131+
description,
132+
target_url,
133+
...context.repo
134+
});
135+
});
136+
137+
it('should call createCommitStatus with correct params on merge_group event', async () => {
138+
context.eventName = 'merge_group';
104139
await initiateDeployment({
105140
sha,
106141
environment,

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

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,19 @@ jest.mock('../../src/helpers/set-deployment-status');
5757
data: [{ head: { sha: 'sha 1' } }, { head: { sha: 'sha 2' } }, { head: { sha: 'sha 3' } }]
5858
}));
5959

60-
describe('setOpenPullRequestStatus', () => {
60+
describe('notify-pipeline-complete', () => {
6161
const description = 'Pipeline clear.';
6262

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

67-
it('should call list with correct params', () => {
6867
expect(octokit.pulls.list).toHaveBeenCalledWith({
6968
state: 'open',
7069
per_page: 100,
7170
...context.repo
7271
});
73-
});
7472

75-
it('should call createCommitStatus with correct params', () => {
7673
expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({
7774
sha: 'sha 1',
7875
context: DEFAULT_PIPELINE_STATUS,
@@ -101,6 +98,69 @@ describe('setOpenPullRequestStatus', () => {
10198
description,
10299
...context.repo
103100
});
101+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
102+
sha: 'merge queue sha 1',
103+
context: DEFAULT_PIPELINE_STATUS,
104+
state: 'success',
105+
description,
106+
...context.repo
107+
});
108+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
109+
sha: 'merge queue sha 2',
110+
context: DEFAULT_PIPELINE_STATUS,
111+
state: 'success',
112+
description,
113+
...context.repo
114+
});
115+
116+
expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({
117+
state: 'success',
118+
environment: PRODUCTION_ENVIRONMENT,
119+
deployment_id: 123,
120+
description,
121+
...context.repo,
122+
...GITHUB_OPTIONS
123+
});
124+
});
125+
126+
it('should notify that the pipeline is clear on merge_group event', async () => {
127+
context.eventName = 'merge_group';
128+
await notifyPipelineComplete({});
129+
130+
expect(octokit.pulls.list).toHaveBeenCalledWith({
131+
state: 'open',
132+
per_page: 100,
133+
...context.repo
134+
});
135+
136+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
137+
sha: 'sha 1',
138+
context: DEFAULT_PIPELINE_STATUS,
139+
state: 'success',
140+
description,
141+
...context.repo
142+
});
143+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
144+
sha: 'sha 2',
145+
context: DEFAULT_PIPELINE_STATUS,
146+
state: 'success',
147+
description,
148+
...context.repo
149+
});
150+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
151+
sha: 'sha 3',
152+
context: DEFAULT_PIPELINE_STATUS,
153+
state: 'success',
154+
description,
155+
...context.repo
156+
});
157+
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
158+
sha: 'normal sha 1',
159+
context: DEFAULT_PIPELINE_STATUS,
160+
state: 'success',
161+
description,
162+
...context.repo
163+
});
104164
expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({
105165
sha: 'merge queue sha 1',
106166
context: DEFAULT_PIPELINE_STATUS,
@@ -115,9 +175,7 @@ describe('setOpenPullRequestStatus', () => {
115175
description,
116176
...context.repo
117177
});
118-
});
119178

120-
it('should call createDeploymentStatus with correct params', () => {
121179
expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({
122180
state: 'success',
123181
environment: PRODUCTION_ENVIRONMENT,

0 commit comments

Comments
 (0)