Skip to content

Commit 8de9e7a

Browse files
authored
fix(get-merge-queue-position): use sha as input rather than pull_number (#678)
1 parent b309052 commit 8de9e7a

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

.github/workflows/get-merge-queue-position.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
- uses: ./
1717
with:
1818
helper: get-merge-queue-position
19-
pull_number: ${{ github.event.pull_request.number }}
19+
sha: ${{ github.sha }}

dist/604.index.js

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/604.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/get-merge-queue-position.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ limitations under the License.
1313

1414
import { HelperInputs } from '../types/generated';
1515
import { context } from '@actions/github';
16-
import { octokitGraphql } from '../octokit';
16+
import { octokit, octokitGraphql } from '../octokit';
1717
import { Repository } from '@octokit/graphql-schema';
1818

1919
export class GetMergeQueuePosition extends HelperInputs {
20-
pull_number = '';
20+
sha = '';
2121
max_queue_size?: string;
2222
}
2323

24-
export const getMergeQueuePosition = async ({ pull_number, max_queue_size = '10' }: GetMergeQueuePosition) => {
25-
const data = await octokitGraphql<{ repository: Repository }>(`
24+
export const getMergeQueuePosition = async ({ sha, max_queue_size = '10' }: GetMergeQueuePosition) => {
25+
const { repository } = await octokitGraphql<{ repository: Repository }>(`
2626
query {
2727
repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") {
2828
mergeQueue {
@@ -38,6 +38,11 @@ query {
3838
}
3939
}
4040
`);
41-
const mergeQueueEntries = data.repository.mergeQueue?.entries?.nodes;
42-
return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pull_number))?.position;
41+
const { data: pullRequests } = await octokit.repos.listPullRequestsAssociatedWithCommit({
42+
commit_sha: sha,
43+
...context.repo
44+
});
45+
const pullRequestNumber = pullRequests.find(Boolean)?.number;
46+
const mergeQueueEntries = repository.mergeQueue?.entries?.nodes;
47+
return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pullRequestNumber))?.position;
4348
};

test/helpers/get-merge-queue-position.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jest.mock('@actions/core');
2020
jest.mock('@actions/github', () => ({
2121
context: { repo: { repo: 'repo', owner: 'owner' }, issue: { number: 123 } },
2222
getOctokit: jest.fn(() => ({
23+
rest: {
24+
repos: {
25+
listPullRequestsAssociatedWithCommit: jest.fn(({ commit_sha }) => ({ data: [{ number: Number(commit_sha.split('sha')[1]) }] }))
26+
}
27+
},
2328
graphql: jest.fn()
2429
}))
2530
}));
@@ -45,7 +50,7 @@ describe('getMergeQueuePosition', () => {
4550
{ position: 1, pullRequest: { number: 123 } },
4651
{ position: 2, pullRequest: { number: 456 } }
4752
]);
48-
const result = await getMergeQueuePosition({ pull_number: '123' });
53+
const result = await getMergeQueuePosition({ sha: 'sha123' });
4954
expect(result).toBe(1);
5055
});
5156

@@ -55,7 +60,7 @@ describe('getMergeQueuePosition', () => {
5560
{ position: 2, pullRequest: { number: 456 } },
5661
{ position: 3, pullRequest: { number: 789 } }
5762
]);
58-
const result = await getMergeQueuePosition({ pull_number: '789' });
63+
const result = await getMergeQueuePosition({ sha: 'sha789' });
5964
expect(result).toBe(3);
6065
});
6166
});

0 commit comments

Comments
 (0)