Skip to content

Commit

Permalink
fix(initiate-deployment): don't set commit statuses on merge queue PRs (
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Jan 15, 2025
1 parent 9dc4581 commit 2ec4f0a
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 207 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ jobs:
helper: delete-deployment
sha: ${{ github.event.pull_request.head.sha }}
environment: test
github_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
102 changes: 3 additions & 99 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.

2 changes: 0 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42996,13 +42996,11 @@ var map = {
"./initiate-deployment": [
5264,
461,
366,
264
],
"./initiate-deployment.ts": [
5264,
461,
366,
264
],
"./is-user-core-member": [
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

17 changes: 1 addition & 16 deletions src/helpers/initiate-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ limitations under the License.
*/

import { DeploymentState } from '../types/github';
import { DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS } from '../constants';
import { GITHUB_OPTIONS } from '../constants';
import { HelperInputs } from '../types/generated';
import { context as githubContext } from '@actions/github';
import { octokit } from '../octokit';
import { map } from 'bluebird';
import { getMergeQueueCommitHashes } from '../utils/merge-queue';

export class InitiateDeployment extends HelperInputs {
sha = '';
Expand All @@ -31,7 +29,6 @@ export class InitiateDeployment extends HelperInputs {
export const initiateDeployment = async ({
sha,
state = 'in_progress',
context = DEFAULT_PIPELINE_STATUS,
environment,
environment_url,
description,
Expand All @@ -58,17 +55,5 @@ 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
})
);

return deployment_id;
};
89 changes: 1 addition & 88 deletions test/helpers/initiate-deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS } from '../../src/constants';
import { GITHUB_OPTIONS } from '../../src/constants';
import { Mocktokit } from '../types';
import { context } from '@actions/github';
import { initiateDeployment } from '../../src/helpers/initiate-deployment';
Expand All @@ -23,7 +23,6 @@ jest.mock('@actions/github', () => ({
getOctokit: jest.fn(() => ({
rest: {
repos: {
createCommitStatus: jest.fn(),
createDeployment: jest.fn(),
createDeploymentStatus: jest.fn(),
listBranches: jest.fn(() => ({ data: [] }))
Expand Down Expand Up @@ -81,92 +80,6 @@ describe('initiateDeployment', () => {
});
});

it('should call createCommitStatus with correct params', async () => {
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 when merge queue branches are present', async () => {
(octokit.repos.listBranches as unknown as Mocktokit).mockImplementation(async ({ page }) =>
page > 1
? { data: [] }
: {
data: [
{
name: 'some-branch',
commit: { sha: 'normal sha 1' }
},
{
name: 'gh-readonly-queue/default-branch/pr-123-79a5ad2b1a46f6b5d77e02573937667979635f27',
commit: { sha: 'merge queue sha 1' }
},
{
name: 'gh-readonly-queue/default-branch/pr-456-79a5ad2b1a46f6b5d77e02573937667979635f27',
commit: { sha: 'merge queue sha 2' }
}
]
}
);
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).toHaveBeenCalledWith({
sha: 'merge queue sha 1',
context: DEFAULT_PIPELINE_STATUS,
state: 'pending',
description,
target_url,
...context.repo
});
expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({
sha: 'merge queue sha 2',
context: DEFAULT_PIPELINE_STATUS,
state: 'pending',
description,
target_url,
...context.repo
});
});

it('should return deployment id as output', async () => {
const result = await initiateDeployment({
sha,
Expand Down
1 change: 1 addition & 0 deletions test/helpers/manage-merge-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jest.mock('../../src/helpers/is-user-in-team');
jest.mock('../../src/helpers/approvals-satisfied');
jest.mock('../../src/helpers/create-pr-comment');
jest.mock('../../src/utils/../../src/helpers/prepare-queued-pr-for-merge');
jest.mock('path');
jest.mock('@actions/core');
jest.mock('@actions/github', () => ({
context: { repo: { repo: 'repo', owner: 'owner' }, issue: { number: 123 }, serverUrl: 'sampleUrl' },
Expand Down

0 comments on commit 2ec4f0a

Please sign in to comment.