From 4014a439b59ba1ed428a52cfff2d13f7c9b95fc8 Mon Sep 17 00:00:00 2001 From: Dan Adajian Date: Thu, 19 Dec 2024 10:23:50 -0600 Subject: [PATCH] fix(get-merge-queue-position): use sha as input rather than pull_number --- .github/workflows/get-merge-queue-position.yml | 2 +- dist/604.index.js | 15 ++++++++++----- dist/604.index.js.map | 2 +- src/helpers/get-merge-queue-position.ts | 17 +++++++++++------ test/helpers/get-merge-queue-position.test.ts | 9 +++++++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/get-merge-queue-position.yml b/.github/workflows/get-merge-queue-position.yml index a2320e3d..22ee102f 100644 --- a/.github/workflows/get-merge-queue-position.yml +++ b/.github/workflows/get-merge-queue-position.yml @@ -16,4 +16,4 @@ jobs: - uses: ./ with: helper: get-merge-queue-position - pull_number: ${{ github.event.pull_request.number }} + sha: ${{ github.sha }} diff --git a/dist/604.index.js b/dist/604.index.js index dc2ac139..e184c9c3 100644 --- a/dist/604.index.js +++ b/dist/604.index.js @@ -32,11 +32,11 @@ limitations under the License. class GetMergeQueuePosition extends _types_generated__WEBPACK_IMPORTED_MODULE_2__/* .HelperInputs */ .m { constructor() { super(...arguments); - this.pull_number = ''; + this.sha = ''; } } -const getMergeQueuePosition = async ({ pull_number, max_queue_size = '10' }) => { - const data = await (0,_octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokitGraphql */ .n)(` +const getMergeQueuePosition = async ({ sha, max_queue_size = '10' }) => { + const { repository } = await (0,_octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokitGraphql */ .n)(` query { repository(owner: "${_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo.owner}", name: "${_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo.repo}") { mergeQueue { @@ -52,8 +52,13 @@ query { } } `); - const mergeQueueEntries = data.repository.mergeQueue?.entries?.nodes; - return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pull_number))?.position; + const { data: pullRequests } = await _octokit__WEBPACK_IMPORTED_MODULE_1__/* .octokit */ .A.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: sha, + ..._actions_github__WEBPACK_IMPORTED_MODULE_0__.context.repo + }); + const pullRequestNumber = pullRequests.find(Boolean)?.number; + const mergeQueueEntries = repository.mergeQueue?.entries?.nodes; + return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pullRequestNumber))?.position; }; diff --git a/dist/604.index.js.map b/dist/604.index.js.map index cb850c13..a8e6e303 100644 --- a/dist/604.index.js.map +++ b/dist/604.index.js.map @@ -1 +1 @@ -{"version":3,"file":"604.index.js","mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAGA;AAAA;;AACA;AAEA;AAAA;AAEA;AACA;;AAEA;;AAEA;;;;;;;;;;;AAWA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC1CA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA","sources":[".././src/helpers/get-merge-queue-position.ts",".././src/octokit.ts",".././src/types/generated.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokitGraphql } from '../octokit';\nimport { Repository } from '@octokit/graphql-schema';\n\nexport class GetMergeQueuePosition extends HelperInputs {\n pull_number = '';\n max_queue_size?: string;\n}\n\nexport const getMergeQueuePosition = async ({ pull_number, max_queue_size = '10' }: GetMergeQueuePosition) => {\n const data = await octokitGraphql<{ repository: Repository }>(`\nquery {\n repository(owner: \"${context.repo.owner}\", name: \"${context.repo.repo}\") {\n mergeQueue {\n entries(first: ${max_queue_size}) {\n nodes {\n pullRequest {\n number\n }\n position\n }\n }\n }\n }\n}\n`);\n const mergeQueueEntries = data.repository.mergeQueue?.entries?.nodes;\n return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pull_number))?.position;\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"604.index.js","mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAGA;AAAA;;AACA;AAEA;AAAA;AAEA;AACA;;AAEA;;AAEA;;;;;;;;;;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;AC/CA;;;;;;;;;;;AAWA;AAEA;AACA;AACA;AAEA;AACA;;;;;;;;;;;AClBA;;;;;;;;;;;AAWA;AAEA;AAoDA","sources":[".././src/helpers/get-merge-queue-position.ts",".././src/octokit.ts",".././src/types/generated.ts"],"sourcesContent":["/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\nhttps://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { HelperInputs } from '../types/generated';\nimport { context } from '@actions/github';\nimport { octokit, octokitGraphql } from '../octokit';\nimport { Repository } from '@octokit/graphql-schema';\n\nexport class GetMergeQueuePosition extends HelperInputs {\n sha = '';\n max_queue_size?: string;\n}\n\nexport const getMergeQueuePosition = async ({ sha, max_queue_size = '10' }: GetMergeQueuePosition) => {\n const { repository } = await octokitGraphql<{ repository: Repository }>(`\nquery {\n repository(owner: \"${context.repo.owner}\", name: \"${context.repo.repo}\") {\n mergeQueue {\n entries(first: ${max_queue_size}) {\n nodes {\n pullRequest {\n number\n }\n position\n }\n }\n }\n }\n}\n`);\n const { data: pullRequests } = await octokit.repos.listPullRequestsAssociatedWithCommit({\n commit_sha: sha,\n ...context.repo\n });\n const pullRequestNumber = pullRequests.find(Boolean)?.number;\n const mergeQueueEntries = repository.mergeQueue?.entries?.nodes;\n return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pullRequestNumber))?.position;\n};\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as core from '@actions/core';\nimport * as fetch from '@adobe/node-fetch-retry';\nimport { getOctokit } from '@actions/github';\n\nconst githubToken = core.getInput('github_token', { required: true });\nexport const { rest: octokit, graphql: octokitGraphql } = getOctokit(githubToken, { request: { fetch } });\n","/*\nCopyright 2021 Expedia, Inc.\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n https://www.apache.org/licenses/LICENSE-2.0\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport class HelperInputs {\n helper?: string;\n github_token?: string;\n body?: string;\n project_name?: string;\n project_destination_column_name?: string;\n note?: string;\n project_origin_column_name?: string;\n sha?: string;\n context?: string;\n state?: string;\n description?: string;\n target_url?: string;\n environment?: string;\n environment_url?: string;\n label?: string;\n labels?: string;\n paths?: string;\n ignore_globs?: string;\n extensions?: string;\n override_filter_paths?: string;\n batches?: string;\n pattern?: string;\n teams?: string;\n users?: string;\n login?: string;\n paths_no_filter?: string;\n slack_webhook_url?: string;\n number_of_assignees?: string;\n number_of_reviewers?: string;\n globs?: string;\n override_filter_globs?: string;\n title?: string;\n seconds?: string;\n pull_number?: string;\n base?: string;\n head?: string;\n days?: string;\n no_evict_upon_conflict?: string;\n skip_if_already_set?: string;\n delimiter?: string;\n team?: string;\n ignore_deleted?: string;\n return_full_payload?: string;\n skip_auto_merge?: string;\n repo_name?: string;\n repo_owner_name?: string;\n load_balancing_sizes?: string;\n required_review_overrides?: string;\n max_queue_size?: string;\n allow_only_for_maintainers?: string;\n use_basic_matrix_configuration?: string;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/src/helpers/get-merge-queue-position.ts b/src/helpers/get-merge-queue-position.ts index b1abf206..ecfb3e87 100644 --- a/src/helpers/get-merge-queue-position.ts +++ b/src/helpers/get-merge-queue-position.ts @@ -13,16 +13,16 @@ limitations under the License. import { HelperInputs } from '../types/generated'; import { context } from '@actions/github'; -import { octokitGraphql } from '../octokit'; +import { octokit, octokitGraphql } from '../octokit'; import { Repository } from '@octokit/graphql-schema'; export class GetMergeQueuePosition extends HelperInputs { - pull_number = ''; + sha = ''; max_queue_size?: string; } -export const getMergeQueuePosition = async ({ pull_number, max_queue_size = '10' }: GetMergeQueuePosition) => { - const data = await octokitGraphql<{ repository: Repository }>(` +export const getMergeQueuePosition = async ({ sha, max_queue_size = '10' }: GetMergeQueuePosition) => { + const { repository } = await octokitGraphql<{ repository: Repository }>(` query { repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") { mergeQueue { @@ -38,6 +38,11 @@ query { } } `); - const mergeQueueEntries = data.repository.mergeQueue?.entries?.nodes; - return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pull_number))?.position; + const { data: pullRequests } = await octokit.repos.listPullRequestsAssociatedWithCommit({ + commit_sha: sha, + ...context.repo + }); + const pullRequestNumber = pullRequests.find(Boolean)?.number; + const mergeQueueEntries = repository.mergeQueue?.entries?.nodes; + return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pullRequestNumber))?.position; }; diff --git a/test/helpers/get-merge-queue-position.test.ts b/test/helpers/get-merge-queue-position.test.ts index ab66e797..7c34ddae 100644 --- a/test/helpers/get-merge-queue-position.test.ts +++ b/test/helpers/get-merge-queue-position.test.ts @@ -20,6 +20,11 @@ jest.mock('@actions/core'); jest.mock('@actions/github', () => ({ context: { repo: { repo: 'repo', owner: 'owner' }, issue: { number: 123 } }, getOctokit: jest.fn(() => ({ + rest: { + repos: { + listPullRequestsAssociatedWithCommit: jest.fn(({ commit_sha }) => ({ data: [{ number: Number(commit_sha.split('sha')[1]) }] })) + } + }, graphql: jest.fn() })) })); @@ -45,7 +50,7 @@ describe('getMergeQueuePosition', () => { { position: 1, pullRequest: { number: 123 } }, { position: 2, pullRequest: { number: 456 } } ]); - const result = await getMergeQueuePosition({ pull_number: '123' }); + const result = await getMergeQueuePosition({ sha: 'sha123' }); expect(result).toBe(1); }); @@ -55,7 +60,7 @@ describe('getMergeQueuePosition', () => { { position: 2, pullRequest: { number: 456 } }, { position: 3, pullRequest: { number: 789 } } ]); - const result = await getMergeQueuePosition({ pull_number: '789' }); + const result = await getMergeQueuePosition({ sha: 'sha789' }); expect(result).toBe(3); }); });