Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 101 additions & 4 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: 2 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43008,11 +43008,13 @@ 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.

24 changes: 21 additions & 3 deletions src/helpers/initiate-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ limitations under the License.
*/

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

export class InitiateDeployment extends HelperInputs {
sha = '';
Expand All @@ -24,6 +26,8 @@ export class InitiateDeployment extends HelperInputs {
declare environment_url?: string;
declare description?: string;
declare target_url?: string;
declare context?: string;
declare merge_queue_enabled?: string;
}

export const initiateDeployment = async ({
Expand All @@ -32,7 +36,9 @@ export const initiateDeployment = async ({
environment,
environment_url,
description,
target_url
target_url,
context = DEFAULT_PIPELINE_STATUS,
merge_queue_enabled
}: InitiateDeployment) => {
const { data } = await octokit.repos.createDeployment({
ref: sha,
Expand All @@ -55,5 +61,17 @@ export const initiateDeployment = async ({
...GITHUB_OPTIONS
});

return deployment_id;
if (merge_queue_enabled === 'true') {
const mergeQueueCommitHashes = await getMergeQueueCommitHashes();
return map(mergeQueueCommitHashes, async sha =>
octokit.repos.createCommitStatus({
sha,
context,
state: 'pending',
description,
target_url,
...githubContext.repo
})
);
}
};
71 changes: 59 additions & 12 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 { GITHUB_OPTIONS } from '../../src/constants';
import { DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS } from '../../src/constants';
import { Mocktokit } from '../types';
import { context } from '@actions/github';
import { initiateDeployment } from '../../src/helpers/initiate-deployment';
Expand All @@ -25,6 +25,7 @@ jest.mock('@actions/github', () => ({
repos: {
createDeployment: jest.fn(),
createDeploymentStatus: jest.fn(),
createCommitStatus: jest.fn(),
listBranches: jest.fn(() => ({ data: [] }))
}
}
Expand All @@ -46,13 +47,14 @@ describe('initiateDeployment', () => {
const target_url = 'url';
const auto_merge = false;

it('should call createDeployment with correct params', async () => {
it('should handle non merge queue case', async () => {
await initiateDeployment({
sha,
environment,
description,
target_url
});

expect(octokit.repos.createDeployment).toHaveBeenCalledWith({
ref: sha,
environment,
Expand All @@ -61,14 +63,53 @@ describe('initiateDeployment', () => {
...context.repo,
...GITHUB_OPTIONS
});
expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({
state: 'in_progress',
deployment_id,
description,
target_url,
...context.repo,
...GITHUB_OPTIONS
});
expect(octokit.repos.listBranches).not.toHaveBeenCalled();
});

it('should call createDeploymentStatus with correct params', async () => {
it('should handle merge queue case', 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
target_url,
merge_queue_enabled: 'true'
});

expect(octokit.repos.createDeployment).toHaveBeenCalledWith({
ref: sha,
environment,
auto_merge,
required_contexts: [],
...context.repo,
...GITHUB_OPTIONS
});
expect(octokit.repos.createDeploymentStatus).toHaveBeenCalledWith({
state: 'in_progress',
Expand All @@ -78,15 +119,21 @@ describe('initiateDeployment', () => {
...context.repo,
...GITHUB_OPTIONS
});
});

it('should return deployment id as output', async () => {
const result = await initiateDeployment({
sha,
environment,
expect(octokit.repos.createCommitStatus).toHaveBeenCalledWith({
sha: 'merge queue sha 1',
context: DEFAULT_PIPELINE_STATUS,
state: 'pending',
description,
target_url
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
});
expect(result).toEqual(deployment_id);
});
});