Skip to content

Commit

Permalink
fix(notify-pipeline-complete): only set merge queue statuses on merge…
Browse files Browse the repository at this point in the history
…_group event
  • Loading branch information
danadajian committed Jan 6, 2025
1 parent cab8117 commit 672f236
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 35 deletions.
20 changes: 11 additions & 9 deletions dist/264.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/264.index.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/467.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/467.index.js.map

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions src/helpers/initiate-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ export const initiateDeployment = async ({
...GITHUB_OPTIONS
});

const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();
await map(commitHashesForMergeQueueBranches, async sha =>
octokit.repos.createCommitStatus({
sha,
context,
state: 'pending',
description,
target_url,
...githubContext.repo
})
);
if (githubContext.eventName === 'merge_group') {
const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();
await map(commitHashesForMergeQueueBranches, async sha =>
octokit.repos.createCommitStatus({
sha,
context,
state: 'pending',
description,
target_url,
...githubContext.repo
})
);
}

return deployment_id;
};
3 changes: 1 addition & 2 deletions src/helpers/notify-pipeline-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export const notifyPipelineComplete = async ({
...githubContext.repo
});
const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);
const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();
const commitHashes = commitHashesForOpenPullRequests.concat(commitHashesForMergeQueueBranches);
const commitHashes = githubContext.eventName === 'merge_group' ? await getMergeQueueCommitHashes() : commitHashesForOpenPullRequests;
await map(commitHashes, async sha =>
octokit.repos.createCommitStatus({
sha,
Expand Down
37 changes: 36 additions & 1 deletion test/helpers/initiate-deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,42 @@ describe('initiateDeployment', () => {
});
});

it('should call createCommitStatus with correct params', async () => {
it('should call createCommitStatus with correct params on pull_request event', async () => {
context.eventName = 'pull_request';
await initiateDeployment({
sha,
environment,
description,
target_url
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'normal sha 1',
context: DEFAULT_PIPELINE_STATUS,
state: 'pending',
description,
target_url,
...context.repo
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'merge queue sha 1',
context: DEFAULT_PIPELINE_STATUS,
state: 'pending',
description,
target_url,
...context.repo
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'merge queue sha 2',
context: DEFAULT_PIPELINE_STATUS,
state: 'pending',
description,
target_url,
...context.repo
});
});

it('should call createCommitStatus with correct params on merge_group event', async () => {
context.eventName = 'merge_group';
await initiateDeployment({
sha,
environment,
Expand Down
74 changes: 66 additions & 8 deletions test/helpers/notify-pipeline-complete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,19 @@ jest.mock('../../src/helpers/set-deployment-status');
data: [{ head: { sha: 'sha 1' } }, { head: { sha: 'sha 2' } }, { head: { sha: 'sha 3' } }]
}));

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

beforeEach(async () => {
it('should notify that the pipeline is clear on pull_request event', async () => {
context.eventName = 'pull_request';
await notifyPipelineComplete({});
});

it('should call list with correct params', () => {
expect(octokit.pulls.list).toHaveBeenCalledWith({
state: 'open',
per_page: 100,
...context.repo
});
});

it('should call createCommitStatus with correct params', () => {
expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({
sha: 'sha 1',
context: DEFAULT_PIPELINE_STATUS,
Expand Down Expand Up @@ -101,6 +98,69 @@ describe('setOpenPullRequestStatus', () => {
description,
...context.repo
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'merge queue sha 1',
context: DEFAULT_PIPELINE_STATUS,
state: 'success',
description,
...context.repo
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'merge queue sha 2',
context: DEFAULT_PIPELINE_STATUS,
state: 'success',
description,
...context.repo
});

expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({
state: 'success',
environment: PRODUCTION_ENVIRONMENT,
deployment_id: 123,
description,
...context.repo,
...GITHUB_OPTIONS
});
});

it('should notify that the pipeline is clear on merge_group event', async () => {
context.eventName = 'merge_group';
await notifyPipelineComplete({});

expect(octokit.pulls.list).toHaveBeenCalledWith({
state: 'open',
per_page: 100,
...context.repo
});

expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'sha 1',
context: DEFAULT_PIPELINE_STATUS,
state: 'success',
description,
...context.repo
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'sha 2',
context: DEFAULT_PIPELINE_STATUS,
state: 'success',
description,
...context.repo
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'sha 3',
context: DEFAULT_PIPELINE_STATUS,
state: 'success',
description,
...context.repo
});
expect(octokit.repos.createCommitStatus).not.toHaveBeenCalledWith({
sha: 'normal sha 1',
context: DEFAULT_PIPELINE_STATUS,
state: 'success',
description,
...context.repo
});
expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({
sha: 'merge queue sha 1',
context: DEFAULT_PIPELINE_STATUS,
Expand All @@ -115,9 +175,7 @@ describe('setOpenPullRequestStatus', () => {
description,
...context.repo
});
});

it('should call createDeploymentStatus with correct params', () => {
expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({
state: 'success',
environment: PRODUCTION_ENVIRONMENT,
Expand Down

0 comments on commit 672f236

Please sign in to comment.