diff --git a/dist/338.index.js b/dist/338.index.js index d7027aae..e34fb7c1 100644 --- a/dist/338.index.js +++ b/dist/338.index.js @@ -10,10 +10,11 @@ __webpack_require__.r(__webpack_exports__); /* harmony export */ GetChangedFiles: () => (/* binding */ GetChangedFiles), /* harmony export */ getChangedFiles: () => (/* binding */ getChangedFiles) /* harmony export */ }); -/* harmony import */ var _types_generated__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8428); +/* harmony import */ var _types_generated__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8428); /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3228); /* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _utils_get_changed_filepaths__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6039); +/* harmony import */ var _utils_merge_queue__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5323); /* Copyright 2021 Expedia, Inc. Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,10 +30,12 @@ limitations under the License. -class GetChangedFiles extends _types_generated__WEBPACK_IMPORTED_MODULE_2__/* .HelperInputs */ .m { + +class GetChangedFiles extends _types_generated__WEBPACK_IMPORTED_MODULE_3__/* .HelperInputs */ .m { } const getChangedFiles = async ({ pattern, delimiter = ',', ignore_deleted }) => { - const filePaths = await (0,_utils_get_changed_filepaths__WEBPACK_IMPORTED_MODULE_1__/* .getChangedFilepaths */ .t)(_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.issue.number, Boolean(ignore_deleted)); + const pullNumber = _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.eventName === 'merge_group' ? (0,_utils_merge_queue__WEBPACK_IMPORTED_MODULE_2__/* .getPrNumberFromMergeQueueRef */ .M)() : _actions_github__WEBPACK_IMPORTED_MODULE_0__.context.issue.number; + const filePaths = await (0,_utils_get_changed_filepaths__WEBPACK_IMPORTED_MODULE_1__/* .getChangedFilepaths */ .t)(pullNumber, Boolean(ignore_deleted)); const filteredFilePaths = pattern ? filePaths.filter(fileName => fileName.match(pattern)) : filePaths; return filteredFilePaths.join(delimiter); }; @@ -144,6 +147,88 @@ const paginateAllChangedFilepaths = async (pull_number, page = 1) => { }; +/***/ }), + +/***/ 5323: +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ M: () => (/* binding */ getPrNumberFromMergeQueueRef), +/* harmony export */ T: () => (/* binding */ getMergeQueueCommitHashes) +/* harmony export */ }); +/* harmony import */ var _paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9615); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); +/* +Copyright 2022 Expedia, Inc. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + https://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +const getMergeQueueCommitHashes = async () => { + const branches = await (0,_paginate_all_branches__WEBPACK_IMPORTED_MODULE_0__/* .paginateAllBranches */ .h)(); + const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/')); + return mergeQueueBranches.map(branch => branch.commit.sha); +}; +const getPrNumberFromMergeQueueRef = () => { + const prNumber = Number(_actions_github__WEBPACK_IMPORTED_MODULE_1__.context.ref + .split('/') + .find(part => part.includes('pr-')) + ?.match(/\d+/)?.[0]); + if (isNaN(prNumber)) { + throw new Error('Could not find PR number in merge queue ref.'); + } + return prNumber; +}; + + +/***/ }), + +/***/ 9615: +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +/* harmony export */ __webpack_require__.d(__webpack_exports__, { +/* harmony export */ h: () => (/* binding */ paginateAllBranches) +/* harmony export */ }); +/* harmony import */ var _octokit__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6590); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3228); +/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__); +/* +Copyright 2022 Expedia, Inc. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + https://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +const paginateAllBranches = async ({ protectedBranches, page = 1 } = {}) => { + const response = await _octokit__WEBPACK_IMPORTED_MODULE_0__/* .octokit */ .A.repos.listBranches({ + protected: protectedBranches, + per_page: 100, + page, + ..._actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo + }); + if (!response.data.length) { + return []; + } + return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))]; +}; + + /***/ }) }; diff --git a/dist/338.index.js.map b/dist/338.index.js.map index b519c518..1f463ae2 100644 --- a/dist/338.index.js.map +++ b/dist/338.index.js.map @@ -1 +1 @@ -{"version":3,"file":"338.index.js","mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AAIA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC3BA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAsDA;;;;;;;;;;;;;;ACnEA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/helpers/get-changed-files.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/get-changed-filepaths.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 { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { getChangedFilepaths } from '../utils/get-changed-filepaths';\n\nexport class GetChangedFiles extends HelperInputs {\n declare pattern?: string;\n declare delimiter?: string;\n declare ignore_deleted?: string;\n}\n\nexport const getChangedFiles = async ({ pattern, delimiter = ',', ignore_deleted }: GetChangedFiles) => {\n const filePaths = await getChangedFilepaths(context.issue.number, Boolean(ignore_deleted));\n const filteredFilePaths = pattern ? filePaths.filter(fileName => fileName.match(pattern)) : filePaths;\n return filteredFilePaths.join(delimiter);\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 declare helper?: string;\n declare github_token?: string;\n declare body?: string;\n declare project_name?: string;\n declare project_destination_column_name?: string;\n declare note?: string;\n declare project_origin_column_name?: string;\n declare sha?: string;\n declare context?: string;\n declare state?: string;\n declare description?: string;\n declare target_url?: string;\n declare environment?: string;\n declare environment_url?: string;\n declare label?: string;\n declare labels?: string;\n declare paths?: string;\n declare ignore_globs?: string;\n declare override_filter_paths?: string;\n declare batches?: string;\n declare pattern?: string;\n declare teams?: string;\n declare users?: string;\n declare login?: string;\n declare paths_no_filter?: string;\n declare slack_webhook_url?: string;\n declare number_of_assignees?: string;\n declare number_of_reviewers?: string;\n declare globs?: string;\n declare override_filter_globs?: string;\n declare title?: string;\n declare seconds?: string;\n declare pull_number?: string;\n declare base?: string;\n declare head?: string;\n declare days?: string;\n declare no_evict_upon_conflict?: string;\n declare skip_if_already_set?: string;\n declare delimiter?: string;\n declare team?: string;\n declare ignore_deleted?: string;\n declare return_full_payload?: string;\n declare skip_auto_merge?: string;\n declare repo_name?: string;\n declare repo_owner_name?: string;\n declare load_balancing_sizes?: string;\n declare required_review_overrides?: string;\n declare codeowners_overrides?: string;\n declare max_queue_size?: string;\n declare allow_only_for_maintainers?: string;\n declare use_basic_matrix_configuration?: string;\n declare merge_queue_enabled?: string;\n declare packages?: string;\n}\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { 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 renamedPreviousFilenames = changedFiles\n .filter(({ status }) => status === 'renamed')\n .map(({ previous_filename }) => previous_filename)\n .filter(Boolean); // GitHub should always include previous_filename for renamed files, but just in case\n const processedFilenames = (ignore_deleted ? changedFiles.filter(({ status }) => status !== 'removed') : changedFiles).map(\n ({ filename }) => filename\n );\n return processedFilenames.concat(renamedPreviousFilenames);\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"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"338.index.js","mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AACA;AAEA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC7BA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAsDA;;;;;;;;;;;;;;ACnEA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;ACxCA;;;;;;;;;;;AAWA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;ACjCA;;;;;;;;;;;AAWA;AAGA;AACA;AAEA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":[".././src/helpers/get-changed-files.ts",".././src/octokit.ts",".././src/types/generated.ts",".././src/utils/get-changed-filepaths.ts",".././src/utils/merge-queue.ts",".././src/utils/paginate-all-branches.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { getChangedFilepaths } from '../utils/get-changed-filepaths';\nimport { getPrNumberFromMergeQueueRef } from '../utils/merge-queue';\n\nexport class GetChangedFiles extends HelperInputs {\n declare pattern?: string;\n declare delimiter?: string;\n declare ignore_deleted?: string;\n}\n\nexport const getChangedFiles = async ({ pattern, delimiter = ',', ignore_deleted }: GetChangedFiles) => {\n const pullNumber = context.eventName === 'merge_group' ? getPrNumberFromMergeQueueRef() : context.issue.number;\n const filePaths = await getChangedFilepaths(pullNumber, Boolean(ignore_deleted));\n const filteredFilePaths = pattern ? filePaths.filter(fileName => fileName.match(pattern)) : filePaths;\n return filteredFilePaths.join(delimiter);\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 declare helper?: string;\n declare github_token?: string;\n declare body?: string;\n declare project_name?: string;\n declare project_destination_column_name?: string;\n declare note?: string;\n declare project_origin_column_name?: string;\n declare sha?: string;\n declare context?: string;\n declare state?: string;\n declare description?: string;\n declare target_url?: string;\n declare environment?: string;\n declare environment_url?: string;\n declare label?: string;\n declare labels?: string;\n declare paths?: string;\n declare ignore_globs?: string;\n declare override_filter_paths?: string;\n declare batches?: string;\n declare pattern?: string;\n declare teams?: string;\n declare users?: string;\n declare login?: string;\n declare paths_no_filter?: string;\n declare slack_webhook_url?: string;\n declare number_of_assignees?: string;\n declare number_of_reviewers?: string;\n declare globs?: string;\n declare override_filter_globs?: string;\n declare title?: string;\n declare seconds?: string;\n declare pull_number?: string;\n declare base?: string;\n declare head?: string;\n declare days?: string;\n declare no_evict_upon_conflict?: string;\n declare skip_if_already_set?: string;\n declare delimiter?: string;\n declare team?: string;\n declare ignore_deleted?: string;\n declare return_full_payload?: string;\n declare skip_auto_merge?: string;\n declare repo_name?: string;\n declare repo_owner_name?: string;\n declare load_balancing_sizes?: string;\n declare required_review_overrides?: string;\n declare codeowners_overrides?: string;\n declare max_queue_size?: string;\n declare allow_only_for_maintainers?: string;\n declare use_basic_matrix_configuration?: string;\n declare merge_queue_enabled?: string;\n declare packages?: string;\n}\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { 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 renamedPreviousFilenames = changedFiles\n .filter(({ status }) => status === 'renamed')\n .map(({ previous_filename }) => previous_filename)\n .filter(Boolean); // GitHub should always include previous_filename for renamed files, but just in case\n const processedFilenames = (ignore_deleted ? changedFiles.filter(({ status }) => status !== 'removed') : changedFiles).map(\n ({ filename }) => filename\n );\n return processedFilenames.concat(renamedPreviousFilenames);\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 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { paginateAllBranches } from './paginate-all-branches';\nimport { context } from '@actions/github';\n\nexport const getMergeQueueCommitHashes = async () => {\n const branches = await paginateAllBranches();\n const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/'));\n return mergeQueueBranches.map(branch => branch.commit.sha);\n};\n\nexport const getPrNumberFromMergeQueueRef = () => {\n const prNumber = Number(\n context.ref\n .split('/')\n .find(part => part.includes('pr-'))\n ?.match(/\\d+/)?.[0]\n );\n if (isNaN(prNumber)) {\n throw new Error('Could not find PR number in merge queue ref.');\n }\n return prNumber;\n};\n","/*\nCopyright 2022 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { PullRequestBranchesList } from '../types/github';\nimport { octokit } from '../octokit';\nimport { context } from '@actions/github';\n\nexport const paginateAllBranches = async ({\n protectedBranches,\n page = 1\n}: { protectedBranches?: boolean; page?: number } = {}): Promise => {\n const response = await octokit.repos.listBranches({\n protected: protectedBranches,\n per_page: 100,\n page,\n ...context.repo\n });\n if (!response.data.length) {\n return [];\n }\n return [...response.data, ...(await paginateAllBranches({ protectedBranches, page: page + 1 }))];\n};\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/get-changed-files.ts b/src/helpers/get-changed-files.ts index d6aa6734..4ff1f520 100644 --- a/src/helpers/get-changed-files.ts +++ b/src/helpers/get-changed-files.ts @@ -14,6 +14,7 @@ limitations under the License. import { HelperInputs } from '../types/generated'; import { context } from '@actions/github'; import { getChangedFilepaths } from '../utils/get-changed-filepaths'; +import { getPrNumberFromMergeQueueRef } from '../utils/merge-queue'; export class GetChangedFiles extends HelperInputs { declare pattern?: string; @@ -22,7 +23,8 @@ export class GetChangedFiles extends HelperInputs { } export const getChangedFiles = async ({ pattern, delimiter = ',', ignore_deleted }: GetChangedFiles) => { - const filePaths = await getChangedFilepaths(context.issue.number, Boolean(ignore_deleted)); + const pullNumber = context.eventName === 'merge_group' ? getPrNumberFromMergeQueueRef() : context.issue.number; + const filePaths = await getChangedFilepaths(pullNumber, Boolean(ignore_deleted)); const filteredFilePaths = pattern ? filePaths.filter(fileName => fileName.match(pattern)) : filePaths; return filteredFilePaths.join(delimiter); }; diff --git a/test/helpers/get-changed-files.test.ts b/test/helpers/get-changed-files.test.ts index f81872f2..c9948070 100644 --- a/test/helpers/get-changed-files.test.ts +++ b/test/helpers/get-changed-files.test.ts @@ -14,6 +14,7 @@ limitations under the License. import { Mocktokit } from '../types'; import { getChangedFiles } from '../../src/helpers/get-changed-files'; import { octokit } from '../../src/octokit'; +import { context } from '@actions/github'; jest.mock('@actions/core'); jest.mock('@actions/github', () => ({ @@ -154,4 +155,15 @@ describe('getChangedFiles', () => { expect(result).toEqual([mock_data4[0].filename, mock_data4[1].filename, mock_data4[1].previous_filename].join(',')); }); + + it('should handle merge queue case', async () => { + context.eventName = 'merge_group'; + context.ref = 'refs/heads/gh-readonly-queue/default-branch/pr-12345-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f'; + (octokit.pulls.listFiles as unknown as Mocktokit).mockImplementation(async ({ page, pull_number }) => ({ + data: pull_number === 12345 && page === 1 ? mock_data4 : [] + })); + const result = await getChangedFiles({}); + + expect(result).toEqual([mock_data4[0].filename, mock_data4[1].filename, mock_data4[1].previous_filename].join(',')); + }); });