diff --git a/dist/264.index.js b/dist/264.index.js index 187384a9..01be9567 100644 --- a/dist/264.index.js +++ b/dist/264.index.js @@ -102,7 +102,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6590); /* harmony import */ var bluebird__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4366); /* harmony import */ var bluebird__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(bluebird__WEBPACK_IMPORTED_MODULE_3__); -/* harmony import */ var _utils_get_merge_queue_commit_hashes__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7987); +/* harmony import */ var _utils_merge_queue__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5323); /* Copyright 2021 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -149,7 +149,7 @@ 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)(); + const commitHashesForMergeQueueBranches = await (0,_utils_merge_queue__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, @@ -222,13 +222,16 @@ class HelperInputs { /***/ }), -/***/ 7987: +/***/ 5323: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ M: () => (/* binding */ getPrNumberFromMergeQueueRef), /* harmony export */ T: () => (/* binding */ getMergeQueueCommitHashes) /* harmony export */ }); /* harmony import */ var _paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9615); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); /* Copyright 2022 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -242,11 +245,22 @@ See the License for the specific language governing permissions and limitations under the License. */ + const getMergeQueueCommitHashes = async () => { const branches = await (0,_paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__/* .paginateAllBranches */ .h)(); const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/')); return mergeQueueBranches.map(branch => branch.commit.sha); }; +const getPrNumberFromMergeQueueRef = () => { + const prNumber = Number(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0]); + if (isNaN(prNumber)) { + throw new Error('Could not find PR number in merge queue ref.'); + } + return prNumber; +}; /***/ }), diff --git a/dist/264.index.js.map b/dist/264.index.js.map index a1ab018a..1955dd4a 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/'));\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;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;;;;;;;;;;;;;;;;;;ACzEA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA;;;;;;;;;;;;;;;ACjEA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACjCA;;;;;;;;;;;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/merge-queue.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/merge-queue';\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';\nimport { context } from '@actions/github';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n\nexport const getPrNumberFromMergeQueueRef = () => {\n const prNumber = Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n );\n if (isNaN(prNumber)) {\n throw new Error('Could not find PR number in merge queue ref.');\n }\n return prNumber;\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 65de40e8..3deb5c55 100644 --- a/dist/467.index.js +++ b/dist/467.index.js @@ -102,7 +102,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var bluebird__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4366); /* harmony import */ var bluebird__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(bluebird__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6590); -/* harmony import */ var _utils_get_merge_queue_commit_hashes__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7987); +/* harmony import */ var _utils_merge_queue__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5323); /* Copyright 2021 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -130,7 +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 mergeQueueCommitHashes = await (0,_utils_get_merge_queue_commit_hashes__WEBPACK_IMPORTED_MODULE_4__/* .getMergeQueueCommitHashes */ .T)(); + const mergeQueueCommitHashes = await (0,_utils_merge_queue__WEBPACK_IMPORTED_MODULE_4__/* .getMergeQueueCommitHashes */ .T)(); const commitHashes = mergeQueueCommitHashes.length ? mergeQueueCommitHashes : commitHashesForOpenPullRequests; await (0,bluebird__WEBPACK_IMPORTED_MODULE_2__.map)(commitHashes, async (sha) => _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit */ .A.repos.createCommitStatus({ sha, @@ -220,13 +220,16 @@ class HelperInputs { /***/ }), -/***/ 7987: +/***/ 5323: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ M: () => (/* binding */ getPrNumberFromMergeQueueRef), /* harmony export */ T: () => (/* binding */ getMergeQueueCommitHashes) /* harmony export */ }); /* harmony import */ var _paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9615); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); /* Copyright 2022 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -240,11 +243,22 @@ See the License for the specific language governing permissions and limitations under the License. */ + const getMergeQueueCommitHashes = async () => { const branches = await (0,_paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__/* .paginateAllBranches */ .h)(); const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/')); return mergeQueueBranches.map(branch => branch.commit.sha); }; +const getPrNumberFromMergeQueueRef = () => { + const prNumber = Number(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0]); + if (isNaN(prNumber)) { + throw new Error('Could not find PR number in merge queue ref.'); + } + return prNumber; +}; /***/ }), diff --git a/dist/467.index.js.map b/dist/467.index.js.map index 1697850c..d712c5fb 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 mergeQueueCommitHashes = await getMergeQueueCommitHashes();\n const commitHashes = mergeQueueCommitHashes.length ? mergeQueueCommitHashes : 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/'));\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;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;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACjCA;;;;;;;;;;;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/merge-queue.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/merge-queue';\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 mergeQueueCommitHashes = await getMergeQueueCommitHashes();\n const commitHashes = mergeQueueCommitHashes.length ? mergeQueueCommitHashes : 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';\nimport { context } from '@actions/github';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n\nexport const getPrNumberFromMergeQueueRef = () => {\n const prNumber = Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n );\n if (isNaN(prNumber)) {\n throw new Error('Could not find PR number in merge queue ref.');\n }\n return prNumber;\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/604.index.js b/dist/604.index.js index dd5e7c99..d39d48ff 100644 --- a/dist/604.index.js +++ b/dist/604.index.js @@ -10,10 +10,11 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ GetMergeQueuePosition: () => (/* binding */ GetMergeQueuePosition), /* harmony export */ getMergeQueuePosition: () => (/* binding */ getMergeQueuePosition) /* harmony export */ }); -/* harmony import */ var _types_generated__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8428); +/* harmony import */ var _types_generated__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8428); /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3228); /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6590); +/* harmony import */ var _utils_merge_queue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5323); /* Copyright 2021 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +30,8 @@ limitations under the License. -class GetMergeQueuePosition extends _types_generated__WEBPACK_IMPORTED_MODULE_2__/* .HelperInputs */ .m { + +class GetMergeQueuePosition extends _types_generated__WEBPACK_IMPORTED_MODULE_3__/* .HelperInputs */ .m { } const getMergeQueuePosition = async ({ max_queue_size = '10' }) => { const { repository } = await (0,_octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokitGraphql */ .n)(` @@ -48,10 +50,7 @@ query { } } `); - const prNumberFromMergeQueueRef = Number(_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.ref - .split('/') - .find(part => part.includes('pr-')) - ?.match(/\d+/)?.[0]); + const prNumberFromMergeQueueRef = (0,_utils_merge_queue__WEBPACK_IMPORTED_MODULE_2__/* .getPrNumberFromMergeQueueRef */ .M)(); const mergeQueueEntries = repository.mergeQueue?.entries?.nodes; return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === prNumberFromMergeQueueRef)?.position; }; @@ -115,6 +114,88 @@ class HelperInputs { } +/***/ }), + +/***/ 5323: +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ M: () => (/* binding */ getPrNumberFromMergeQueueRef), +/* harmony export */ T: () => (/* binding */ getMergeQueueCommitHashes) +/* harmony export */ }); +/* harmony import */ var _paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9615); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); +/* +Copyright 2022 Expedia, Inc. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + https://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +const getMergeQueueCommitHashes = async () => { + const branches = await (0,_paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__/* .paginateAllBranches */ .h)(); + const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/')); + return mergeQueueBranches.map(branch => branch.commit.sha); +}; +const getPrNumberFromMergeQueueRef = () => { + const prNumber = Number(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0]); + if (isNaN(prNumber)) { + throw new Error('Could not find PR number in merge queue ref.'); + } + return prNumber; +}; + + +/***/ }), + +/***/ 9615: +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ h: () => (/* binding */ paginateAllBranches) +/* harmony export */ }); +/* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6590); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); +/* +Copyright 2022 Expedia, Inc. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + https://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +const paginateAllBranches = async ({ protectedBranches, page = 1 } = {}) => { + const response = await _octokit__WEBPACK_IMPORTED_MODULE_0__/* .octokit */ .A.repos.listBranches({ + protected: protectedBranches, + per_page: 100, + page, + ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + }); + if (!response.data.length) { + return []; + } + return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))]; +}; + + /***/ }) }; diff --git a/dist/604.index.js.map b/dist/604.index.js.map index 32e63334..01759573 100644 --- a/dist/604.index.js.map +++ b/dist/604.index.js.map @@ -1 +1 @@ -{"version":3,"file":"604.index.js","mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAGA;AAEA;AAEA;AACA;;AAEA;;AAEA;;;;;;;;;;;AAWA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;;;;;;;;;;;;;;;;;;AC/CA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA","sources":[".././src/helpers/get-merge-queue-position.ts",".././src/octokit.ts",".././src/types/generated.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\nhttps://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 { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokitGraphql } from '../octokit';\nimport { Repository } from '@octokit/graphql-schema';\n\nexport class GetMergeQueuePosition extends HelperInputs {\n max_queue_size?: string;\n}\n\nexport const getMergeQueuePosition = async ({ max_queue_size = '10' }: GetMergeQueuePosition) => {\n const { repository } = await octokitGraphql<{ repository: Repository }>(`\nquery {\n repository(owner: \"${context.repo.owner}\", name: \"${context.repo.repo}\") {\n mergeQueue {\n entries(first: ${max_queue_size}) {\n nodes {\n pullRequest {\n number\n }\n position\n }\n }\n }\n }\n}\n`);\n const prNumberFromMergeQueueRef = Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n );\n const mergeQueueEntries = repository.mergeQueue?.entries?.nodes;\n return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === prNumberFromMergeQueueRef)?.position;\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"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"604.index.js","mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AAEA;AAEA;AAEA;AACA;;AAEA;;AAEA;;;;;;;;;;;AAWA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC3CA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA;;;;;;;;;;;;;;;ACjEA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACjCA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/helpers/get-merge-queue-position.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/merge-queue.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\nhttps://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 { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokitGraphql } from '../octokit';\nimport { Repository } from '@octokit/graphql-schema';\nimport { getPrNumberFromMergeQueueRef } from '../utils/merge-queue';\n\nexport class GetMergeQueuePosition extends HelperInputs {\n max_queue_size?: string;\n}\n\nexport const getMergeQueuePosition = async ({ max_queue_size = '10' }: GetMergeQueuePosition) => {\n const { repository } = await octokitGraphql<{ repository: Repository }>(`\nquery {\n repository(owner: \"${context.repo.owner}\", name: \"${context.repo.repo}\") {\n mergeQueue {\n entries(first: ${max_queue_size}) {\n nodes {\n pullRequest {\n number\n }\n position\n }\n }\n }\n }\n}\n`);\n const prNumberFromMergeQueueRef = getPrNumberFromMergeQueueRef();\n const mergeQueueEntries = repository.mergeQueue?.entries?.nodes;\n return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === prNumberFromMergeQueueRef)?.position;\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';\nimport { context } from '@actions/github';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n\nexport const getPrNumberFromMergeQueueRef = () => {\n const prNumber = Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n );\n if (isNaN(prNumber)) {\n throw new Error('Could not find PR number in merge queue ref.');\n }\n return prNumber;\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/654.index.js b/dist/654.index.js index ca26151f..426dca21 100644 --- a/dist/654.index.js +++ b/dist/654.index.js @@ -12,12 +12,13 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ }); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7484); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _types_generated__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8428); +/* harmony import */ var _types_generated__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(8428); /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var micromatch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8785); /* harmony import */ var micromatch__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(micromatch__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6590); +/* harmony import */ var _utils_merge_queue__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5323); /* Copyright 2021 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,21 +36,11 @@ limitations under the License. -class FilterPaths extends _types_generated__WEBPACK_IMPORTED_MODULE_4__/* .HelperInputs */ .m { + +class FilterPaths extends _types_generated__WEBPACK_IMPORTED_MODULE_5__/* .HelperInputs */ .m { } -const filterPaths = async ({ paths, globs, sha }) => { - const prNumberFromSha = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.eventName === 'merge_group' - ? Number(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref - .split('/') - .find(part => part.includes('pr-')) - ?.match(/\d+/)?.[0]) - : sha - ? (await _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit */ .A.repos.listPullRequestsAssociatedWithCommit({ - commit_sha: sha, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo - })).data.find(Boolean)?.number - : undefined; - const pull_number = prNumberFromSha ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; +const filterPaths = async ({ paths, globs }) => { + const pull_number = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.eventName === 'merge_group' ? (0,_utils_merge_queue__WEBPACK_IMPORTED_MODULE_4__/* .getPrNumberFromMergeQueueRef */ .M)() : _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; const { data } = await _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit */ .A.pulls.listFiles({ per_page: 100, pull_number, @@ -129,6 +120,88 @@ class HelperInputs { } +/***/ }), + +/***/ 5323: +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ M: () => (/* binding */ getPrNumberFromMergeQueueRef), +/* harmony export */ T: () => (/* binding */ getMergeQueueCommitHashes) +/* harmony export */ }); +/* harmony import */ var _paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9615); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); +/* +Copyright 2022 Expedia, Inc. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + https://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +const getMergeQueueCommitHashes = async () => { + const branches = await (0,_paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__/* .paginateAllBranches */ .h)(); + const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/')); + return mergeQueueBranches.map(branch => branch.commit.sha); +}; +const getPrNumberFromMergeQueueRef = () => { + const prNumber = Number(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0]); + if (isNaN(prNumber)) { + throw new Error('Could not find PR number in merge queue ref.'); + } + return prNumber; +}; + + +/***/ }), + +/***/ 9615: +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ h: () => (/* binding */ paginateAllBranches) +/* harmony export */ }); +/* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6590); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); +/* +Copyright 2022 Expedia, Inc. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + https://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +const paginateAllBranches = async ({ protectedBranches, page = 1 } = {}) => { + const response = await _octokit__WEBPACK_IMPORTED_MODULE_0__/* .octokit */ .A.repos.listBranches({ + protected: protectedBranches, + per_page: 100, + page, + ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + }); + if (!response.data.length) { + return []; + } + return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))]; +}; + + /***/ }) }; diff --git a/dist/654.index.js.map b/dist/654.index.js.map index 423530e6..4f749d56 100644 --- a/dist/654.index.js.map +++ b/dist/654.index.js.map @@ -1 +1 @@ -{"version":3,"file":"654.index.js","mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AACA;AAEA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAAA;AACA;AACA;AAAA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC5DA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA","sources":[".././src/helpers/filter-paths.ts",".././src/octokit.ts",".././src/types/generated.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\nimport * as core from '@actions/core';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport micromatch from 'micromatch';\nimport { octokit } from '../octokit';\n\nexport class FilterPaths extends HelperInputs {\n paths?: string;\n globs?: string;\n sha?: string;\n}\n\nexport const filterPaths = async ({ paths, globs, sha }: FilterPaths) => {\n const prNumberFromSha =\n context.eventName === 'merge_group'\n ? Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n )\n : sha\n ? (\n await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n ...context.repo\n })\n ).data.find(Boolean)?.number\n : undefined;\n const pull_number = prNumberFromSha ?? context.issue.number;\n\n const { data } = await octokit.pulls.listFiles({\n per_page: 100,\n pull_number,\n ...context.repo\n });\n\n const fileNames = data.map(file => file.filename);\n if (globs) {\n if (paths) core.info('`paths` and `globs` inputs found, defaulting to use `globs` for filtering');\n return micromatch(fileNames, globs.split('\\n')).length > 0;\n } else if (paths) {\n const filePaths = paths.split('\\n');\n return fileNames.some(changedFile => filePaths.some(filePath => changedFile.startsWith(filePath)));\n } else {\n core.error('Must pass `globs` or `paths` for filtering');\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"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"654.index.js","mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAGA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAAA;AACA;AACA;AAAA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC5CA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA;;;;;;;;;;;;;;;ACjEA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACjCA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/helpers/filter-paths.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/merge-queue.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\nimport * as core from '@actions/core';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport micromatch from 'micromatch';\nimport { octokit } from '../octokit';\nimport { getPrNumberFromMergeQueueRef } from '../utils/merge-queue';\n\nexport class FilterPaths extends HelperInputs {\n paths?: string;\n globs?: string;\n}\n\nexport const filterPaths = async ({ paths, globs }: FilterPaths) => {\n const pull_number = context.eventName === 'merge_group' ? getPrNumberFromMergeQueueRef() : context.issue.number;\n\n const { data } = await octokit.pulls.listFiles({\n per_page: 100,\n pull_number,\n ...context.repo\n });\n\n const fileNames = data.map(file => file.filename);\n if (globs) {\n if (paths) core.info('`paths` and `globs` inputs found, defaulting to use `globs` for filtering');\n return micromatch(fileNames, globs.split('\\n')).length > 0;\n } else if (paths) {\n const filePaths = paths.split('\\n');\n return fileNames.some(changedFile => filePaths.some(filePath => changedFile.startsWith(filePath)));\n } else {\n core.error('Must pass `globs` or `paths` for filtering');\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';\nimport { context } from '@actions/github';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n\nexport const getPrNumberFromMergeQueueRef = () => {\n const prNumber = Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n );\n if (isNaN(prNumber)) {\n throw new Error('Could not find PR number in merge queue ref.');\n }\n return prNumber;\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/filter-paths.ts b/src/helpers/filter-paths.ts index e122406b..ee84f4fb 100644 --- a/src/helpers/filter-paths.ts +++ b/src/helpers/filter-paths.ts @@ -16,31 +16,15 @@ import { HelperInputs } from '../types/generated'; import { context } from '@actions/github'; import micromatch from 'micromatch'; import { octokit } from '../octokit'; +import { getPrNumberFromMergeQueueRef } from '../utils/merge-queue'; export class FilterPaths extends HelperInputs { paths?: string; globs?: string; - sha?: string; } -export const filterPaths = async ({ paths, globs, sha }: FilterPaths) => { - const prNumberFromSha = - context.eventName === 'merge_group' - ? Number( - context.ref - .split('/') - .find(part => part.includes('pr-')) - ?.match(/\d+/)?.[0] - ) - : sha - ? ( - await octokit.repos.listPullRequestsAssociatedWithCommit({ - commit_sha: sha, - ...context.repo - }) - ).data.find(Boolean)?.number - : undefined; - const pull_number = prNumberFromSha ?? context.issue.number; +export const filterPaths = async ({ paths, globs }: FilterPaths) => { + const pull_number = context.eventName === 'merge_group' ? getPrNumberFromMergeQueueRef() : context.issue.number; const { data } = await octokit.pulls.listFiles({ per_page: 100, diff --git a/src/helpers/get-merge-queue-position.ts b/src/helpers/get-merge-queue-position.ts index 281cf24f..72b495a1 100644 --- a/src/helpers/get-merge-queue-position.ts +++ b/src/helpers/get-merge-queue-position.ts @@ -15,6 +15,7 @@ import { HelperInputs } from '../types/generated'; import { context } from '@actions/github'; import { octokitGraphql } from '../octokit'; import { Repository } from '@octokit/graphql-schema'; +import { getPrNumberFromMergeQueueRef } from '../utils/merge-queue'; export class GetMergeQueuePosition extends HelperInputs { max_queue_size?: string; @@ -37,12 +38,7 @@ query { } } `); - const prNumberFromMergeQueueRef = Number( - context.ref - .split('/') - .find(part => part.includes('pr-')) - ?.match(/\d+/)?.[0] - ); + const prNumberFromMergeQueueRef = getPrNumberFromMergeQueueRef(); const mergeQueueEntries = repository.mergeQueue?.entries?.nodes; return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === prNumberFromMergeQueueRef)?.position; }; diff --git a/src/helpers/initiate-deployment.ts b/src/helpers/initiate-deployment.ts index 6f4d65bc..b8590f55 100644 --- a/src/helpers/initiate-deployment.ts +++ b/src/helpers/initiate-deployment.ts @@ -17,7 +17,7 @@ import { HelperInputs } from '../types/generated'; import { context as githubContext } from '@actions/github'; import { octokit } from '../octokit'; import { map } from 'bluebird'; -import { getMergeQueueCommitHashes } from '../utils/get-merge-queue-commit-hashes'; +import { getMergeQueueCommitHashes } from '../utils/merge-queue'; export class InitiateDeployment extends HelperInputs { sha = ''; diff --git a/src/helpers/notify-pipeline-complete.ts b/src/helpers/notify-pipeline-complete.ts index c14348ef..88712b9f 100644 --- a/src/helpers/notify-pipeline-complete.ts +++ b/src/helpers/notify-pipeline-complete.ts @@ -16,7 +16,7 @@ import { HelperInputs } from '../types/generated'; import { context as githubContext } from '@actions/github'; import { map } from 'bluebird'; import { octokit } from '../octokit'; -import { getMergeQueueCommitHashes } from '../utils/get-merge-queue-commit-hashes'; +import { getMergeQueueCommitHashes } from '../utils/merge-queue'; export class NotifyPipelineComplete extends HelperInputs { context?: string; diff --git a/src/utils/get-merge-queue-commit-hashes.ts b/src/utils/merge-queue.ts similarity index 71% rename from src/utils/get-merge-queue-commit-hashes.ts rename to src/utils/merge-queue.ts index bc95f442..50ded80f 100644 --- a/src/utils/get-merge-queue-commit-hashes.ts +++ b/src/utils/merge-queue.ts @@ -12,9 +12,23 @@ limitations under the License. */ import { paginateAllBranches } from './paginate-all-branches'; +import { context } from '@actions/github'; export const getMergeQueueCommitHashes = async () => { const branches = await paginateAllBranches(); const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/')); return mergeQueueBranches.map(branch => branch.commit.sha); }; + +export const getPrNumberFromMergeQueueRef = () => { + const prNumber = Number( + context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0] + ); + if (isNaN(prNumber)) { + throw new Error('Could not find PR number in merge queue ref.'); + } + return prNumber; +}; diff --git a/test/helpers/filter-paths.test.ts b/test/helpers/filter-paths.test.ts index f2f189bc..5a17532a 100644 --- a/test/helpers/filter-paths.test.ts +++ b/test/helpers/filter-paths.test.ts @@ -188,28 +188,7 @@ describe('filterPaths', () => { expect(result).toBe(true); }); - it('should call listFiles with correct pull number if sha is provided', async () => { - await filterPaths({ - paths, - sha: 'sha' - }); - - expect(octokit.pulls.listFiles).toHaveBeenCalledWith({ - per_page: 100, - pull_number: 789, - ...context.repo - }); - }); - - it('should not call listPullRequestsAssociatedWithCommit if sha is omitted', async () => { - await filterPaths({ - paths - }); - - expect(octokit.repos.listPullRequestsAssociatedWithCommit).not.toHaveBeenCalled(); - }); - - it('should not call listPullRequestsAssociatedWithCommit if sha is omitted', async () => { + it('should call listFiles with correct pr number in merge queue case', async () => { context.eventName = 'merge_group'; context.ref = 'refs/heads/gh-readonly-queue/default-branch/pr-12345-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f'; await filterPaths({