Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Merge your pull request in order when enabled the `Require branches to be up to
Inspired by [Merge Queue feature of Mergify](https://mergify.io/features/merge-queue).

> Safety
>
>
> 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.

> Save CI time
>
>
> Rather than overconsuming your CI time by trying to merge multiple pull requests, just run it once before the pull request gets merged.

## Quick Start
Expand All @@ -18,7 +18,7 @@ Inspired by [Merge Queue feature of Mergify](https://mergify.io/features/merge-q

1. Enable `Allow auto-merge` in `Settings/Options`.

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

Example:

Expand Down Expand Up @@ -59,6 +59,12 @@ jobs:
requiredStatusChecks: |
build_pr
WIP
# Optionally set the maximum amount of pull requests to match against (default: 50)
fetchMaxPr: 50
# Optionally set the maximum amount of pull request checks to fetch (default: 100)
fetchMaxPrChecks: 100
# Optionally set the maximum amount of pull request labels to fetch (default: 10)
fetchMaxPrLabels: 10
```

If you are using a personal access token and it has permission to access branch protection rules, you can set your jobs like:
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ inputs:
required: false
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.'
default: ''
fetchMaxPr:
required: false
description: 'The maximum amount of pull request fetch when searching for eligible pull requests.'
default: '50'
fetchMaxPrChecks:
required: false
description: 'The maximum amount of pull request checks to fetch when searching for requiredStatusChecks.'
default: '100'
fetchMaxPrLabels:
required: false
description: 'The maximum amount of pull request labels to fetch when searching for requiredLabels.'
default: '10'
runs:
using: 'node16'
main: 'dist/index.js'
9 changes: 7 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
mergePullRequest,
updateBranch
} from './pullRequest'
import {Condition, GhContext, IssueInfo, RecordBody} from './type'
import {Condition, FetchConfig, GhContext, IssueInfo, RecordBody} from './type'
import {getViewerName} from './user'
import {
createIssueBody,
Expand Down Expand Up @@ -39,10 +39,15 @@ async function run(): Promise<void> {
const protectedBranchNamePattern = core.getInput(
'protectedBranchNamePattern'
)
const fetchConfig: FetchConfig = {
prs: parseInt(core.getInput('fetchMaxPr')),
checks: parseInt(core.getInput('fetchMaxPrChecks')),
labels: parseInt(core.getInput('fetchMaxPrLabels'))
}

const octokit = github.getOctokit(token)
const {owner, repo} = github.context.repo
const ctx: GhContext = {octokit, owner, repo, autoMergeMethod}
const ctx: GhContext = {octokit, owner, repo, autoMergeMethod, fetchConfig}

const branchProtectionRule = await getBranchProtectionRule(
ctx,
Expand Down
19 changes: 9 additions & 10 deletions src/pullRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import retry from 'async-retry'
import {
FetchConfig,
GhContext,
PullRequestInfo,
RepositoryGetPullRequest,
Expand All @@ -14,7 +15,7 @@ export async function getPullRequest(
`query ($owner: String!, $repo: String!, $num: Int!) {
repository(name: $repo, owner: $owner) {
pullRequest(number: $num) {
${pullRequestFragment}
${getPullRequestFragment(ctx.fetchConfig)}
}
}
}`,
Expand Down Expand Up @@ -96,9 +97,9 @@ async function listPullRequests(ctx: GhContext): Promise<PullRequestInfo[]> {
const result: RepositoryListPullRequest = await ctx.octokit.graphql(
`query ($owner: String!, $repo: String!) {
repository(name: $repo, owner: $owner) {
pullRequests(first: ${pullRequestCount}, states: OPEN) {
pullRequests(first: ${ctx.fetchConfig.prs}, states: OPEN) {
nodes {
${pullRequestFragment}
${getPullRequestFragment(ctx.fetchConfig)}
}
}
}
Expand All @@ -114,11 +115,8 @@ async function listPullRequests(ctx: GhContext): Promise<PullRequestInfo[]> {
return result.repository.pullRequests.nodes
}

const pullRequestCount = 50
const checkCount = 100
const labelCount = 10

const pullRequestFragment = `
function getPullRequestFragment(cfg: FetchConfig): string {
return `
id
title
baseRefName
Expand All @@ -132,7 +130,7 @@ const pullRequestFragment = `
reviewRequests {
totalCount
}
labels(first: ${labelCount}) {
labels(first: ${cfg.labels}) {
nodes {
name
}
Expand All @@ -141,7 +139,7 @@ const pullRequestFragment = `
nodes {
commit {
statusCheckRollup {
contexts(first: ${checkCount}) {
contexts(first: ${cfg.checks}) {
nodes {
... on CheckRun {
name
Expand All @@ -158,3 +156,4 @@ const pullRequestFragment = `
}
}
}`
}
7 changes: 7 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import {Octokit} from '@octokit/core'

export interface FetchConfig {
prs: number
labels: number
checks: number
}

export interface GhContext {
octokit: Octokit
owner: string
repo: string
autoMergeMethod: string
fetchConfig: FetchConfig
}

export interface Condition {
Expand Down