diff --git a/dist/654.index.js b/dist/654.index.js index 75eceecd..ca26151f 100644 --- a/dist/654.index.js +++ b/dist/654.index.js @@ -38,12 +38,17 @@ limitations under the License. class FilterPaths extends _types_generated__WEBPACK_IMPORTED_MODULE_4__/* .HelperInputs */ .m { } const filterPaths = async ({ paths, globs, sha }) => { - const prNumberFromSha = sha - ? (await _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit */ .A.repos.listPullRequestsAssociatedWithCommit({ - commit_sha: sha, - ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo - })).data.find(Boolean)?.number - : undefined; + const prNumberFromSha = _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.eventName === 'merge_group' + ? Number(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0]) + : sha + ? (await _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit */ .A.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: sha, + ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + })).data.find(Boolean)?.number + : undefined; const pull_number = prNumberFromSha ?? _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number; const { data } = await _octokit__WEBPACK_IMPORTED_MODULE_3__/* .octokit */ .A.pulls.listFiles({ per_page: 100, diff --git a/dist/654.index.js.map b/dist/654.index.js.map index 6d92a17d..423530e6 100644 --- a/dist/654.index.js.map +++ b/dist/654.index.js.map @@ -1 +1 @@ -{"version":3,"file":"654.index.js","mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAAA;AACA;AACA;AAAA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;ACpDA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA","sources":[".././src/helpers/filter-paths.ts",".././src/octokit.ts",".././src/types/generated.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport micromatch from 'micromatch';\nimport { octokit } from '../octokit';\n\nexport class FilterPaths extends HelperInputs {\n paths?: string;\n globs?: string;\n sha?: string;\n}\n\nexport const filterPaths = async ({ paths, globs, sha }: FilterPaths) => {\n const prNumberFromSha = sha\n ? (\n await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n ...context.repo\n })\n ).data.find(Boolean)?.number\n : undefined;\n const pull_number = prNumberFromSha ?? context.issue.number;\n\n const { data } = await octokit.pulls.listFiles({\n per_page: 100,\n pull_number,\n ...context.repo\n });\n\n const fileNames = data.map(file => file.filename);\n if (globs) {\n if (paths) core.info('`paths` and `globs` inputs found, defaulting to use `globs` for filtering');\n return micromatch(fileNames, globs.split('\\n')).length > 0;\n } else if (paths) {\n const filePaths = paths.split('\\n');\n return fileNames.some(changedFile => filePaths.some(filePath => changedFile.startsWith(filePath)));\n } else {\n core.error('Must pass `globs` or `paths` for filtering');\n }\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"654.index.js","mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AACA;AAEA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAAA;AACA;AACA;AAAA;AACA;AACA;AACA;AAAA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC5DA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA","sources":[".././src/helpers/filter-paths.ts",".././src/octokit.ts",".././src/types/generated.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport micromatch from 'micromatch';\nimport { octokit } from '../octokit';\n\nexport class FilterPaths extends HelperInputs {\n paths?: string;\n globs?: string;\n sha?: string;\n}\n\nexport const filterPaths = async ({ paths, globs, sha }: FilterPaths) => {\n const prNumberFromSha =\n context.eventName === 'merge_group'\n ? Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n )\n : sha\n ? (\n await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n ...context.repo\n })\n ).data.find(Boolean)?.number\n : undefined;\n const pull_number = prNumberFromSha ?? context.issue.number;\n\n const { data } = await octokit.pulls.listFiles({\n per_page: 100,\n pull_number,\n ...context.repo\n });\n\n const fileNames = data.map(file => file.filename);\n if (globs) {\n if (paths) core.info('`paths` and `globs` inputs found, defaulting to use `globs` for filtering');\n return micromatch(fileNames, globs.split('\\n')).length > 0;\n } else if (paths) {\n const filePaths = paths.split('\\n');\n return fileNames.some(changedFile => filePaths.some(filePath => changedFile.startsWith(filePath)));\n } else {\n core.error('Must pass `globs` or `paths` for filtering');\n }\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/filter-paths.ts b/src/helpers/filter-paths.ts index d7c72072..e122406b 100644 --- a/src/helpers/filter-paths.ts +++ b/src/helpers/filter-paths.ts @@ -24,14 +24,22 @@ export class FilterPaths extends HelperInputs { } export const filterPaths = async ({ paths, globs, sha }: FilterPaths) => { - const prNumberFromSha = sha - ? ( - await octokit.repos.listPullRequestsAssociatedWithCommit({ - commit_sha: sha, - ...context.repo - }) - ).data.find(Boolean)?.number - : undefined; + const prNumberFromSha = + context.eventName === 'merge_group' + ? Number( + context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0] + ) + : sha + ? ( + await octokit.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: sha, + ...context.repo + }) + ).data.find(Boolean)?.number + : undefined; const pull_number = prNumberFromSha ?? context.issue.number; const { data } = await octokit.pulls.listFiles({ diff --git a/test/helpers/filter-paths.test.ts b/test/helpers/filter-paths.test.ts index b6752eee..0188811d 100644 --- a/test/helpers/filter-paths.test.ts +++ b/test/helpers/filter-paths.test.ts @@ -208,4 +208,18 @@ describe('filterPaths', () => { expect(octokit.repos.listPullRequestsAssociatedWithCommit).not.toHaveBeenCalled(); }); + + it('should not call listPullRequestsAssociatedWithCommit if sha is omitted', async () => { + context.eventName = 'merge_group'; + context.ref = 'refs/heads/gh-readonly-queue/branch-name/pr-12345-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f'; + await filterPaths({ + paths + }); + + expect(octokit.pulls.listFiles).toHaveBeenCalledWith({ + per_page: 100, + pull_number: 12345, + ...context.repo + }); + }); });