From 672f236dcd5549c640a7737a81dc562cd6c045b6 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Mon, 6 Jan 2025 09:13:38 -0600 Subject: [PATCH] fix(notify-pipeline-complete): only set merge queue statuses on merge_group event --- dist/264.index.js | 20 ++--- dist/264.index.js.map | 2 +- dist/467.index.js | 3 +- dist/467.index.js.map | 2 +- src/helpers/initiate-deployment.ts | 24 +++--- src/helpers/notify-pipeline-complete.ts | 3 +- test/helpers/initiate-deployment.test.ts | 37 +++++++++- test/helpers/notify-pipeline-complete.test.ts | 74 +++++++++++++++++-- 8 files changed, 130 insertions(+), 35 deletions(-) diff --git a/dist/264.index.js b/dist/264.index.js index 406af148..5699aff4 100644 --- a/dist/264.index.js +++ b/dist/264.index.js @@ -149,15 +149,17 @@ const initiateDeployment = async ({ sha, state = 'in_progress', context = _const ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo, ..._constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .r0 }); - const commitHashesForMergeQueueBranches = await (0,_utils_get_merge_queue_commit_hashes__WEBPACK_IMPORTED_MODULE_4__/* .getMergeQueueCommitHashes */ .T)(); - await (0,bluebird__WEBPACK_IMPORTED_MODULE_3__.map)(commitHashesForMergeQueueBranches, async (sha) => _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit */ .A.repos.createCommitStatus({ - sha, - context, - state: 'pending', - description, - target_url, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo - })); + if (_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.eventName === 'merge_group') { + const commitHashesForMergeQueueBranches = await (0,_utils_get_merge_queue_commit_hashes__WEBPACK_IMPORTED_MODULE_4__/* .getMergeQueueCommitHashes */ .T)(); + await (0,bluebird__WEBPACK_IMPORTED_MODULE_3__.map)(commitHashesForMergeQueueBranches, async (sha) => _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit */ .A.repos.createCommitStatus({ + sha, + context, + state: 'pending', + description, + target_url, + ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + })); + } return deployment_id; }; diff --git a/dist/264.index.js.map b/dist/264.index.js.map index 1d5238f9..83fd75ca 100644 --- a/dist/264.index.js.map +++ b/dist/264.index.js.map @@ -1 +1 @@ -{"version":3,"file":"264.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;AC1DA;;;;;;;;;;;AAWA;AAGA;AACA;AACA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AAKA;AAAA;AAEA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;;;;;;;;;;;;;;;;;;ACzEA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA;;;;;;;;;;;;ACjEA;;;;;;;;;;;AAWA;AAEA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACnBA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/helpers/initiate-deployment.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/get-merge-queue-commit-hashes.ts",".././src/utils/paginate-all-branches.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const SECONDS_IN_A_DAY = 86400000;\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const LATE_REVIEW = 'Late Review';\nexport const OVERDUE_ISSUE = 'Overdue';\nexport const ALMOST_OVERDUE_ISSUE = 'Due Soon';\nexport const PRIORITY_1 = 'Priority: Critical';\nexport const PRIORITY_2 = 'Priority: High';\nexport const PRIORITY_3 = 'Priority: Medium';\nexport const PRIORITY_4 = 'Priority: Low';\nexport const PRIORITY_LABELS = [PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4] as const;\nexport const PRIORITY_TO_DAYS_MAP = {\n [PRIORITY_1]: 2,\n [PRIORITY_2]: 14,\n [PRIORITY_3]: 45,\n [PRIORITY_4]: 90\n};\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\nexport const COPYRIGHT_HEADER = `/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/`;\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DeploymentState } from '../types/github';\nimport { DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { map } from 'bluebird';\nimport { getMergeQueueCommitHashes } from '../utils/get-merge-queue-commit-hashes';\n\nexport class InitiateDeployment extends HelperInputs {\n sha = '';\n environment = '';\n state?: DeploymentState;\n environment_url?: string;\n description?: string;\n target_url?: string;\n}\n\nexport const initiateDeployment = async ({\n sha,\n state = 'in_progress',\n context = DEFAULT_PIPELINE_STATUS,\n environment,\n environment_url,\n description,\n target_url\n}: InitiateDeployment) => {\n const { data } = await octokit.repos.createDeployment({\n ref: sha,\n environment,\n auto_merge: false,\n required_contexts: [],\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = 'ref' in data ? data.id : undefined;\n if (!deployment_id) return;\n\n await octokit.repos.createDeploymentStatus({\n state,\n deployment_id,\n description,\n environment_url,\n target_url,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n\n const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();\n await map(commitHashesForMergeQueueBranches, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'pending',\n description,\n target_url,\n ...githubContext.repo\n })\n );\n\n return deployment_id;\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { paginateAllBranches } from './paginate-all-branches';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/merge-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { PullRequestBranchesList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllBranches = async ({\n protectedBranches,\n page = 1\n}: { protectedBranches?: boolean; page?: number } = {}): Promise => {\n const response = await octokit.repos.listBranches({\n protected: protectedBranches,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))];\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"264.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;AC1DA;;;;;;;;;;;AAWA;AAGA;AACA;AACA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AAKA;AAAA;AAEA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;;;;;;;;;;;;;;;;;;AC3EA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA;;;;;;;;;;;;ACjEA;;;;;;;;;;;AAWA;AAEA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACnBA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/helpers/initiate-deployment.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/get-merge-queue-commit-hashes.ts",".././src/utils/paginate-all-branches.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const SECONDS_IN_A_DAY = 86400000;\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const LATE_REVIEW = 'Late Review';\nexport const OVERDUE_ISSUE = 'Overdue';\nexport const ALMOST_OVERDUE_ISSUE = 'Due Soon';\nexport const PRIORITY_1 = 'Priority: Critical';\nexport const PRIORITY_2 = 'Priority: High';\nexport const PRIORITY_3 = 'Priority: Medium';\nexport const PRIORITY_4 = 'Priority: Low';\nexport const PRIORITY_LABELS = [PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4] as const;\nexport const PRIORITY_TO_DAYS_MAP = {\n [PRIORITY_1]: 2,\n [PRIORITY_2]: 14,\n [PRIORITY_3]: 45,\n [PRIORITY_4]: 90\n};\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\nexport const COPYRIGHT_HEADER = `/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/`;\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DeploymentState } from '../types/github';\nimport { DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { map } from 'bluebird';\nimport { getMergeQueueCommitHashes } from '../utils/get-merge-queue-commit-hashes';\n\nexport class InitiateDeployment extends HelperInputs {\n sha = '';\n environment = '';\n state?: DeploymentState;\n environment_url?: string;\n description?: string;\n target_url?: string;\n}\n\nexport const initiateDeployment = async ({\n sha,\n state = 'in_progress',\n context = DEFAULT_PIPELINE_STATUS,\n environment,\n environment_url,\n description,\n target_url\n}: InitiateDeployment) => {\n const { data } = await octokit.repos.createDeployment({\n ref: sha,\n environment,\n auto_merge: false,\n required_contexts: [],\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = 'ref' in data ? data.id : undefined;\n if (!deployment_id) return;\n\n await octokit.repos.createDeploymentStatus({\n state,\n deployment_id,\n description,\n environment_url,\n target_url,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n\n if (githubContext.eventName === 'merge_group') {\n const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();\n await map(commitHashesForMergeQueueBranches, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'pending',\n description,\n target_url,\n ...githubContext.repo\n })\n );\n }\n\n return deployment_id;\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { paginateAllBranches } from './paginate-all-branches';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/merge-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { PullRequestBranchesList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllBranches = async ({\n protectedBranches,\n page = 1\n}: { protectedBranches?: boolean; page?: number } = {}): Promise => {\n const response = await octokit.repos.listBranches({\n protected: protectedBranches,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))];\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/dist/467.index.js b/dist/467.index.js index 1b77397d..6e248c5e 100644 --- a/dist/467.index.js +++ b/dist/467.index.js @@ -130,8 +130,7 @@ const notifyPipelineComplete = async ({ context = _constants__WEBPACK_IMPORTED_M ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo }); const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha); - const commitHashesForMergeQueueBranches = await (0,_utils_get_merge_queue_commit_hashes__WEBPACK_IMPORTED_MODULE_4__/* .getMergeQueueCommitHashes */ .T)(); - const commitHashes = commitHashesForOpenPullRequests.concat(commitHashesForMergeQueueBranches); + const commitHashes = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.eventName === 'merge_group' ? await (0,_utils_get_merge_queue_commit_hashes__WEBPACK_IMPORTED_MODULE_4__/* .getMergeQueueCommitHashes */ .T)() : commitHashesForOpenPullRequests; await (0,bluebird__WEBPACK_IMPORTED_MODULE_2__.map)(commitHashes, async (sha) => _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit */ .A.repos.createCommitStatus({ sha, context, diff --git a/dist/467.index.js.map b/dist/467.index.js.map index e9569f7b..468c6e8e 100644 --- a/dist/467.index.js.map +++ b/dist/467.index.js.map @@ -1 +1 @@ -{"version":3,"file":"467.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;AC1DA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAKA;AAEA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACpEA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA;;;;;;;;;;;;ACjEA;;;;;;;;;;;AAWA;AAEA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACnBA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/helpers/notify-pipeline-complete.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/get-merge-queue-commit-hashes.ts",".././src/utils/paginate-all-branches.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const SECONDS_IN_A_DAY = 86400000;\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const LATE_REVIEW = 'Late Review';\nexport const OVERDUE_ISSUE = 'Overdue';\nexport const ALMOST_OVERDUE_ISSUE = 'Due Soon';\nexport const PRIORITY_1 = 'Priority: Critical';\nexport const PRIORITY_2 = 'Priority: High';\nexport const PRIORITY_3 = 'Priority: Medium';\nexport const PRIORITY_4 = 'Priority: Low';\nexport const PRIORITY_LABELS = [PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4] as const;\nexport const PRIORITY_TO_DAYS_MAP = {\n [PRIORITY_1]: 2,\n [PRIORITY_2]: 14,\n [PRIORITY_3]: 45,\n [PRIORITY_4]: 90\n};\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\nexport const COPYRIGHT_HEADER = `/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/`;\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { getMergeQueueCommitHashes } from '../utils/get-merge-queue-commit-hashes';\n\nexport class NotifyPipelineComplete extends HelperInputs {\n context?: string;\n description?: string;\n environment?: string;\n target_url?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n environment = PRODUCTION_ENVIRONMENT,\n target_url\n}: NotifyPipelineComplete) => {\n const { data: pullRequests } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);\n const commitHashesForMergeQueueBranches = await getMergeQueueCommitHashes();\n const commitHashes = commitHashesForOpenPullRequests.concat(commitHashesForMergeQueueBranches);\n await map(commitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo\n })\n );\n const { data: deployments } = await octokit.repos.listDeployments({\n environment,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (deployment_id) {\n return octokit.repos.createDeploymentStatus({\n environment,\n deployment_id,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n }\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { paginateAllBranches } from './paginate-all-branches';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/merge-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { PullRequestBranchesList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllBranches = async ({\n protectedBranches,\n page = 1\n}: { protectedBranches?: boolean; page?: number } = {}): Promise => {\n const response = await octokit.repos.listBranches({\n protected: protectedBranches,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))];\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"467.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;AC1DA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAKA;AAEA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACnEA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA;;;;;;;;;;;;ACjEA;;;;;;;;;;;AAWA;AAEA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACnBA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/helpers/notify-pipeline-complete.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/get-merge-queue-commit-hashes.ts",".././src/utils/paginate-all-branches.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n// These extra headers are for experimental API features on Github Enterprise. See https://docs.github.com/en/enterprise-server@3.0/rest/overview/api-previews for details.\nconst PREVIEWS = ['ant-man', 'flash', 'groot', 'inertia', 'starfox'];\nexport const GITHUB_OPTIONS = {\n headers: {\n accept: PREVIEWS.map(preview => `application/vnd.github.${preview}-preview+json`).join()\n }\n};\n\nexport const SECONDS_IN_A_DAY = 86400000;\nexport const DEFAULT_PIPELINE_STATUS = 'Pipeline Status';\nexport const DEFAULT_PIPELINE_DESCRIPTION = 'Pipeline clear.';\nexport const PRODUCTION_ENVIRONMENT = 'production';\nexport const LATE_REVIEW = 'Late Review';\nexport const OVERDUE_ISSUE = 'Overdue';\nexport const ALMOST_OVERDUE_ISSUE = 'Due Soon';\nexport const PRIORITY_1 = 'Priority: Critical';\nexport const PRIORITY_2 = 'Priority: High';\nexport const PRIORITY_3 = 'Priority: Medium';\nexport const PRIORITY_4 = 'Priority: Low';\nexport const PRIORITY_LABELS = [PRIORITY_1, PRIORITY_2, PRIORITY_3, PRIORITY_4] as const;\nexport const PRIORITY_TO_DAYS_MAP = {\n [PRIORITY_1]: 2,\n [PRIORITY_2]: 14,\n [PRIORITY_3]: 45,\n [PRIORITY_4]: 90\n};\nexport const CORE_APPROVED_PR_LABEL = 'CORE APPROVED';\nexport const PEER_APPROVED_PR_LABEL = 'PEER APPROVED';\nexport const READY_FOR_MERGE_PR_LABEL = 'READY FOR MERGE';\nexport const MERGE_QUEUE_STATUS = 'QUEUE CHECKER';\nexport const QUEUED_FOR_MERGE_PREFIX = 'QUEUED FOR MERGE';\nexport const FIRST_QUEUED_PR_LABEL = `${QUEUED_FOR_MERGE_PREFIX} #1`;\nexport const JUMP_THE_QUEUE_PR_LABEL = 'JUMP THE QUEUE';\nexport const DEFAULT_PR_TITLE_REGEX = '^(build|ci|chore|docs|feat|fix|perf|refactor|style|test|revert|Revert|BREAKING CHANGE)((.*))?: .+$';\nexport const COPYRIGHT_HEADER = `/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/`;\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { DEFAULT_PIPELINE_DESCRIPTION, DEFAULT_PIPELINE_STATUS, GITHUB_OPTIONS, PRODUCTION_ENVIRONMENT } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { getMergeQueueCommitHashes } from '../utils/get-merge-queue-commit-hashes';\n\nexport class NotifyPipelineComplete extends HelperInputs {\n context?: string;\n description?: string;\n environment?: string;\n target_url?: string;\n}\n\nexport const notifyPipelineComplete = async ({\n context = DEFAULT_PIPELINE_STATUS,\n description = DEFAULT_PIPELINE_DESCRIPTION,\n environment = PRODUCTION_ENVIRONMENT,\n target_url\n}: NotifyPipelineComplete) => {\n const { data: pullRequests } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...githubContext.repo\n });\n const commitHashesForOpenPullRequests = pullRequests.map(pullRequest => pullRequest.head.sha);\n const commitHashes = githubContext.eventName === 'merge_group' ? await getMergeQueueCommitHashes() : commitHashesForOpenPullRequests;\n await map(commitHashes, async sha =>\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo\n })\n );\n const { data: deployments } = await octokit.repos.listDeployments({\n environment,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n const deployment_id = deployments.find(Boolean)?.id;\n if (deployment_id) {\n return octokit.repos.createDeploymentStatus({\n environment,\n deployment_id,\n state: 'success',\n description,\n target_url,\n ...githubContext.repo,\n ...GITHUB_OPTIONS\n });\n }\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { paginateAllBranches } from './paginate-all-branches';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/merge-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { PullRequestBranchesList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllBranches = async ({\n protectedBranches,\n page = 1\n}: { protectedBranches?: boolean; page?: number } = {}): Promise => {\n const response = await octokit.repos.listBranches({\n protected: protectedBranches,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))];\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/initiate-deployment.ts b/src/helpers/initiate-deployment.ts index 6f4d65bc..c4ff3f89 100644 --- a/src/helpers/initiate-deployment.ts +++ b/src/helpers/initiate-deployment.ts @@ -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; }; diff --git a/src/helpers/notify-pipeline-complete.ts b/src/helpers/notify-pipeline-complete.ts index edbfa4e6..01e6a099 100644 --- a/src/helpers/notify-pipeline-complete.ts +++ b/src/helpers/notify-pipeline-complete.ts @@ -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, diff --git a/test/helpers/initiate-deployment.test.ts b/test/helpers/initiate-deployment.test.ts index 70d31f9a..35e518a5 100644 --- a/test/helpers/initiate-deployment.test.ts +++ b/test/helpers/initiate-deployment.test.ts @@ -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, diff --git a/test/helpers/notify-pipeline-complete.test.ts b/test/helpers/notify-pipeline-complete.test.ts index f74f790c..c03326bc 100644 --- a/test/helpers/notify-pipeline-complete.test.ts +++ b/test/helpers/notify-pipeline-complete.test.ts @@ -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, @@ -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, @@ -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,