Skip to content

Commit b309052

Browse files
authored
feat(get-merge-queue-position): add merge queue position helper (#677)
1 parent 9a90ec4 commit b309052

File tree

13 files changed

+273
-12
lines changed

13 files changed

+273
-12
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Get Merge Queue Position
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
paths:
7+
- 'src/helpers/get-merge-queue-position.ts'
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- uses: ./
17+
with:
18+
helper: get-merge-queue-position
19+
pull_number: ${{ github.event.pull_request.number }}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ with:
4646

4747
Each of the following helpers are defined in a file of the same name in `src/helpers`:
4848

49+
### [get-merge-queue-position](.github/workflows/get-merge-queue-position.yml)
50+
51+
- Returns the current position of a given PR in the GitHub merge queue
52+
4953
### [are-reviewers-required](.github/workflows/are-reviewers-required.yml)
5054

5155
- Returns true if all teams specified are requested for review on a pull request

bun.lockb

1.21 KB
Binary file not shown.

dist/604.index.js

Lines changed: 122 additions & 0 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 & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42973,6 +42973,16 @@ var map = {
4297342973
461,
4297442974
338
4297542975
],
42976+
"./get-merge-queue-position": [
42977+
3604,
42978+
461,
42979+
604
42980+
],
42981+
"./get-merge-queue-position.ts": [
42982+
3604,
42983+
461,
42984+
604
42985+
],
4297642986
"./initiate-deployment": [
4297742987
5264,
4297842988
461,

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@actions/core": "1.11.1",
99
"@actions/github": "6.0.0",
1010
"@adobe/node-fetch-retry": "2.2.0",
11+
"@octokit/graphql-schema": "15.25.0",
1112
"@octokit/rest": "21.0.2",
1213
"axios": "1.7.9",
1314
"bluebird": "3.7.2",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2021 Expedia, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
https://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
import { HelperInputs } from '../types/generated';
15+
import { context } from '@actions/github';
16+
import { octokitGraphql } from '../octokit';
17+
import { Repository } from '@octokit/graphql-schema';
18+
19+
export class GetMergeQueuePosition extends HelperInputs {
20+
pull_number = '';
21+
max_queue_size?: string;
22+
}
23+
24+
export const getMergeQueuePosition = async ({ pull_number, max_queue_size = '10' }: GetMergeQueuePosition) => {
25+
const data = await octokitGraphql<{ repository: Repository }>(`
26+
query {
27+
repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") {
28+
mergeQueue {
29+
entries(first: ${max_queue_size}) {
30+
nodes {
31+
pullRequest {
32+
number
33+
}
34+
position
35+
}
36+
}
37+
}
38+
}
39+
}
40+
`);
41+
const mergeQueueEntries = data.repository.mergeQueue?.entries?.nodes;
42+
return mergeQueueEntries?.find(entry => entry?.pullRequest?.number === Number(pull_number))?.position;
43+
};

templates/helper.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { context } from '@actions/github';
1616
import { octokit } from '../octokit';
1717

1818
export class {{ properCase helper }} extends HelperInputs {
19-
requiredInput = '';
20-
optionalInput?: string;
19+
requiredInput = '';
20+
optionalInput?: string;
2121
}
2222

2323
export const {{ camelCase helper }} = async ({ requiredInput, optionalInput }: {{ properCase helper }}) => {

0 commit comments

Comments
 (0)