Skip to content

Commit 6d6e097

Browse files
authored
fix(get-merge-queue-position): misc merge queue fixes (#690)
1 parent 3e26ab6 commit 6d6e097

12 files changed

+32
-39
lines changed

dist/264.index.js

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

dist/264.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.

dist/467.index.js

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

dist/467.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.

dist/604.index.js

Lines changed: 6 additions & 11 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: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ limitations under the License.
1313

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

1919
export class GetMergeQueuePosition extends HelperInputs {
20-
sha = '';
2120
max_queue_size?: string;
2221
}
2322

24-
export const getMergeQueuePosition = async ({ sha, max_queue_size = '10' }: GetMergeQueuePosition) => {
23+
export const getMergeQueuePosition = async ({ max_queue_size = '10' }: GetMergeQueuePosition) => {
2524
const { repository } = await octokitGraphql<{ repository: Repository }>(`
2625
query {
2726
repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") {
@@ -38,11 +37,12 @@ query {
3837
}
3938
}
4039
`);
41-
const { data: pullRequests } = await octokit.repos.listPullRequestsAssociatedWithCommit({
42-
commit_sha: sha,
43-
...context.repo
44-
});
45-
const pullRequestNumber = pullRequests.find(Boolean)?.number;
40+
const prNumberFromMergeQueueRef = Number(
41+
context.ref
42+
.split('/')
43+
.find(part => part.includes('pr-'))
44+
?.match(/\d+/)?.[0]
45+
);
4646
const mergeQueueEntries = repository.mergeQueue?.entries?.nodes;
47-
return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pullRequestNumber))?.position;
47+
return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === prNumberFromMergeQueueRef)?.position;
4848
};

src/utils/get-merge-queue-commit-hashes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ import { paginateAllBranches } from './paginate-all-branches';
1515

1616
export const getMergeQueueCommitHashes = async () => {
1717
const branches = await paginateAllBranches();
18-
const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/merge-queue/'));
18+
const mergeQueueBranches = branches.filter(branch => branch.name.startsWith('gh-readonly-queue/'));
1919
return mergeQueueBranches.map(branch => branch.commit.sha);
2020
};

test/helpers/filter-paths.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('filterPaths', () => {
211211

212212
it('should not call listPullRequestsAssociatedWithCommit if sha is omitted', async () => {
213213
context.eventName = 'merge_group';
214-
context.ref = 'refs/heads/gh-readonly-queue/branch-name/pr-12345-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f';
214+
context.ref = 'refs/heads/gh-readonly-queue/default-branch/pr-12345-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f';
215215
await filterPaths({
216216
paths
217217
});

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ import { Mocktokit } from '../types';
1515
import { getMergeQueuePosition } from '../../src/helpers/get-merge-queue-position';
1616
import { octokitGraphql } from '../../src/octokit';
1717
import { MergeQueueEntry } from '@octokit/graphql-schema';
18+
import { context } from '@actions/github';
1819

1920
jest.mock('@actions/core');
2021
jest.mock('@actions/github', () => ({
21-
context: { repo: { repo: 'repo', owner: 'owner' }, issue: { number: 123 } },
22+
context: { repo: { repo: 'repo', owner: 'owner' } },
2223
getOctokit: jest.fn(() => ({
23-
rest: {
24-
repos: {
25-
listPullRequestsAssociatedWithCommit: jest.fn(({ commit_sha }) => ({ data: [{ number: Number(commit_sha.split('sha')[1]) }] }))
26-
}
27-
},
2824
graphql: jest.fn()
2925
}))
3026
}));
@@ -46,21 +42,23 @@ function mockGraphQLResponse(mergeQueueEntries: RecursivePartial<MergeQueueEntry
4642

4743
describe('getMergeQueuePosition', () => {
4844
it('should return 1 for PR 1st in the queue', async () => {
45+
context.ref = 'refs/heads/gh-readonly-queue/default-branch/pr-123-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f';
4946
mockGraphQLResponse([
5047
{ position: 1, pullRequest: { number: 123 } },
5148
{ position: 2, pullRequest: { number: 456 } }
5249
]);
53-
const result = await getMergeQueuePosition({ sha: 'sha123' });
50+
const result = await getMergeQueuePosition({});
5451
expect(result).toBe(1);
5552
});
5653

5754
it('should return 3 for PR 3rd in the queue', async () => {
55+
context.ref = 'refs/heads/gh-readonly-queue/default-branch/pr-789-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f';
5856
mockGraphQLResponse([
5957
{ position: 1, pullRequest: { number: 123 } },
6058
{ position: 2, pullRequest: { number: 456 } },
6159
{ position: 3, pullRequest: { number: 789 } }
6260
]);
63-
const result = await getMergeQueuePosition({ sha: 'sha789' });
61+
const result = await getMergeQueuePosition({});
6462
expect(result).toBe(3);
6563
});
6664
});

0 commit comments

Comments
 (0)