Skip to content

Commit

Permalink
fix(get-merge-queue-position): use sha as input rather than pull_number
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian committed Dec 19, 2024
1 parent b309052 commit 4014a43
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/get-merge-queue-position.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
- uses: ./
with:
helper: get-merge-queue-position
pull_number: ${{ github.event.pull_request.number }}
sha: ${{ github.sha }}
15 changes: 10 additions & 5 deletions dist/604.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/604.index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions src/helpers/get-merge-queue-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
};
9 changes: 7 additions & 2 deletions test/helpers/get-merge-queue-position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}))
}));
Expand All @@ -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);
});

Expand All @@ -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);
});
});

0 comments on commit 4014a43

Please sign in to comment.