From cd7ad3ffce85c814b9bb64571e8cf4e4e91a14de Mon Sep 17 00:00:00 2001 From: Amanda Olsen Date: Wed, 3 Apr 2024 15:56:28 -0500 Subject: [PATCH 1/2] Update close-pr to support other repos, etc --- README.md | 10 +-- action.yml | 6 ++ src/helpers/close-pr.ts | 17 +++-- src/helpers/create-pr-comment.ts | 35 +++++++---- test/helpers/close-pr.test.ts | 87 +++++++++++++++++++++++++- test/helpers/create-pr-comment.test.ts | 19 +++++- 6 files changed, 149 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 38aa00e76..cca30a365 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,11 @@ The following parameters can be used for additional control over when it is safe ### [close-pr](.github/workflows/close-pr.yml) -- Closes a pull request +- Closes a pull request in your current repo or in another repo. ### [create-pr](.github/workflows/create-pr.yml) -- Opens a pull request +- Opens a pull request. ### [create-project-card](.github/workflows/create-project-card.yml) @@ -143,7 +143,7 @@ The following parameters can be used for additional control over when it is safe ### [create-pr-comment](.github/workflows/create-pr-comment.yml) -- Comments on a pull request or other issue +- Comments on a pull request or other issue in your current repo or in another repo ### [delete-stale-branches](.github/workflows/delete-stale-branches.yml) @@ -209,6 +209,7 @@ Additionally, the following parameters can be used for additional control over t - When a PR is merged, it automatically updates the first-queued PR with the default branch. - You can also pass `login` and `slack_webhook_url` to notify the PR author when they are in the 1st position of the merge queue. - Passing `skip_auto_merge: true` changes the default behaviour of automatically enabling auto-merge for PRs from the merge queue. In such case auto-merging should be enabled manually on individual PRs. It can be useful to avoid unattended deployments in case of CICD pipelines which are not fully prepared for continuous deployment. + ### [move-project-card](.github/workflows/move-project-card.yml) - Moves a GitHub Project card to a new column, using the `project_origin_column_name` and`project_destination_column_name` you provide. @@ -248,8 +249,9 @@ Additionally, the following parameters can be used for additional control over t - Determines whether the pipeline is clear for a PR. This means it will set the "pipeline" commit status to `pending` if there is an in-progress production deployment for the repo, and `success` otherwise. ### [update-check-result](.github/workflows/update-check-result.yml) + - -- Updates the result of a previous PR check tied to a commit status. +- Updates the result of a previous PR check tied to a commit status. ## Legal diff --git a/action.yml b/action.yml index 4aa1ad8bd..431d39688 100644 --- a/action.yml +++ b/action.yml @@ -134,6 +134,12 @@ inputs: skip_auto_merge: description: 'Do not enable auto-merge automatically for the PRs from the merge queue' required: false + repo_name: + description: 'Repository to interact with' + required: false + repo_owner_name: + description: 'Organization in which repository is stored' + required: false outputs: output: description: 'The output of the helper' diff --git a/src/helpers/close-pr.ts b/src/helpers/close-pr.ts index b41a310b8..8882e3939 100644 --- a/src/helpers/close-pr.ts +++ b/src/helpers/close-pr.ts @@ -18,16 +18,23 @@ import { createPrComment } from './create-pr-comment'; export class ClosePr extends HelperInputs { body?: string; + pull_number?: string; + repo_name?: string; + repo_owner_name?: string; } -export const closePr = async ({ body }: ClosePr = {}) => { +export const closePr = async ({ body, pull_number, repo_name, repo_owner_name }: ClosePr = {}) => { + if ((repo_name || repo_owner_name) && !pull_number) { + throw new Error('pull_number is required when repo_name or repo_owner_name is provided'); + } if (body) { - await createPrComment({ body }); + await createPrComment({ body, pull_number, repo_name, repo_owner_name }); } return octokit.pulls.update({ - pull_number: context.issue.number, - state: 'closed', - ...context.repo + pull_number: pull_number ? Number(pull_number) : context.issue.number, + repo: repo_name ?? context.repo.repo, + owner: repo_owner_name ?? context.repo.owner, + state: 'closed' }); }; diff --git a/src/helpers/create-pr-comment.ts b/src/helpers/create-pr-comment.ts index b927e8a4e..5e07528c2 100644 --- a/src/helpers/create-pr-comment.ts +++ b/src/helpers/create-pr-comment.ts @@ -20,16 +20,20 @@ export class CreatePrComment extends HelperInputs { body = ''; sha?: string; login?: string; + pull_number?: string; + repo_name?: string; + repo_owner_name?: string; } const emptyResponse = { data: [] }; -const getPrsByCommit = async (sha?: string) => { +const getFirstPrByCommit = async (sha?: string, repo_name?: string, repo_owner_name?: string) => { const prs = (sha && (await octokit.repos.listPullRequestsAssociatedWithCommit({ commit_sha: sha, - ...context.repo, + repo: repo_name ?? context.repo.repo, + owner: repo_owner_name ?? context.repo.owner, ...GITHUB_OPTIONS }))) || emptyResponse; @@ -37,42 +41,47 @@ const getPrsByCommit = async (sha?: string) => { return prs.data.find(Boolean)?.number; }; -const getCommentByUser = async (login?: string) => { +const getCommentByUser = async (login?: string, pull_number?: string, repo_name?: string, repo_owner_name?: string) => { const comments = (login && (await octokit.issues.listComments({ - issue_number: context.issue.number, - ...context.repo + issue_number: pull_number ? Number(pull_number) : context.issue.number, + repo: repo_name ?? context.repo.repo, + owner: repo_owner_name ?? context.repo.owner }))) || emptyResponse; return comments.data.find(comment => comment?.user?.login === login)?.id; }; -export const createPrComment = async ({ body, sha, login }: CreatePrComment) => { +export const createPrComment = async ({ body, sha, login, pull_number, repo_name, repo_owner_name }: CreatePrComment) => { + const defaultPrNumber = context.issue.number; + if (!sha && !login) { return octokit.issues.createComment({ body, - issue_number: context.issue.number, - ...context.repo + issue_number: pull_number ? Number(pull_number) : defaultPrNumber, + repo: repo_name ?? context.repo.repo, + owner: repo_owner_name ?? context.repo.owner }); } - const defaultPrNumber = context.issue.number; - const prNumber = (await getPrsByCommit(sha)) ?? defaultPrNumber; - const commentId = await getCommentByUser(login); + const prNumber = (await getFirstPrByCommit(sha, repo_name, repo_owner_name)) ?? (pull_number ? Number(pull_number) : defaultPrNumber); + const commentId = await getCommentByUser(login, pull_number, repo_name, repo_owner_name); if (commentId) { return octokit.issues.updateComment({ comment_id: commentId, body, - ...context.repo + repo: repo_name ?? context.repo.repo, + owner: repo_owner_name ?? context.repo.owner }); } else { return octokit.issues.createComment({ body, issue_number: prNumber, - ...context.repo + repo: repo_name ?? context.repo.repo, + owner: repo_owner_name ?? context.repo.owner }); } }; diff --git a/test/helpers/close-pr.test.ts b/test/helpers/close-pr.test.ts index 75de2d306..effed53a5 100644 --- a/test/helpers/close-pr.test.ts +++ b/test/helpers/close-pr.test.ts @@ -28,7 +28,7 @@ jest.mock('@actions/github', () => ({ })); describe('closePr', () => { - describe('without comment', () => { + describe('without comment in the same PR', () => { beforeEach(() => { closePr(); }); @@ -46,7 +46,44 @@ describe('closePr', () => { }); }); - describe('with comment', () => { + describe('without comment in different PR', () => { + beforeEach(() => { + closePr({ pull_number: '456' }); + }); + + it('should not call createPrComment', () => { + expect(createPrComment).not.toHaveBeenCalled(); + }); + + it('should call pulls.update with correct params', () => { + expect(octokit.pulls.update).toHaveBeenCalledWith({ + pull_number: 456, + state: 'closed', + ...context.repo + }); + }); + }); + + describe('without comment in different repo', () => { + beforeEach(() => { + closePr({ repo_name: 'another-repo', repo_owner_name: 'another-owner', pull_number: '456' }); + }); + + it('should not call createPrComment', () => { + expect(createPrComment).not.toHaveBeenCalled(); + }); + + it('should call pulls.update with correct params', () => { + expect(octokit.pulls.update).toHaveBeenCalledWith({ + pull_number: 456, + state: 'closed', + repo: 'another-repo', + owner: 'another-owner' + }); + }); + }); + + describe('with comment in the same PR', () => { const body = 'some comment'; beforeEach(() => { @@ -65,4 +102,50 @@ describe('closePr', () => { }); }); }); + + describe('with comment in different PR', () => { + const body = 'some comment'; + + beforeEach(() => { + closePr({ body, pull_number: '456' }); + }); + + it('should call createPrComment', () => { + expect(createPrComment).toHaveBeenCalledWith({ body, pull_number: '456' }); + }); + + it('should call pulls.update with correct params', () => { + expect(octokit.pulls.update).toHaveBeenCalledWith({ + pull_number: 456, + state: 'closed', + ...context.repo + }); + }); + }); + + describe('with comment in different repo', () => { + const body = 'some comment'; + + beforeEach(() => { + closePr({ body, repo_name: 'another-repo', repo_owner_name: 'another-owner', pull_number: '456' }); + }); + + it('should call createPrComment', () => { + expect(createPrComment).toHaveBeenCalledWith({ + body, + repo_name: 'another-repo', + repo_owner_name: 'another-owner', + pull_number: '456' + }); + }); + + it('should call pulls.update with correct params', () => { + expect(octokit.pulls.update).toHaveBeenCalledWith({ + pull_number: 456, + state: 'closed', + repo: 'another-repo', + owner: 'another-owner' + }); + }); + }); }); diff --git a/test/helpers/create-pr-comment.test.ts b/test/helpers/create-pr-comment.test.ts index dcc254dfe..e2fcbf3e8 100644 --- a/test/helpers/create-pr-comment.test.ts +++ b/test/helpers/create-pr-comment.test.ts @@ -64,7 +64,7 @@ jest.mock('@actions/github', () => ({ })); describe('createPrComment', () => { - describe('create comment case', () => { + describe('create comment in same PR', () => { const body = 'body'; beforeEach(() => { @@ -80,6 +80,23 @@ describe('createPrComment', () => { }); }); + describe('create comment in other repo', () => { + const body = 'body'; + + beforeEach(() => { + createPrComment({ body, repo_name: 'another-repo', repo_owner_name: 'another-owner', pull_number: '456' }); + }); + + it('should call createComment with correct params', () => { + expect(octokit.issues.createComment).toHaveBeenCalledWith({ + body, + issue_number: 456, + repo: 'another-repo', + owner: 'another-owner' + }); + }); + }); + describe('create comment case - sha supplied', () => { const body = 'body'; const sha = 'sha'; From 178a246b5aeee0db0ca87ddfced8e28bf57d4005 Mon Sep 17 00:00:00 2001 From: amandaolsen Date: Thu, 4 Apr 2024 21:05:12 +0000 Subject: [PATCH 2/2] chore: committing generated dist --- dist/461.index.js | 31 ++++++++++++++++------------- dist/461.index.js.map | 2 +- dist/676.index.js | 31 ++++++++++++++++------------- dist/676.index.js.map | 2 +- dist/830.index.js | 45 ++++++++++++++++++++++++++----------------- dist/830.index.js.map | 2 +- dist/action.yml | 6 ++++++ 7 files changed, 72 insertions(+), 47 deletions(-) diff --git a/dist/461.index.js b/dist/461.index.js index a2d49023c..36ee6148e 100644 --- a/dist/461.index.js +++ b/dist/461.index.js @@ -125,48 +125,53 @@ class CreatePrComment extends _types_generated__WEBPACK_IMPORTED_MODULE_3__/* .H } } const emptyResponse = { data: [] }; -const getPrsByCommit = async (sha) => { +const getFirstPrByCommit = async (sha, repo_name, repo_owner_name) => { const prs = (sha && (await _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.listPullRequestsAssociatedWithCommit */ .K.repos.listPullRequestsAssociatedWithCommit({ commit_sha: sha, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner, ..._constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .Cc }))) || emptyResponse; return prs.data.find(Boolean)?.number; }; -const getCommentByUser = async (login) => { +const getCommentByUser = async (login, pull_number, repo_name, repo_owner_name) => { const comments = (login && (await _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.listComments */ .K.issues.listComments({ - issue_number: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + issue_number: pull_number ? Number(pull_number) : _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }))) || emptyResponse; return comments.data.find(comment => comment?.user?.login === login)?.id; }; -const createPrComment = async ({ body, sha, login }) => { +const createPrComment = async ({ body, sha, login, pull_number, repo_name, repo_owner_name }) => { + const defaultPrNumber = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; if (!sha && !login) { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.createComment */ .K.issues.createComment({ body, - issue_number: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + issue_number: pull_number ? Number(pull_number) : defaultPrNumber, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } - const defaultPrNumber = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; - const prNumber = (await getPrsByCommit(sha)) ?? defaultPrNumber; - const commentId = await getCommentByUser(login); + const prNumber = (await getFirstPrByCommit(sha, repo_name, repo_owner_name)) ?? (pull_number ? Number(pull_number) : defaultPrNumber); + const commentId = await getCommentByUser(login, pull_number, repo_name, repo_owner_name); if (commentId) { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.updateComment */ .K.issues.updateComment({ comment_id: commentId, body, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } else { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.createComment */ .K.issues.createComment({ body, issue_number: prNumber, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } }; diff --git a/dist/461.index.js.map b/dist/461.index.js.map index 7af019851..a7e8b3c64 100644 --- a/dist/461.index.js.map +++ b/dist/461.index.js.map @@ -1 +1 @@ -{"version":3,"file":"461.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;AACA;AACA;AACA;AAEA;AAAA;;AACA;AAGA;AAAA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC7EA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA6CA","sources":[".././src/constants.ts",".././src/helpers/create-pr-comment.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\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 { GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePrComment extends HelperInputs {\n body = '';\n sha?: string;\n login?: string;\n}\n\nconst emptyResponse = { data: [] };\n\nconst getPrsByCommit = async (sha?: string) => {\n const prs =\n (sha &&\n (await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n ...context.repo,\n ...GITHUB_OPTIONS\n }))) ||\n emptyResponse;\n\n return prs.data.find(Boolean)?.number;\n};\n\nconst getCommentByUser = async (login?: string) => {\n const comments =\n (login &&\n (await octokit.issues.listComments({\n issue_number: context.issue.number,\n ...context.repo\n }))) ||\n emptyResponse;\n\n return comments.data.find(comment => comment?.user?.login === login)?.id;\n};\n\nexport const createPrComment = async ({ body, sha, login }: CreatePrComment) => {\n if (!sha && !login) {\n return octokit.issues.createComment({\n body,\n issue_number: context.issue.number,\n ...context.repo\n });\n }\n\n const defaultPrNumber = context.issue.number;\n const prNumber = (await getPrsByCommit(sha)) ?? defaultPrNumber;\n const commentId = await getCommentByUser(login);\n\n if (commentId) {\n return octokit.issues.updateComment({\n comment_id: commentId,\n body,\n ...context.repo\n });\n } else {\n return octokit.issues.createComment({\n body,\n issue_number: prNumber,\n ...context.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 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}\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"461.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;AACA;AACA;AACA;AAEA;AAAA;;AACA;AAMA;AAAA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACtFA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA6CA","sources":[".././src/constants.ts",".././src/helpers/create-pr-comment.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\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 { GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePrComment extends HelperInputs {\n body = '';\n sha?: string;\n login?: string;\n pull_number?: string;\n repo_name?: string;\n repo_owner_name?: string;\n}\n\nconst emptyResponse = { data: [] };\n\nconst getFirstPrByCommit = async (sha?: string, repo_name?: string, repo_owner_name?: string) => {\n const prs =\n (sha &&\n (await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner,\n ...GITHUB_OPTIONS\n }))) ||\n emptyResponse;\n\n return prs.data.find(Boolean)?.number;\n};\n\nconst getCommentByUser = async (login?: string, pull_number?: string, repo_name?: string, repo_owner_name?: string) => {\n const comments =\n (login &&\n (await octokit.issues.listComments({\n issue_number: pull_number ? Number(pull_number) : context.issue.number,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n }))) ||\n emptyResponse;\n\n return comments.data.find(comment => comment?.user?.login === login)?.id;\n};\n\nexport const createPrComment = async ({ body, sha, login, pull_number, repo_name, repo_owner_name }: CreatePrComment) => {\n const defaultPrNumber = context.issue.number;\n\n if (!sha && !login) {\n return octokit.issues.createComment({\n body,\n issue_number: pull_number ? Number(pull_number) : defaultPrNumber,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n });\n }\n\n const prNumber = (await getFirstPrByCommit(sha, repo_name, repo_owner_name)) ?? (pull_number ? Number(pull_number) : defaultPrNumber);\n const commentId = await getCommentByUser(login, pull_number, repo_name, repo_owner_name);\n\n if (commentId) {\n return octokit.issues.updateComment({\n comment_id: commentId,\n body,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n });\n } else {\n return octokit.issues.createComment({\n body,\n issue_number: prNumber,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\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}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/dist/676.index.js b/dist/676.index.js index 90776ea94..93bc75d91 100644 --- a/dist/676.index.js +++ b/dist/676.index.js @@ -271,48 +271,53 @@ class CreatePrComment extends _types_generated__WEBPACK_IMPORTED_MODULE_3__/* .H } } const emptyResponse = { data: [] }; -const getPrsByCommit = async (sha) => { +const getFirstPrByCommit = async (sha, repo_name, repo_owner_name) => { const prs = (sha && (await _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.listPullRequestsAssociatedWithCommit */ .K.repos.listPullRequestsAssociatedWithCommit({ commit_sha: sha, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner, ..._constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .Cc }))) || emptyResponse; return prs.data.find(Boolean)?.number; }; -const getCommentByUser = async (login) => { +const getCommentByUser = async (login, pull_number, repo_name, repo_owner_name) => { const comments = (login && (await _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.listComments */ .K.issues.listComments({ - issue_number: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + issue_number: pull_number ? Number(pull_number) : _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }))) || emptyResponse; return comments.data.find(comment => comment?.user?.login === login)?.id; }; -const createPrComment = async ({ body, sha, login }) => { +const createPrComment = async ({ body, sha, login, pull_number, repo_name, repo_owner_name }) => { + const defaultPrNumber = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; if (!sha && !login) { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.createComment */ .K.issues.createComment({ body, - issue_number: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + issue_number: pull_number ? Number(pull_number) : defaultPrNumber, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } - const defaultPrNumber = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; - const prNumber = (await getPrsByCommit(sha)) ?? defaultPrNumber; - const commentId = await getCommentByUser(login); + const prNumber = (await getFirstPrByCommit(sha, repo_name, repo_owner_name)) ?? (pull_number ? Number(pull_number) : defaultPrNumber); + const commentId = await getCommentByUser(login, pull_number, repo_name, repo_owner_name); if (commentId) { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.updateComment */ .K.issues.updateComment({ comment_id: commentId, body, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } else { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.createComment */ .K.issues.createComment({ body, issue_number: prNumber, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } }; diff --git a/dist/676.index.js.map b/dist/676.index.js.map index cd99dde62..fa145d942 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;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AC5BA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAKA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;ACzGA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AAGA;AAAA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC7EA;;;;;;;;;;;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;AAKA;AACA;AACA;AACA;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;;;;;;;;;ACvFA;;;;;;;;;;;AAWA;AAEA;AACA;AAOA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAEA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;;AAEA;;;;AAIA;AACA;AAAA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;ACjIA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAEA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;ACrCA;;;;;;;;;;;AAWA;AAEA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AACA;AAIA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACrDA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA6CA;;;;;;;;;;;AC1DA;;;;;;;;;;;AAWA;AAEA;;;;;;;;;;;;;;ACbA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;AClCA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAGA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;AC5DA;;;;;;;;;;;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/utils/paginate-all-reviews.ts",".././src/helpers/approvals-satisfied.ts",".././src/helpers/create-pr-comment.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/convert-to-team-slug.ts",".././src/utils/get-changed-filepaths.ts",".././src/utils/get-core-member-logins.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 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 { PullRequestReviewList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllReviews = async (prNumber: number, page = 1): Promise => {\n const response = await octokit.pulls.listReviews({\n pull_number: prNumber,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return response.data.concat(await paginateAllReviews(prNumber, page + 1));\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 { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { getRequiredCodeOwnersEntries } from '../utils/get-core-member-logins';\nimport { map } from 'bluebird';\nimport { convertToTeamSlug } from '../utils/convert-to-team-slug';\nimport { CodeOwnersEntry } from 'codeowners-utils';\nimport * as core from '@actions/core';\nimport { paginateAllReviews } from '../utils/paginate-all-reviews';\n\nexport class ApprovalsSatisfied extends HelperInputs {\n teams?: string;\n users?: string;\n number_of_reviewers?: string;\n pull_number?: string;\n}\n\nexport const approvalsSatisfied = async ({ teams, users, number_of_reviewers = '1', pull_number }: ApprovalsSatisfied = {}) => {\n const prNumber = pull_number ? Number(pull_number) : context.issue.number;\n\n const teamsList = updateTeamsList(teams?.split('\\n'));\n if (!validateTeamsList(teamsList)) {\n core.setFailed('If teams input is in the format \"org/team\", then the org must be the same as the repository org');\n return false;\n }\n const usersList = users?.split('\\n');\n\n const reviews = await paginateAllReviews(prNumber);\n const approverLogins = reviews\n .filter(({ state }) => state === 'APPROVED')\n .map(({ user }) => user?.login)\n .filter(Boolean);\n core.debug(`PR already approved by: ${approverLogins.toString()}`);\n\n const requiredCodeOwnersEntries =\n teamsList || usersList\n ? createArtificialCodeOwnersEntry({ teams: teamsList, users: usersList })\n : await getRequiredCodeOwnersEntries(prNumber);\n const requiredCodeOwnersEntriesWithOwners = requiredCodeOwnersEntries.filter(({ owners }) => owners.length);\n\n const codeOwnersEntrySatisfiesApprovals = async (entry: Pick) => {\n const loginsLists = await map(entry.owners, async teamOrUser => {\n if (isTeam(teamOrUser)) {\n return await fetchTeamLogins(teamOrUser);\n } else {\n return [teamOrUser];\n }\n });\n const codeOwnerLogins = distinct(loginsLists.flat());\n\n const numberOfApprovals = approverLogins.filter(login => codeOwnerLogins.includes(login)).length;\n\n core.debug(`Current number of approvals satisfied for ${entry.owners}: ${numberOfApprovals}`);\n\n return numberOfApprovals >= Number(number_of_reviewers);\n };\n\n core.debug(`Required code owners: ${requiredCodeOwnersEntriesWithOwners.map(({ owners }) => owners).toString()}`);\n const booleans = await Promise.all(requiredCodeOwnersEntriesWithOwners.map(codeOwnersEntrySatisfiesApprovals));\n return booleans.every(Boolean);\n};\n\nconst createArtificialCodeOwnersEntry = ({ teams = [], users = [] }: { teams?: string[]; users?: string[] }) => [\n { owners: teams.concat(users) }\n];\nconst distinct = (arrayWithDuplicates: string[]) => arrayWithDuplicates.filter((n, i) => arrayWithDuplicates.indexOf(n) === i);\nconst isTeam = (teamOrUser: string) => teamOrUser.includes('/');\nconst fetchTeamLogins = async (team: string) => {\n const { data } = await octokit.teams.listMembersInOrg({\n org: context.repo.owner,\n team_slug: convertToTeamSlug(team),\n per_page: 100\n });\n return data.map(({ login }) => login);\n};\nconst updateTeamsList = (teamsList?: string[]) => {\n return teamsList?.map(team => {\n if (!team.includes('/')) {\n return `${context.repo.owner}/${team}`;\n } else {\n return team;\n }\n });\n};\n\nconst validateTeamsList = (teamsList?: string[]) => {\n return (\n teamsList?.every(team => {\n const inputOrg = team.split('/')[0];\n return inputOrg === context.repo.owner;\n }) ?? true\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 { GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePrComment extends HelperInputs {\n body = '';\n sha?: string;\n login?: string;\n}\n\nconst emptyResponse = { data: [] };\n\nconst getPrsByCommit = async (sha?: string) => {\n const prs =\n (sha &&\n (await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n ...context.repo,\n ...GITHUB_OPTIONS\n }))) ||\n emptyResponse;\n\n return prs.data.find(Boolean)?.number;\n};\n\nconst getCommentByUser = async (login?: string) => {\n const comments =\n (login &&\n (await octokit.issues.listComments({\n issue_number: context.issue.number,\n ...context.repo\n }))) ||\n emptyResponse;\n\n return comments.data.find(comment => comment?.user?.login === login)?.id;\n};\n\nexport const createPrComment = async ({ body, sha, login }: CreatePrComment) => {\n if (!sha && !login) {\n return octokit.issues.createComment({\n body,\n issue_number: context.issue.number,\n ...context.repo\n });\n }\n\n const defaultPrNumber = context.issue.number;\n const prNumber = (await getPrsByCommit(sha)) ?? defaultPrNumber;\n const commentId = await getCommentByUser(login);\n\n if (commentId) {\n return octokit.issues.updateComment({\n comment_id: commentId,\n body,\n ...context.repo\n });\n } else {\n return octokit.issues.createComment({\n body,\n issue_number: prNumber,\n ...context.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 { 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 const {\n data: {\n head: { sha: updatedHeadSha }\n }\n } = await octokit.pulls.get({ pull_number: number, ...context.repo });\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: updatedHeadSha,\n context: MERGE_QUEUE_STATUS,\n state: 'success',\n description: 'This PR is next to merge.'\n })\n ]);\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';\nimport { updatePrWithDefaultBranch } from './prepare-queued-pr-for-merge';\nimport { approvalsSatisfied } from './approvals-satisfied';\nimport { createPrComment } from './create-pr-comment';\n\nexport class ManageMergeQueue extends HelperInputs {\n login?: string;\n slack_webhook_url?: string;\n skip_auto_merge?: string;\n}\n\nexport const manageMergeQueue = async ({ login, slack_webhook_url, skip_auto_merge }: 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 prMeetsRequiredApprovals = await approvalsSatisfied();\n if (!prMeetsRequiredApprovals) {\n await createPrComment({ body: 'PRs must meet all required approvals before entering 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, skip_auto_merge);\n }\n\n const isFirstQueuePosition = queuePosition === 1 || pullRequest.labels.find(label => label.name === FIRST_QUEUED_PR_LABEL);\n\n if (isFirstQueuePosition) {\n await updatePrWithDefaultBranch(pullRequest);\n }\n\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 (isFirstQueuePosition && slack_webhook_url && login) {\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 return updateMergeQueue(queuedPrs);\n }\n};\n\nconst addPrToQueue = async (pullRequest: PullRequest, queuePosition: number, skip_auto_merge?: string) => {\n await octokit.issues.addLabels({\n labels: [`${QUEUED_FOR_MERGE_PREFIX} #${queuePosition}`],\n issue_number: context.issue.number,\n ...context.repo\n });\n if (skip_auto_merge == 'true') {\n core.info('Skipping auto merge per configuration.');\n return;\n }\n await 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 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 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}\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 const convertToTeamSlug = (codeOwner: string) => codeOwner.substring(codeOwner.indexOf('/') + 1);\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 { ChangedFilesList } from '../types/github';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport const getChangedFilepaths = async (pull_number: number, ignore_deleted?: boolean) => {\n const changedFiles = await paginateAllChangedFilepaths(pull_number);\n const filesToMap = ignore_deleted ? changedFiles.filter(file => file.status !== 'removed') : changedFiles;\n return filesToMap.map(file => file.filename);\n};\n\nconst paginateAllChangedFilepaths = async (pull_number: number, page = 1): Promise => {\n const response = await octokit.pulls.listFiles({\n pull_number,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return response.data.concat(await paginateAllChangedFilepaths(pull_number, page + 1));\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 { CodeOwnersEntry, loadOwners, matchFile } from 'codeowners-utils';\nimport { uniq, union } from 'lodash';\nimport { context } from '@actions/github';\nimport { getChangedFilepaths } from './get-changed-filepaths';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { convertToTeamSlug } from './convert-to-team-slug';\n\nexport const getCoreMemberLogins = async (pull_number: number, teams?: string[]) => {\n const codeOwners = teams ?? getCodeOwnersFromEntries(await getRequiredCodeOwnersEntries(pull_number));\n const teamsAndLogins = await getCoreTeamsAndLogins(codeOwners);\n return uniq(teamsAndLogins.map(({ login }) => login));\n};\n\nexport const getRequiredCodeOwnersEntries = async (pull_number: number): Promise => {\n const codeOwners = (await loadOwners(process.cwd())) ?? [];\n const changedFilePaths = await getChangedFilepaths(pull_number);\n return changedFilePaths.map(filePath => matchFile(filePath, codeOwners)).filter(Boolean);\n};\n\nconst getCoreTeamsAndLogins = async (codeOwners?: string[]) => {\n if (!codeOwners?.length) {\n core.setFailed('No code owners found. Please provide a \"teams\" input or set up a CODEOWNERS file in your repo.');\n throw new Error();\n }\n\n const teamsAndLogins = await map(codeOwners, async team =>\n octokit.teams\n .listMembersInOrg({\n org: context.repo.owner,\n team_slug: team,\n per_page: 100\n })\n .then(listMembersResponse => listMembersResponse.data.map(({ login }) => ({ team, login })))\n );\n return union(...teamsAndLogins);\n};\n\nconst getCodeOwnersFromEntries = (codeOwnersEntries: CodeOwnersEntry[]) => {\n return uniq(\n codeOwnersEntries\n .map(entry => entry.owners)\n .flat()\n .filter(Boolean)\n .map(codeOwner => convertToTeamSlug(codeOwner))\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 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;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AC5BA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAKA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;;ACzGA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AAMA;AAAA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACtFA;;;;;;;;;;;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;AAKA;AACA;AACA;AACA;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;;;;;;;;;ACvFA;;;;;;;;;;;AAWA;AAEA;AACA;AAOA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAEA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;;AAEA;;;;AAIA;AACA;AAAA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;ACjIA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AAEA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;ACrCA;;;;;;;;;;;AAWA;AAEA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AACA;AACA;AAIA;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACrDA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA6CA;;;;;;;;;;;AC1DA;;;;;;;;;;;AAWA;AAEA;;;;;;;;;;;;;;ACbA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;AClCA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAGA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AAEA;;;;;;;;;;;;;;;;;AC5DA;;;;;;;;;;;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/constants.ts",".././src/utils/paginate-all-reviews.ts",".././src/helpers/approvals-satisfied.ts",".././src/helpers/create-pr-comment.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/convert-to-team-slug.ts",".././src/utils/get-changed-filepaths.ts",".././src/utils/get-core-member-logins.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 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 { PullRequestReviewList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllReviews = async (prNumber: number, page = 1): Promise => {\n const response = await octokit.pulls.listReviews({\n pull_number: prNumber,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return response.data.concat(await paginateAllReviews(prNumber, page + 1));\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 { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { getRequiredCodeOwnersEntries } from '../utils/get-core-member-logins';\nimport { map } from 'bluebird';\nimport { convertToTeamSlug } from '../utils/convert-to-team-slug';\nimport { CodeOwnersEntry } from 'codeowners-utils';\nimport * as core from '@actions/core';\nimport { paginateAllReviews } from '../utils/paginate-all-reviews';\n\nexport class ApprovalsSatisfied extends HelperInputs {\n teams?: string;\n users?: string;\n number_of_reviewers?: string;\n pull_number?: string;\n}\n\nexport const approvalsSatisfied = async ({ teams, users, number_of_reviewers = '1', pull_number }: ApprovalsSatisfied = {}) => {\n const prNumber = pull_number ? Number(pull_number) : context.issue.number;\n\n const teamsList = updateTeamsList(teams?.split('\\n'));\n if (!validateTeamsList(teamsList)) {\n core.setFailed('If teams input is in the format \"org/team\", then the org must be the same as the repository org');\n return false;\n }\n const usersList = users?.split('\\n');\n\n const reviews = await paginateAllReviews(prNumber);\n const approverLogins = reviews\n .filter(({ state }) => state === 'APPROVED')\n .map(({ user }) => user?.login)\n .filter(Boolean);\n core.debug(`PR already approved by: ${approverLogins.toString()}`);\n\n const requiredCodeOwnersEntries =\n teamsList || usersList\n ? createArtificialCodeOwnersEntry({ teams: teamsList, users: usersList })\n : await getRequiredCodeOwnersEntries(prNumber);\n const requiredCodeOwnersEntriesWithOwners = requiredCodeOwnersEntries.filter(({ owners }) => owners.length);\n\n const codeOwnersEntrySatisfiesApprovals = async (entry: Pick) => {\n const loginsLists = await map(entry.owners, async teamOrUser => {\n if (isTeam(teamOrUser)) {\n return await fetchTeamLogins(teamOrUser);\n } else {\n return [teamOrUser];\n }\n });\n const codeOwnerLogins = distinct(loginsLists.flat());\n\n const numberOfApprovals = approverLogins.filter(login => codeOwnerLogins.includes(login)).length;\n\n core.debug(`Current number of approvals satisfied for ${entry.owners}: ${numberOfApprovals}`);\n\n return numberOfApprovals >= Number(number_of_reviewers);\n };\n\n core.debug(`Required code owners: ${requiredCodeOwnersEntriesWithOwners.map(({ owners }) => owners).toString()}`);\n const booleans = await Promise.all(requiredCodeOwnersEntriesWithOwners.map(codeOwnersEntrySatisfiesApprovals));\n return booleans.every(Boolean);\n};\n\nconst createArtificialCodeOwnersEntry = ({ teams = [], users = [] }: { teams?: string[]; users?: string[] }) => [\n { owners: teams.concat(users) }\n];\nconst distinct = (arrayWithDuplicates: string[]) => arrayWithDuplicates.filter((n, i) => arrayWithDuplicates.indexOf(n) === i);\nconst isTeam = (teamOrUser: string) => teamOrUser.includes('/');\nconst fetchTeamLogins = async (team: string) => {\n const { data } = await octokit.teams.listMembersInOrg({\n org: context.repo.owner,\n team_slug: convertToTeamSlug(team),\n per_page: 100\n });\n return data.map(({ login }) => login);\n};\nconst updateTeamsList = (teamsList?: string[]) => {\n return teamsList?.map(team => {\n if (!team.includes('/')) {\n return `${context.repo.owner}/${team}`;\n } else {\n return team;\n }\n });\n};\n\nconst validateTeamsList = (teamsList?: string[]) => {\n return (\n teamsList?.every(team => {\n const inputOrg = team.split('/')[0];\n return inputOrg === context.repo.owner;\n }) ?? true\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 { GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePrComment extends HelperInputs {\n body = '';\n sha?: string;\n login?: string;\n pull_number?: string;\n repo_name?: string;\n repo_owner_name?: string;\n}\n\nconst emptyResponse = { data: [] };\n\nconst getFirstPrByCommit = async (sha?: string, repo_name?: string, repo_owner_name?: string) => {\n const prs =\n (sha &&\n (await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner,\n ...GITHUB_OPTIONS\n }))) ||\n emptyResponse;\n\n return prs.data.find(Boolean)?.number;\n};\n\nconst getCommentByUser = async (login?: string, pull_number?: string, repo_name?: string, repo_owner_name?: string) => {\n const comments =\n (login &&\n (await octokit.issues.listComments({\n issue_number: pull_number ? Number(pull_number) : context.issue.number,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n }))) ||\n emptyResponse;\n\n return comments.data.find(comment => comment?.user?.login === login)?.id;\n};\n\nexport const createPrComment = async ({ body, sha, login, pull_number, repo_name, repo_owner_name }: CreatePrComment) => {\n const defaultPrNumber = context.issue.number;\n\n if (!sha && !login) {\n return octokit.issues.createComment({\n body,\n issue_number: pull_number ? Number(pull_number) : defaultPrNumber,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n });\n }\n\n const prNumber = (await getFirstPrByCommit(sha, repo_name, repo_owner_name)) ?? (pull_number ? Number(pull_number) : defaultPrNumber);\n const commentId = await getCommentByUser(login, pull_number, repo_name, repo_owner_name);\n\n if (commentId) {\n return octokit.issues.updateComment({\n comment_id: commentId,\n body,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n });\n } else {\n return octokit.issues.createComment({\n body,\n issue_number: prNumber,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\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 { 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 const {\n data: {\n head: { sha: updatedHeadSha }\n }\n } = await octokit.pulls.get({ pull_number: number, ...context.repo });\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: updatedHeadSha,\n context: MERGE_QUEUE_STATUS,\n state: 'success',\n description: 'This PR is next to merge.'\n })\n ]);\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';\nimport { updatePrWithDefaultBranch } from './prepare-queued-pr-for-merge';\nimport { approvalsSatisfied } from './approvals-satisfied';\nimport { createPrComment } from './create-pr-comment';\n\nexport class ManageMergeQueue extends HelperInputs {\n login?: string;\n slack_webhook_url?: string;\n skip_auto_merge?: string;\n}\n\nexport const manageMergeQueue = async ({ login, slack_webhook_url, skip_auto_merge }: 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 prMeetsRequiredApprovals = await approvalsSatisfied();\n if (!prMeetsRequiredApprovals) {\n await createPrComment({ body: 'PRs must meet all required approvals before entering 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, skip_auto_merge);\n }\n\n const isFirstQueuePosition = queuePosition === 1 || pullRequest.labels.find(label => label.name === FIRST_QUEUED_PR_LABEL);\n\n if (isFirstQueuePosition) {\n await updatePrWithDefaultBranch(pullRequest);\n }\n\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 (isFirstQueuePosition && slack_webhook_url && login) {\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 return updateMergeQueue(queuedPrs);\n }\n};\n\nconst addPrToQueue = async (pullRequest: PullRequest, queuePosition: number, skip_auto_merge?: string) => {\n await octokit.issues.addLabels({\n labels: [`${QUEUED_FOR_MERGE_PREFIX} #${queuePosition}`],\n issue_number: context.issue.number,\n ...context.repo\n });\n if (skip_auto_merge == 'true') {\n core.info('Skipping auto merge per configuration.');\n return;\n }\n await 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 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 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}\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 const convertToTeamSlug = (codeOwner: string) => codeOwner.substring(codeOwner.indexOf('/') + 1);\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 { ChangedFilesList } from '../types/github';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport const getChangedFilepaths = async (pull_number: number, ignore_deleted?: boolean) => {\n const changedFiles = await paginateAllChangedFilepaths(pull_number);\n const filesToMap = ignore_deleted ? changedFiles.filter(file => file.status !== 'removed') : changedFiles;\n return filesToMap.map(file => file.filename);\n};\n\nconst paginateAllChangedFilepaths = async (pull_number: number, page = 1): Promise => {\n const response = await octokit.pulls.listFiles({\n pull_number,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return response.data.concat(await paginateAllChangedFilepaths(pull_number, page + 1));\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 { CodeOwnersEntry, loadOwners, matchFile } from 'codeowners-utils';\nimport { uniq, union } from 'lodash';\nimport { context } from '@actions/github';\nimport { getChangedFilepaths } from './get-changed-filepaths';\nimport { map } from 'bluebird';\nimport { octokit } from '../octokit';\nimport { convertToTeamSlug } from './convert-to-team-slug';\n\nexport const getCoreMemberLogins = async (pull_number: number, teams?: string[]) => {\n const codeOwners = teams ?? getCodeOwnersFromEntries(await getRequiredCodeOwnersEntries(pull_number));\n const teamsAndLogins = await getCoreTeamsAndLogins(codeOwners);\n return uniq(teamsAndLogins.map(({ login }) => login));\n};\n\nexport const getRequiredCodeOwnersEntries = async (pull_number: number): Promise => {\n const codeOwners = (await loadOwners(process.cwd())) ?? [];\n const changedFilePaths = await getChangedFilepaths(pull_number);\n return changedFilePaths.map(filePath => matchFile(filePath, codeOwners)).filter(Boolean);\n};\n\nconst getCoreTeamsAndLogins = async (codeOwners?: string[]) => {\n if (!codeOwners?.length) {\n core.setFailed('No code owners found. Please provide a \"teams\" input or set up a CODEOWNERS file in your repo.');\n throw new Error();\n }\n\n const teamsAndLogins = await map(codeOwners, async team =>\n octokit.teams\n .listMembersInOrg({\n org: context.repo.owner,\n team_slug: team,\n per_page: 100\n })\n .then(listMembersResponse => listMembersResponse.data.map(({ login }) => ({ team, login })))\n );\n return union(...teamsAndLogins);\n};\n\nconst getCodeOwnersFromEntries = (codeOwnersEntries: CodeOwnersEntry[]) => {\n return uniq(\n codeOwnersEntries\n .map(entry => entry.owners)\n .flat()\n .filter(Boolean)\n .map(codeOwner => convertToTeamSlug(codeOwner))\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 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/dist/830.index.js b/dist/830.index.js index 1838bb4b3..ec69ebab5 100644 --- a/dist/830.index.js +++ b/dist/830.index.js @@ -120,14 +120,18 @@ limitations under the License. class ClosePr extends _types_generated__WEBPACK_IMPORTED_MODULE_3__/* .HelperInputs */ .s { } -const closePr = async ({ body } = {}) => { +const closePr = async ({ body, pull_number, repo_name, repo_owner_name } = {}) => { + if ((repo_name || repo_owner_name) && !pull_number) { + throw new Error('pull_number is required when repo_name or repo_owner_name is provided'); + } if (body) { - await (0,_create_pr_comment__WEBPACK_IMPORTED_MODULE_2__.createPrComment)({ body }); + await (0,_create_pr_comment__WEBPACK_IMPORTED_MODULE_2__.createPrComment)({ body, pull_number, repo_name, repo_owner_name }); } return _octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokit.pulls.update */ .K.pulls.update({ - pull_number: _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.issue.number, - state: 'closed', - ..._actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo + pull_number: pull_number ? Number(pull_number) : _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.issue.number, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo.owner, + state: 'closed' }); }; @@ -170,48 +174,53 @@ class CreatePrComment extends _types_generated__WEBPACK_IMPORTED_MODULE_3__/* .H } } const emptyResponse = { data: [] }; -const getPrsByCommit = async (sha) => { +const getFirstPrByCommit = async (sha, repo_name, repo_owner_name) => { const prs = (sha && (await _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.repos.listPullRequestsAssociatedWithCommit */ .K.repos.listPullRequestsAssociatedWithCommit({ commit_sha: sha, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner, ..._constants__WEBPACK_IMPORTED_MODULE_0__/* .GITHUB_OPTIONS */ .Cc }))) || emptyResponse; return prs.data.find(Boolean)?.number; }; -const getCommentByUser = async (login) => { +const getCommentByUser = async (login, pull_number, repo_name, repo_owner_name) => { const comments = (login && (await _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.listComments */ .K.issues.listComments({ - issue_number: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + issue_number: pull_number ? Number(pull_number) : _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }))) || emptyResponse; return comments.data.find(comment => comment?.user?.login === login)?.id; }; -const createPrComment = async ({ body, sha, login }) => { +const createPrComment = async ({ body, sha, login, pull_number, repo_name, repo_owner_name }) => { + const defaultPrNumber = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; if (!sha && !login) { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.createComment */ .K.issues.createComment({ body, - issue_number: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + issue_number: pull_number ? Number(pull_number) : defaultPrNumber, + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } - const defaultPrNumber = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; - const prNumber = (await getPrsByCommit(sha)) ?? defaultPrNumber; - const commentId = await getCommentByUser(login); + const prNumber = (await getFirstPrByCommit(sha, repo_name, repo_owner_name)) ?? (pull_number ? Number(pull_number) : defaultPrNumber); + const commentId = await getCommentByUser(login, pull_number, repo_name, repo_owner_name); if (commentId) { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.updateComment */ .K.issues.updateComment({ comment_id: commentId, body, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } else { return _octokit__WEBPACK_IMPORTED_MODULE_2__/* .octokit.issues.createComment */ .K.issues.createComment({ body, issue_number: prNumber, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + repo: repo_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo, + owner: repo_owner_name ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner }); } }; diff --git a/dist/830.index.js.map b/dist/830.index.js.map index 22a0135b4..fd2959099 100644 --- a/dist/830.index.js.map +++ b/dist/830.index.js.map @@ -1 +1 @@ -{"version":3,"file":"830.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;AACA;AACA;AACA;AAEA;AAEA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AChCA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AAGA;AAAA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC7EA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA6CA","sources":[".././src/constants.ts",".././src/helpers/close-pr.ts",".././src/helpers/create-pr-comment.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\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 { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { createPrComment } from './create-pr-comment';\n\nexport class ClosePr extends HelperInputs {\n body?: string;\n}\n\nexport const closePr = async ({ body }: ClosePr = {}) => {\n if (body) {\n await createPrComment({ body });\n }\n\n return octokit.pulls.update({\n pull_number: context.issue.number,\n state: 'closed',\n ...context.repo\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 { GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePrComment extends HelperInputs {\n body = '';\n sha?: string;\n login?: string;\n}\n\nconst emptyResponse = { data: [] };\n\nconst getPrsByCommit = async (sha?: string) => {\n const prs =\n (sha &&\n (await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n ...context.repo,\n ...GITHUB_OPTIONS\n }))) ||\n emptyResponse;\n\n return prs.data.find(Boolean)?.number;\n};\n\nconst getCommentByUser = async (login?: string) => {\n const comments =\n (login &&\n (await octokit.issues.listComments({\n issue_number: context.issue.number,\n ...context.repo\n }))) ||\n emptyResponse;\n\n return comments.data.find(comment => comment?.user?.login === login)?.id;\n};\n\nexport const createPrComment = async ({ body, sha, login }: CreatePrComment) => {\n if (!sha && !login) {\n return octokit.issues.createComment({\n body,\n issue_number: context.issue.number,\n ...context.repo\n });\n }\n\n const defaultPrNumber = context.issue.number;\n const prNumber = (await getPrsByCommit(sha)) ?? defaultPrNumber;\n const commentId = await getCommentByUser(login);\n\n if (commentId) {\n return octokit.issues.updateComment({\n comment_id: commentId,\n body,\n ...context.repo\n });\n } else {\n return octokit.issues.createComment({\n body,\n issue_number: prNumber,\n ...context.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 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}\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"830.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;AACA;AACA;AACA;AAEA;AAKA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACvCA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AAEA;AAAA;;AACA;AAMA;AAAA;AAEA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACtFA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AA6CA","sources":[".././src/constants.ts",".././src/helpers/close-pr.ts",".././src/helpers/create-pr-comment.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\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 { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\nimport { createPrComment } from './create-pr-comment';\n\nexport class ClosePr extends HelperInputs {\n body?: string;\n pull_number?: string;\n repo_name?: string;\n repo_owner_name?: string;\n}\n\nexport const closePr = async ({ body, pull_number, repo_name, repo_owner_name }: ClosePr = {}) => {\n if ((repo_name || repo_owner_name) && !pull_number) {\n throw new Error('pull_number is required when repo_name or repo_owner_name is provided');\n }\n if (body) {\n await createPrComment({ body, pull_number, repo_name, repo_owner_name });\n }\n\n return octokit.pulls.update({\n pull_number: pull_number ? Number(pull_number) : context.issue.number,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner,\n state: 'closed'\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 { GITHUB_OPTIONS } from '../constants';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit } from '../octokit';\n\nexport class CreatePrComment extends HelperInputs {\n body = '';\n sha?: string;\n login?: string;\n pull_number?: string;\n repo_name?: string;\n repo_owner_name?: string;\n}\n\nconst emptyResponse = { data: [] };\n\nconst getFirstPrByCommit = async (sha?: string, repo_name?: string, repo_owner_name?: string) => {\n const prs =\n (sha &&\n (await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner,\n ...GITHUB_OPTIONS\n }))) ||\n emptyResponse;\n\n return prs.data.find(Boolean)?.number;\n};\n\nconst getCommentByUser = async (login?: string, pull_number?: string, repo_name?: string, repo_owner_name?: string) => {\n const comments =\n (login &&\n (await octokit.issues.listComments({\n issue_number: pull_number ? Number(pull_number) : context.issue.number,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n }))) ||\n emptyResponse;\n\n return comments.data.find(comment => comment?.user?.login === login)?.id;\n};\n\nexport const createPrComment = async ({ body, sha, login, pull_number, repo_name, repo_owner_name }: CreatePrComment) => {\n const defaultPrNumber = context.issue.number;\n\n if (!sha && !login) {\n return octokit.issues.createComment({\n body,\n issue_number: pull_number ? Number(pull_number) : defaultPrNumber,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n });\n }\n\n const prNumber = (await getFirstPrByCommit(sha, repo_name, repo_owner_name)) ?? (pull_number ? Number(pull_number) : defaultPrNumber);\n const commentId = await getCommentByUser(login, pull_number, repo_name, repo_owner_name);\n\n if (commentId) {\n return octokit.issues.updateComment({\n comment_id: commentId,\n body,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\n });\n } else {\n return octokit.issues.createComment({\n body,\n issue_number: prNumber,\n repo: repo_name ?? context.repo.repo,\n owner: repo_owner_name ?? context.repo.owner\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}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/dist/action.yml b/dist/action.yml index 4aa1ad8bd..431d39688 100644 --- a/dist/action.yml +++ b/dist/action.yml @@ -134,6 +134,12 @@ inputs: skip_auto_merge: description: 'Do not enable auto-merge automatically for the PRs from the merge queue' required: false + repo_name: + description: 'Repository to interact with' + required: false + repo_owner_name: + description: 'Organization in which repository is stored' + required: false outputs: output: description: 'The output of the helper'