Skip to content

Commit 91ca3d2

Browse files
authored
Allow configuration of fetch count (#364)
1 parent 8f9a646 commit 91ca3d2

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Merge your pull request in order when enabled the `Require branches to be up to
55
Inspired by [Merge Queue feature of Mergify](https://mergify.io/features/merge-queue).
66

77
> Safety
8-
>
8+
>
99
> Do not merge broken pull requests. By merging your pull requests serially using a queue, your code is safe. Each pull request is tested with the latest CI code.
1010
1111
> Save CI time
12-
>
12+
>
1313
> Rather than overconsuming your CI time by trying to merge multiple pull requests, just run it once before the pull request gets merged.
1414
1515
## Quick Start
@@ -18,7 +18,7 @@ Inspired by [Merge Queue feature of Mergify](https://mergify.io/features/merge-q
1818
1919
1. Enable `Allow auto-merge` in `Settings/Options`.
2020

21-
3. Create a workflow file (`.github/workflow/update-branch.yaml`):
21+
2. Create a workflow file (`.github/workflow/update-branch.yaml`):
2222

2323
Example:
2424

@@ -59,6 +59,12 @@ jobs:
5959
requiredStatusChecks: |
6060
build_pr
6161
WIP
62+
# Optionally set the maximum amount of pull requests to match against (default: 50)
63+
fetchMaxPr: 50
64+
# Optionally set the maximum amount of pull request checks to fetch (default: 100)
65+
fetchMaxPrChecks: 100
66+
# Optionally set the maximum amount of pull request labels to fetch (default: 10)
67+
fetchMaxPrLabels: 10
6268
```
6369
6470
If you are using a personal access token and it has permission to access branch protection rules, you can set your jobs like:

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ inputs:
3131
required: false
3232
description: 'The name pattern of GitHub branch protection rules to apply. The default behavior is to find the name pattern of main or master. Require personal access token to let this feature work.'
3333
default: ''
34+
fetchMaxPr:
35+
required: false
36+
description: 'The maximum amount of pull request fetch when searching for eligible pull requests.'
37+
default: '50'
38+
fetchMaxPrChecks:
39+
required: false
40+
description: 'The maximum amount of pull request checks to fetch when searching for requiredStatusChecks.'
41+
default: '100'
42+
fetchMaxPrLabels:
43+
required: false
44+
description: 'The maximum amount of pull request labels to fetch when searching for requiredLabels.'
45+
default: '10'
3446
runs:
3547
using: 'node16'
3648
main: 'dist/index.js'

src/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
mergePullRequest,
1010
updateBranch
1111
} from './pullRequest'
12-
import {Condition, GhContext, IssueInfo, RecordBody} from './type'
12+
import {Condition, FetchConfig, GhContext, IssueInfo, RecordBody} from './type'
1313
import {getViewerName} from './user'
1414
import {
1515
createIssueBody,
@@ -39,10 +39,15 @@ async function run(): Promise<void> {
3939
const protectedBranchNamePattern = core.getInput(
4040
'protectedBranchNamePattern'
4141
)
42+
const fetchConfig: FetchConfig = {
43+
prs: parseInt(core.getInput('fetchMaxPr')),
44+
checks: parseInt(core.getInput('fetchMaxPrChecks')),
45+
labels: parseInt(core.getInput('fetchMaxPrLabels'))
46+
}
4247

4348
const octokit = github.getOctokit(token)
4449
const {owner, repo} = github.context.repo
45-
const ctx: GhContext = {octokit, owner, repo, autoMergeMethod}
50+
const ctx: GhContext = {octokit, owner, repo, autoMergeMethod, fetchConfig}
4651

4752
const branchProtectionRule = await getBranchProtectionRule(
4853
ctx,

src/pullRequest.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import retry from 'async-retry'
22
import {
3+
FetchConfig,
34
GhContext,
45
PullRequestInfo,
56
RepositoryGetPullRequest,
@@ -14,7 +15,7 @@ export async function getPullRequest(
1415
`query ($owner: String!, $repo: String!, $num: Int!) {
1516
repository(name: $repo, owner: $owner) {
1617
pullRequest(number: $num) {
17-
${pullRequestFragment}
18+
${getPullRequestFragment(ctx.fetchConfig)}
1819
}
1920
}
2021
}`,
@@ -96,9 +97,9 @@ async function listPullRequests(ctx: GhContext): Promise<PullRequestInfo[]> {
9697
const result: RepositoryListPullRequest = await ctx.octokit.graphql(
9798
`query ($owner: String!, $repo: String!) {
9899
repository(name: $repo, owner: $owner) {
99-
pullRequests(first: ${pullRequestCount}, states: OPEN) {
100+
pullRequests(first: ${ctx.fetchConfig.prs}, states: OPEN) {
100101
nodes {
101-
${pullRequestFragment}
102+
${getPullRequestFragment(ctx.fetchConfig)}
102103
}
103104
}
104105
}
@@ -114,11 +115,8 @@ async function listPullRequests(ctx: GhContext): Promise<PullRequestInfo[]> {
114115
return result.repository.pullRequests.nodes
115116
}
116117

117-
const pullRequestCount = 50
118-
const checkCount = 100
119-
const labelCount = 10
120-
121-
const pullRequestFragment = `
118+
function getPullRequestFragment(cfg: FetchConfig): string {
119+
return `
122120
id
123121
title
124122
baseRefName
@@ -132,7 +130,7 @@ const pullRequestFragment = `
132130
reviewRequests {
133131
totalCount
134132
}
135-
labels(first: ${labelCount}) {
133+
labels(first: ${cfg.labels}) {
136134
nodes {
137135
name
138136
}
@@ -141,7 +139,7 @@ const pullRequestFragment = `
141139
nodes {
142140
commit {
143141
statusCheckRollup {
144-
contexts(first: ${checkCount}) {
142+
contexts(first: ${cfg.checks}) {
145143
nodes {
146144
... on CheckRun {
147145
name
@@ -158,3 +156,4 @@ const pullRequestFragment = `
158156
}
159157
}
160158
}`
159+
}

src/type.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import {Octokit} from '@octokit/core'
22

3+
export interface FetchConfig {
4+
prs: number
5+
labels: number
6+
checks: number
7+
}
8+
39
export interface GhContext {
410
octokit: Octokit
511
owner: string
612
repo: string
713
autoMergeMethod: string
14+
fetchConfig: FetchConfig
815
}
916

1017
export interface Condition {

0 commit comments

Comments
 (0)