From 924cc5e6b55277a45073aa87abe4804d31aa94b3 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Mon, 13 Nov 2023 17:05:05 -0500 Subject: [PATCH] fix(manage-merge-queue): commit status being incorrectly set (#488) --- dist/676.index.js | 13 ++++--------- dist/676.index.js.map | 2 +- src/utils/update-merge-queue.ts | 13 ++++--------- test/utils/update-merge-queue.test.ts | 6 ++++++ 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/dist/676.index.js b/dist/676.index.js index 24225b3e9..16b55c584 100644 --- a/dist/676.index.js +++ b/dist/676.index.js @@ -176,14 +176,9 @@ const updateQueuePosition = (pr, index) => __awaiter(void 0, void 0, void 0, fun if (!label || isNaN(queuePosition) || queuePosition === newQueuePosition) { return; } - if (newQueuePosition === 1) { + const prIsNowFirstInQueue = newQueuePosition === 1; + if (prIsNowFirstInQueue) { const { data: firstPrInQueue } = yield octokit/* octokit.pulls.get */.K.pulls.get(Object.assign({ pull_number: number }, github.context.repo)); - yield (0,set_commit_status.setCommitStatus)({ - sha: firstPrInQueue.head.sha, - context: constants/* MERGE_QUEUE_STATUS */.Cb, - state: 'success', - description: 'This PR is next to merge.' - }); yield Promise.all([(0,remove_label.removeLabelIfExists)(constants/* JUMP_THE_QUEUE_PR_LABEL */.nJ, number), (0,prepare_queued_pr_for_merge.updatePrWithDefaultBranch)(firstPrInQueue)]); } return Promise.all([ @@ -192,8 +187,8 @@ const updateQueuePosition = (pr, index) => __awaiter(void 0, void 0, void 0, fun (0,set_commit_status.setCommitStatus)({ sha, context: constants/* MERGE_QUEUE_STATUS */.Cb, - state: 'pending', - description: 'This PR is in line to merge.' + state: prIsNowFirstInQueue ? 'success' : 'pending', + description: `This PR is ${prIsNowFirstInQueue ? 'next' : 'in line'} to merge.` }) ]); }); diff --git a/dist/676.index.js.map b/dist/676.index.js.map index 1673ff476..f620e5d18 100644 --- a/dist/676.index.js.map +++ b/dist/676.index.js.map @@ -1 +1 @@ -{"version":3,"file":"676.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;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3DA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACzEA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAOA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAGA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAKA;AACA;AAAA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;;AAEA;;;;AAIA;AACA;AAAA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;AChHA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAKA;AACA;AACA;AACA;AACA;AAEA;;AACA;AACA;AAEA;AAGA;;AACA;AACA;AACA;AACA;AAIA;AAAA;AACA;AACA;AACA;;AAAA;AACA;AACA;AACA;AACA;AAKA;AAAA;AACA;AACA;AACA;AAAA;AACA;AACA;;AAAA;AACA;AACA;;;;;;;;;;;;;;;;;;;;AClEA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AAEA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AAAA;AAEA;AAEA;AACA;AACA;AAKA;AAAA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;ACrCA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AACA;AAIA;AAAA;AAEA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAGA;AAGA;AACA;;;;;;;;;;;;;;;;;;ACrDA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA2CA;;;;;;;;;;;;;;;;;ACxDA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AACA;AACA;AAQA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;AChDA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AAEA;AACA;AAQA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/utils/update-merge-queue.ts",".././src/helpers/manage-merge-queue.ts",".././src/helpers/prepare-queued-pr-for-merge.ts",".././src/helpers/remove-label.ts",".././src/helpers/set-commit-status.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/notify-user.ts",".././src/utils/paginate-open-pull-requests.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_EXEMPT_DESCRIPTION = 'Passed in case the check is exempt.';\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 { JUMP_THE_QUEUE_PR_LABEL, MERGE_QUEUE_STATUS, QUEUED_FOR_MERGE_PREFIX } from '../constants';\nimport { PullRequestList } from '../types/github';\nimport { context } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { removeLabelIfExists } from '../helpers/remove-label';\nimport { updatePrWithDefaultBranch } from '../helpers/prepare-queued-pr-for-merge';\nimport { setCommitStatus } from '../helpers/set-commit-status';\n\nexport const updateMergeQueue = (queuedPrs: PullRequestList) => {\n const sortedPrs = sortPrsByQueuePosition(queuedPrs);\n return map(sortedPrs, updateQueuePosition);\n};\n\nconst sortPrsByQueuePosition = (queuedPrs: PullRequestList) =>\n queuedPrs\n .map(pr => {\n const label = pr.labels.find(label => label.name?.startsWith(QUEUED_FOR_MERGE_PREFIX))?.name;\n const isJumpingTheQueue = Boolean(pr.labels.find(label => label.name === JUMP_THE_QUEUE_PR_LABEL));\n const queuePosition = isJumpingTheQueue ? 0 : Number(label?.split('#')?.[1]);\n return {\n number: pr.number,\n label,\n queuePosition,\n sha: pr.head.sha\n };\n })\n .sort((pr1, pr2) => pr1.queuePosition - pr2.queuePosition);\n\nconst updateQueuePosition = async (pr: ReturnType[number], index: number) => {\n const { number, label, queuePosition, sha } = pr;\n const newQueuePosition = index + 1;\n if (!label || isNaN(queuePosition) || queuePosition === newQueuePosition) {\n return;\n }\n if (newQueuePosition === 1) {\n const { data: firstPrInQueue } = await octokit.pulls.get({ pull_number: number, ...context.repo });\n await setCommitStatus({\n sha: firstPrInQueue.head.sha,\n context: MERGE_QUEUE_STATUS,\n state: 'success',\n description: 'This PR is next to merge.'\n });\n await Promise.all([removeLabelIfExists(JUMP_THE_QUEUE_PR_LABEL, number), updatePrWithDefaultBranch(firstPrInQueue)]);\n }\n\n return Promise.all([\n octokit.issues.addLabels({\n labels: [`${QUEUED_FOR_MERGE_PREFIX} #${newQueuePosition}`],\n issue_number: number,\n ...context.repo\n }),\n removeLabelIfExists(label, number),\n setCommitStatus({\n sha,\n context: MERGE_QUEUE_STATUS,\n state: 'pending',\n description: 'This PR is in line to merge.'\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 {\n FIRST_QUEUED_PR_LABEL,\n JUMP_THE_QUEUE_PR_LABEL,\n MERGE_QUEUE_STATUS,\n QUEUED_FOR_MERGE_PREFIX,\n READY_FOR_MERGE_PR_LABEL\n} from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { PullRequest, PullRequestList } from '../types/github';\nimport { context } from '@actions/github';\nimport { map } from 'bluebird';\nimport { notifyUser } from '../utils/notify-user';\nimport { octokit, octokitGraphql } from '../octokit';\nimport { removeLabelIfExists } from './remove-label';\nimport { setCommitStatus } from './set-commit-status';\nimport { updateMergeQueue } from '../utils/update-merge-queue';\nimport { paginateAllOpenPullRequests } from '../utils/paginate-open-pull-requests';\n\nexport class ManageMergeQueue extends HelperInputs {\n login?: string;\n slack_webhook_url?: string;\n}\n\nexport const manageMergeQueue = async ({ login, slack_webhook_url }: ManageMergeQueue = {}) => {\n const { data: pullRequest } = await octokit.pulls.get({ pull_number: context.issue.number, ...context.repo });\n if (pullRequest.merged || !pullRequest.labels.find(label => label.name === READY_FOR_MERGE_PR_LABEL)) {\n core.info('This PR is not in the merge queue.');\n return removePrFromQueue(pullRequest);\n }\n const queuedPrs = await getQueuedPullRequests();\n const queuePosition = queuedPrs.length;\n if (pullRequest.labels.find(label => label.name === JUMP_THE_QUEUE_PR_LABEL)) {\n return updateMergeQueue(queuedPrs);\n }\n if (!pullRequest.labels.find(label => label.name?.startsWith(QUEUED_FOR_MERGE_PREFIX))) {\n await addPrToQueue(pullRequest, queuePosition);\n }\n\n const isFirstQueuePosition = queuePosition === 1 || pullRequest.labels.find(label => label.name === FIRST_QUEUED_PR_LABEL);\n await setCommitStatus({\n sha: pullRequest.head.sha,\n context: MERGE_QUEUE_STATUS,\n state: isFirstQueuePosition ? 'success' : 'pending',\n description: isFirstQueuePosition ? 'This PR is next to merge.' : 'This PR is in line to merge.'\n });\n\n if (slack_webhook_url && login && queuePosition === 1) {\n await notifyUser({\n login,\n pull_number: context.issue.number,\n slack_webhook_url\n });\n }\n};\n\nexport const removePrFromQueue = async (pullRequest: PullRequest) => {\n const queueLabel = pullRequest.labels.find(label => label.name?.startsWith(QUEUED_FOR_MERGE_PREFIX))?.name;\n if (queueLabel) {\n await map([READY_FOR_MERGE_PR_LABEL, queueLabel], async label => removeLabelIfExists(label, pullRequest.number));\n await setCommitStatus({\n sha: pullRequest.head.sha,\n context: MERGE_QUEUE_STATUS,\n state: 'pending',\n description: 'This PR is not in the merge queue.'\n });\n const queuedPrs = await getQueuedPullRequests();\n await updateMergeQueue(queuedPrs);\n }\n};\n\nconst addPrToQueue = async (pullRequest: PullRequest, queuePosition: number) =>\n Promise.all([\n octokit.issues.addLabels({\n labels: [`${QUEUED_FOR_MERGE_PREFIX} #${queuePosition}`],\n issue_number: context.issue.number,\n ...context.repo\n }),\n enableAutoMerge(pullRequest.node_id)\n ]);\n\nconst getQueuedPullRequests = async (): Promise => {\n const openPullRequests = await paginateAllOpenPullRequests();\n return openPullRequests.filter(pr => pr.labels.some(label => label.name === READY_FOR_MERGE_PR_LABEL));\n};\n\nexport const enableAutoMerge = async (pullRequestId: string, mergeMethod = 'SQUASH') => {\n try {\n return await octokitGraphql(`\n mutation {\n enablePullRequestAutoMerge(input: { pullRequestId: \"${pullRequestId}\", mergeMethod: ${mergeMethod} }) {\n clientMutationId\n }\n }\n `);\n } catch (error) {\n core.warning('Auto merge could not be enabled. Perhaps you need to enable auto-merge on your repo?');\n core.warning(error as Error);\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 { FIRST_QUEUED_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL, READY_FOR_MERGE_PR_LABEL } from '../constants';\nimport { GithubError, PullRequest, PullRequestList, SinglePullRequest } from '../types/github';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { removePrFromQueue } from './manage-merge-queue';\n\nexport const prepareQueuedPrForMerge = async () => {\n const { data } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...context.repo\n });\n const pullRequest = findNextPrToMerge(data);\n if (pullRequest) {\n return updatePrWithDefaultBranch(pullRequest as PullRequest);\n }\n};\n\nconst findNextPrToMerge = (pullRequests: PullRequestList) =>\n pullRequests.find(pr => hasRequiredLabels(pr, [READY_FOR_MERGE_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL])) ??\n pullRequests.find(pr => hasRequiredLabels(pr, [READY_FOR_MERGE_PR_LABEL, FIRST_QUEUED_PR_LABEL]));\n\nconst hasRequiredLabels = (pr: SinglePullRequest, requiredLabels: string[]) =>\n requiredLabels.every(mergeQueueLabel => pr.labels.some(label => label.name === mergeQueueLabel));\n\nexport const updatePrWithDefaultBranch = async (pullRequest: PullRequest) => {\n if (pullRequest.head.user?.login && pullRequest.base.user?.login && pullRequest.head.user?.login !== pullRequest.base.user?.login) {\n try {\n // update fork default branch with upstream\n await octokit.repos.mergeUpstream({\n ...context.repo,\n branch: pullRequest.base.repo.default_branch\n });\n } catch (error) {\n if ((error as GithubError).status === 409) {\n core.setFailed('Attempt to update fork branch with upstream failed; conflict on default branch between fork and upstream.');\n } else core.setFailed((error as GithubError).message);\n }\n }\n try {\n await octokit.repos.merge({\n base: pullRequest.head.ref,\n head: 'HEAD',\n ...context.repo\n });\n } catch (error) {\n const noEvictUponConflict = core.getBooleanInput('no_evict_upon_conflict');\n if ((error as GithubError).status === 409) {\n if (!noEvictUponConflict) await removePrFromQueue(pullRequest);\n core.setFailed('The first PR in the queue has a merge conflict.');\n } else core.setFailed((error as GithubError).message);\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 { GithubError } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class RemoveLabel extends HelperInputs {\n label = '';\n}\n\nexport const removeLabel = async ({ label }: RemoveLabel) => removeLabelIfExists(label, context.issue.number);\n\nexport const removeLabelIfExists = async (labelName: string, issue_number: number) => {\n try {\n await octokit.issues.removeLabel({\n name: labelName,\n issue_number,\n ...context.repo\n });\n } catch (error) {\n if ((error as GithubError).status === 404) {\n core.info('Label is not present on PR.');\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 { PipelineState } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\n\nexport class SetCommitStatus extends HelperInputs {\n sha = '';\n context = '';\n state = '';\n description?: string;\n target_url?: string;\n skip_if_already_set?: string;\n}\n\nexport const setCommitStatus = async ({ sha, context, state, description, target_url, skip_if_already_set }: SetCommitStatus) => {\n await map(context.split('\\n').filter(Boolean), async context => {\n if (skip_if_already_set === 'true') {\n const check_runs = await octokit.checks.listForRef({\n ...githubContext.repo,\n ref: sha\n });\n const run = check_runs.data.check_runs.find(({ name }) => name === context);\n const runCompletedAndIsValid = run?.status === 'completed' && (run?.conclusion === 'failure' || run?.conclusion === 'success');\n if (runCompletedAndIsValid) {\n core.info(`${context} already completed with a ${run.conclusion} conclusion.`);\n return;\n }\n }\n\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\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 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}\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 axios from 'axios';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\ninterface NotifyUser {\n login: string;\n pull_number: number;\n slack_webhook_url: string;\n}\n\nexport const notifyUser = async ({ login, pull_number, slack_webhook_url }: NotifyUser) => {\n core.info(`Notifying user ${login}...`);\n const {\n data: { email }\n } = await octokit.users.getByUsername({ username: login });\n if (!email) {\n core.info(`No github email found for user ${login}. Ensure you have set your email to be publicly visible on your Github profile.`);\n return;\n }\n const {\n data: { title, html_url }\n } = await octokit.pulls.get({ pull_number, ...context.repo });\n\n try {\n await axios.post(slack_webhook_url, {\n assignee: email,\n title,\n html_url,\n repo: context.repo.repo\n });\n } catch (error) {\n core.warning('User notification failed');\n core.warning(error as Error);\n }\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 { PullRequestList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllOpenPullRequests = async (page = 1): Promise => {\n const response = await octokit.pulls.list({\n state: 'open',\n sort: 'updated',\n direction: 'desc',\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return response.data.concat(await paginateAllOpenPullRequests(page + 1));\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"676.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;AACA;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3DA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACpEA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAOA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAGA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAKA;AACA;AAAA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;;AAEA;;;;AAIA;AACA;AAAA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;AChHA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAKA;AACA;AACA;AACA;AACA;AAEA;;AACA;AACA;AAEA;AAGA;;AACA;AACA;AACA;AACA;AAIA;AAAA;AACA;AACA;AACA;;AAAA;AACA;AACA;AACA;AACA;AAKA;AAAA;AACA;AACA;AACA;AAAA;AACA;AACA;;AAAA;AACA;AACA;;;;;;;;;;;;;;;;;;;;AClEA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AAEA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AAAA;AAEA;AAEA;AACA;AACA;AAKA;AAAA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;ACrCA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AACA;AAIA;AAAA;AAEA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAGA;AAGA;AACA;;;;;;;;;;;;;;;;;;ACrDA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA2CA;;;;;;;;;;;;;;;;;ACxDA;;;;;;;;;;;AAWA;;;;;;;;;;AAEA;AACA;AACA;AACA;AAQA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;AChDA;;;;;;;;;;;AAWA;;;;;;;;;;AAGA;AACA;AAEA;AACA;AAQA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/utils/update-merge-queue.ts",".././src/helpers/manage-merge-queue.ts",".././src/helpers/prepare-queued-pr-for-merge.ts",".././src/helpers/remove-label.ts",".././src/helpers/set-commit-status.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/notify-user.ts",".././src/utils/paginate-open-pull-requests.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_EXEMPT_DESCRIPTION = 'Passed in case the check is exempt.';\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 { JUMP_THE_QUEUE_PR_LABEL, MERGE_QUEUE_STATUS, QUEUED_FOR_MERGE_PREFIX } from '../constants';\nimport { PullRequestList } from '../types/github';\nimport { context } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { removeLabelIfExists } from '../helpers/remove-label';\nimport { updatePrWithDefaultBranch } from '../helpers/prepare-queued-pr-for-merge';\nimport { setCommitStatus } from '../helpers/set-commit-status';\n\nexport const updateMergeQueue = (queuedPrs: PullRequestList) => {\n const sortedPrs = sortPrsByQueuePosition(queuedPrs);\n return map(sortedPrs, updateQueuePosition);\n};\n\nconst sortPrsByQueuePosition = (queuedPrs: PullRequestList) =>\n queuedPrs\n .map(pr => {\n const label = pr.labels.find(label => label.name?.startsWith(QUEUED_FOR_MERGE_PREFIX))?.name;\n const isJumpingTheQueue = Boolean(pr.labels.find(label => label.name === JUMP_THE_QUEUE_PR_LABEL));\n const queuePosition = isJumpingTheQueue ? 0 : Number(label?.split('#')?.[1]);\n return {\n number: pr.number,\n label,\n queuePosition,\n sha: pr.head.sha\n };\n })\n .sort((pr1, pr2) => pr1.queuePosition - pr2.queuePosition);\n\nconst updateQueuePosition = async (pr: ReturnType[number], index: number) => {\n const { number, label, queuePosition, sha } = pr;\n const newQueuePosition = index + 1;\n if (!label || isNaN(queuePosition) || queuePosition === newQueuePosition) {\n return;\n }\n const prIsNowFirstInQueue = newQueuePosition === 1;\n if (prIsNowFirstInQueue) {\n const { data: firstPrInQueue } = await octokit.pulls.get({ pull_number: number, ...context.repo });\n await Promise.all([removeLabelIfExists(JUMP_THE_QUEUE_PR_LABEL, number), updatePrWithDefaultBranch(firstPrInQueue)]);\n }\n\n return Promise.all([\n octokit.issues.addLabels({\n labels: [`${QUEUED_FOR_MERGE_PREFIX} #${newQueuePosition}`],\n issue_number: number,\n ...context.repo\n }),\n removeLabelIfExists(label, number),\n setCommitStatus({\n sha,\n context: MERGE_QUEUE_STATUS,\n state: prIsNowFirstInQueue ? 'success' : 'pending',\n description: `This PR is ${prIsNowFirstInQueue ? 'next' : 'in line'} to merge.`\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 {\n FIRST_QUEUED_PR_LABEL,\n JUMP_THE_QUEUE_PR_LABEL,\n MERGE_QUEUE_STATUS,\n QUEUED_FOR_MERGE_PREFIX,\n READY_FOR_MERGE_PR_LABEL\n} from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { PullRequest, PullRequestList } from '../types/github';\nimport { context } from '@actions/github';\nimport { map } from 'bluebird';\nimport { notifyUser } from '../utils/notify-user';\nimport { octokit, octokitGraphql } from '../octokit';\nimport { removeLabelIfExists } from './remove-label';\nimport { setCommitStatus } from './set-commit-status';\nimport { updateMergeQueue } from '../utils/update-merge-queue';\nimport { paginateAllOpenPullRequests } from '../utils/paginate-open-pull-requests';\n\nexport class ManageMergeQueue extends HelperInputs {\n login?: string;\n slack_webhook_url?: string;\n}\n\nexport const manageMergeQueue = async ({ login, slack_webhook_url }: ManageMergeQueue = {}) => {\n const { data: pullRequest } = await octokit.pulls.get({ pull_number: context.issue.number, ...context.repo });\n if (pullRequest.merged || !pullRequest.labels.find(label => label.name === READY_FOR_MERGE_PR_LABEL)) {\n core.info('This PR is not in the merge queue.');\n return removePrFromQueue(pullRequest);\n }\n const queuedPrs = await getQueuedPullRequests();\n const queuePosition = queuedPrs.length;\n if (pullRequest.labels.find(label => label.name === JUMP_THE_QUEUE_PR_LABEL)) {\n return updateMergeQueue(queuedPrs);\n }\n if (!pullRequest.labels.find(label => label.name?.startsWith(QUEUED_FOR_MERGE_PREFIX))) {\n await addPrToQueue(pullRequest, queuePosition);\n }\n\n const isFirstQueuePosition = queuePosition === 1 || pullRequest.labels.find(label => label.name === FIRST_QUEUED_PR_LABEL);\n await setCommitStatus({\n sha: pullRequest.head.sha,\n context: MERGE_QUEUE_STATUS,\n state: isFirstQueuePosition ? 'success' : 'pending',\n description: isFirstQueuePosition ? 'This PR is next to merge.' : 'This PR is in line to merge.'\n });\n\n if (slack_webhook_url && login && queuePosition === 1) {\n await notifyUser({\n login,\n pull_number: context.issue.number,\n slack_webhook_url\n });\n }\n};\n\nexport const removePrFromQueue = async (pullRequest: PullRequest) => {\n const queueLabel = pullRequest.labels.find(label => label.name?.startsWith(QUEUED_FOR_MERGE_PREFIX))?.name;\n if (queueLabel) {\n await map([READY_FOR_MERGE_PR_LABEL, queueLabel], async label => removeLabelIfExists(label, pullRequest.number));\n await setCommitStatus({\n sha: pullRequest.head.sha,\n context: MERGE_QUEUE_STATUS,\n state: 'pending',\n description: 'This PR is not in the merge queue.'\n });\n const queuedPrs = await getQueuedPullRequests();\n await updateMergeQueue(queuedPrs);\n }\n};\n\nconst addPrToQueue = async (pullRequest: PullRequest, queuePosition: number) =>\n Promise.all([\n octokit.issues.addLabels({\n labels: [`${QUEUED_FOR_MERGE_PREFIX} #${queuePosition}`],\n issue_number: context.issue.number,\n ...context.repo\n }),\n enableAutoMerge(pullRequest.node_id)\n ]);\n\nconst getQueuedPullRequests = async (): Promise => {\n const openPullRequests = await paginateAllOpenPullRequests();\n return openPullRequests.filter(pr => pr.labels.some(label => label.name === READY_FOR_MERGE_PR_LABEL));\n};\n\nexport const enableAutoMerge = async (pullRequestId: string, mergeMethod = 'SQUASH') => {\n try {\n return await octokitGraphql(`\n mutation {\n enablePullRequestAutoMerge(input: { pullRequestId: \"${pullRequestId}\", mergeMethod: ${mergeMethod} }) {\n clientMutationId\n }\n }\n `);\n } catch (error) {\n core.warning('Auto merge could not be enabled. Perhaps you need to enable auto-merge on your repo?');\n core.warning(error as Error);\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 { FIRST_QUEUED_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL, READY_FOR_MERGE_PR_LABEL } from '../constants';\nimport { GithubError, PullRequest, PullRequestList, SinglePullRequest } from '../types/github';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { removePrFromQueue } from './manage-merge-queue';\n\nexport const prepareQueuedPrForMerge = async () => {\n const { data } = await octokit.pulls.list({\n state: 'open',\n per_page: 100,\n ...context.repo\n });\n const pullRequest = findNextPrToMerge(data);\n if (pullRequest) {\n return updatePrWithDefaultBranch(pullRequest as PullRequest);\n }\n};\n\nconst findNextPrToMerge = (pullRequests: PullRequestList) =>\n pullRequests.find(pr => hasRequiredLabels(pr, [READY_FOR_MERGE_PR_LABEL, JUMP_THE_QUEUE_PR_LABEL])) ??\n pullRequests.find(pr => hasRequiredLabels(pr, [READY_FOR_MERGE_PR_LABEL, FIRST_QUEUED_PR_LABEL]));\n\nconst hasRequiredLabels = (pr: SinglePullRequest, requiredLabels: string[]) =>\n requiredLabels.every(mergeQueueLabel => pr.labels.some(label => label.name === mergeQueueLabel));\n\nexport const updatePrWithDefaultBranch = async (pullRequest: PullRequest) => {\n if (pullRequest.head.user?.login && pullRequest.base.user?.login && pullRequest.head.user?.login !== pullRequest.base.user?.login) {\n try {\n // update fork default branch with upstream\n await octokit.repos.mergeUpstream({\n ...context.repo,\n branch: pullRequest.base.repo.default_branch\n });\n } catch (error) {\n if ((error as GithubError).status === 409) {\n core.setFailed('Attempt to update fork branch with upstream failed; conflict on default branch between fork and upstream.');\n } else core.setFailed((error as GithubError).message);\n }\n }\n try {\n await octokit.repos.merge({\n base: pullRequest.head.ref,\n head: 'HEAD',\n ...context.repo\n });\n } catch (error) {\n const noEvictUponConflict = core.getBooleanInput('no_evict_upon_conflict');\n if ((error as GithubError).status === 409) {\n if (!noEvictUponConflict) await removePrFromQueue(pullRequest);\n core.setFailed('The first PR in the queue has a merge conflict.');\n } else core.setFailed((error as GithubError).message);\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 { GithubError } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class RemoveLabel extends HelperInputs {\n label = '';\n}\n\nexport const removeLabel = async ({ label }: RemoveLabel) => removeLabelIfExists(label, context.issue.number);\n\nexport const removeLabelIfExists = async (labelName: string, issue_number: number) => {\n try {\n await octokit.issues.removeLabel({\n name: labelName,\n issue_number,\n ...context.repo\n });\n } catch (error) {\n if ((error as GithubError).status === 404) {\n core.info('Label is not present on PR.');\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 { PipelineState } from '../types/github';\nimport { HelperInputs } from '../types/generated';\nimport { context as githubContext } from '@actions/github';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\n\nexport class SetCommitStatus extends HelperInputs {\n sha = '';\n context = '';\n state = '';\n description?: string;\n target_url?: string;\n skip_if_already_set?: string;\n}\n\nexport const setCommitStatus = async ({ sha, context, state, description, target_url, skip_if_already_set }: SetCommitStatus) => {\n await map(context.split('\\n').filter(Boolean), async context => {\n if (skip_if_already_set === 'true') {\n const check_runs = await octokit.checks.listForRef({\n ...githubContext.repo,\n ref: sha\n });\n const run = check_runs.data.check_runs.find(({ name }) => name === context);\n const runCompletedAndIsValid = run?.status === 'completed' && (run?.conclusion === 'failure' || run?.conclusion === 'success');\n if (runCompletedAndIsValid) {\n core.info(`${context} already completed with a ${run.conclusion} conclusion.`);\n return;\n }\n }\n\n octokit.repos.createCommitStatus({\n sha,\n context,\n state: state as PipelineState,\n description,\n target_url,\n ...githubContext.repo\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 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}\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 axios from 'axios';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\ninterface NotifyUser {\n login: string;\n pull_number: number;\n slack_webhook_url: string;\n}\n\nexport const notifyUser = async ({ login, pull_number, slack_webhook_url }: NotifyUser) => {\n core.info(`Notifying user ${login}...`);\n const {\n data: { email }\n } = await octokit.users.getByUsername({ username: login });\n if (!email) {\n core.info(`No github email found for user ${login}. Ensure you have set your email to be publicly visible on your Github profile.`);\n return;\n }\n const {\n data: { title, html_url }\n } = await octokit.pulls.get({ pull_number, ...context.repo });\n\n try {\n await axios.post(slack_webhook_url, {\n assignee: email,\n title,\n html_url,\n repo: context.repo.repo\n });\n } catch (error) {\n core.warning('User notification failed');\n core.warning(error as Error);\n }\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 { PullRequestList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllOpenPullRequests = async (page = 1): Promise => {\n const response = await octokit.pulls.list({\n state: 'open',\n sort: 'updated',\n direction: 'desc',\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return response.data.concat(await paginateAllOpenPullRequests(page + 1));\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/utils/update-merge-queue.ts b/src/utils/update-merge-queue.ts index 6be451c7d..bad6c352c 100644 --- a/src/utils/update-merge-queue.ts +++ b/src/utils/update-merge-queue.ts @@ -46,14 +46,9 @@ const updateQueuePosition = async (pr: ReturnType if (!label || isNaN(queuePosition) || queuePosition === newQueuePosition) { return; } - if (newQueuePosition === 1) { + const prIsNowFirstInQueue = newQueuePosition === 1; + if (prIsNowFirstInQueue) { const { data: firstPrInQueue } = await octokit.pulls.get({ pull_number: number, ...context.repo }); - await setCommitStatus({ - sha: firstPrInQueue.head.sha, - context: MERGE_QUEUE_STATUS, - state: 'success', - description: 'This PR is next to merge.' - }); await Promise.all([removeLabelIfExists(JUMP_THE_QUEUE_PR_LABEL, number), updatePrWithDefaultBranch(firstPrInQueue)]); } @@ -67,8 +62,8 @@ const updateQueuePosition = async (pr: ReturnType setCommitStatus({ sha, context: MERGE_QUEUE_STATUS, - state: 'pending', - description: 'This PR is in line to merge.' + state: prIsNowFirstInQueue ? 'success' : 'pending', + description: `This PR is ${prIsNowFirstInQueue ? 'next' : 'in line'} to merge.` }) ]); }; diff --git a/test/utils/update-merge-queue.test.ts b/test/utils/update-merge-queue.test.ts index 5a874c110..d22b91ae9 100644 --- a/test/utils/update-merge-queue.test.ts +++ b/test/utils/update-merge-queue.test.ts @@ -167,6 +167,12 @@ describe('updateMergeQueue', () => { state: 'success', description: 'This PR is next to merge.' }); + expect(setCommitStatus).not.toHaveBeenCalledWith({ + sha: 'sha123', + context: MERGE_QUEUE_STATUS, + state: 'pending', + description: 'This PR is in line to merge.' + }); }); it('should update pr with default branch', () => {