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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ jobs:
- uses: ./
with:
token: ${{ secrets.ACTION_PAT }}
requiredApprovals: 2
requiredLabels: auto-merge
requiredStatusChecks: |
build
test
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ Inspired by [Merge Queue feature of Mergify](https://mergify.io/features/merge-q

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

2. Create a branch protection rule in `Settings/Branches`
2. (Optional) Create a branch protection rule in `Settings/Branches`.

Support checks:

- `Require approvals`
- `Status checks that are required`

This feature requires personal access token that has enough permission.

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

```yaml
Expand All @@ -48,12 +50,19 @@ jobs:
steps:
- uses: lcdsmao/update-branch@v3
with:
# Personal access token
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
token: ${{ secrets.MY_PERSONAL_ACCESS_TOKEN }}
# Or use personal access token
token: ${{ secrets.GITHUB_TOKEN }}
# One of MERGE, SQUASH, REBASE (default: MERGE)
autoMergeMethod: SQUASH
# Required at least 2 approves (default: 0)
requiredApprovals: 2
# Ignore pull requests without these labels
requiredLabels: auto-merge
# Required these status checks success
requiredStatusChecks: |
build_pr
WIP
# Optional branch name pattern instead of main or master
# Status checks will be used
# protectedBranchNamePattern: trunk
```
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ branding:
inputs:
token:
required: true
description: 'Require personal access token to access branch protection rules or trigger other workflows.'
description: 'Github token or personal access token. Require personal access token to access branch protection rules or trigger other workflows.'
autoMergeMethod:
required: false
description: 'Method to use when enable pull request auto merge.'
default: 'MERGE'
requiredLabels:
required: false
description: 'Labels need to be present for a pull request.'
requiredApprovals:
required: false
description: 'Count of required approval'
default: '0'
requiredStatusChecks:
required: false
description: 'Multiple status checks required to be success'
default: ''
protectedBranchNamePattern:
required: false
description: 'The name pattern of the base branch that your pull request wants to merge into. Branch protection rule with the same name pattern must be existed. If not set, the default behavior is to find the name pattern of main or master.'
Expand Down
25 changes: 15 additions & 10 deletions dist/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/index.js.map

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ import {isPendingMergePr, isStatusCheckPassPr, stringify} from './utils'

async function run(): Promise<void> {
try {
const protectedBranchNamePattern = core.getInput(
'protectedBranchNamePattern'
)
const token = core.getInput('token')
const autoMergeMethod = core.getInput('autoMergeMethod')
const requiredLabels = core
.getInput('requiredLabels')
.split('\n')
.filter(s => s !== '')
const requiredApprovals = parseInt(core.getInput('requiredApprovals'))
const requiredStatusChecks = core
.getInput('requiredStatusChecks')
.split('\n')
.filter(s => s !== '')
const protectedBranchNamePattern = core.getInput(
'protectedBranchNamePattern'
)

const octokit = github.getOctokit(token)
const {owner, repo} = github.context.repo
Expand All @@ -33,21 +38,16 @@ async function run(): Promise<void> {
ctx,
protectedBranchNamePattern
)
if (!branchProtectionRule) {
throw Error(
`Not found branch protection rule with name pattern of ${
protectedBranchNamePattern
? protectedBranchNamePattern
: 'main or master'
}.`
)
}

const condition: Condition = {
branchNamePattern: branchProtectionRule.pattern,
requiredApprovals: branchProtectionRule.requiredApprovingReviewCount ?? 0,
requiredStatusChecks:
branchProtectionRule.requiredStatusCheckContexts ?? [],
branchNamePattern: branchProtectionRule?.pattern,
requiredApprovals:
requiredApprovals ||
(branchProtectionRule?.requiredApprovingReviewCount ?? 0),
requiredStatusChecks: [
...requiredStatusChecks,
...(branchProtectionRule?.requiredStatusCheckContexts ?? [])
],
requiredLabels
}

Expand Down
2 changes: 1 addition & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface GhContext {
}

export interface Condition {
branchNamePattern: string
branchNamePattern?: string
requiredApprovals: number
requiredStatusChecks: string[]
requiredLabels: string[]
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function isSatisfyBasicConditionPr(
pr.reviews.totalCount >= condition.requiredApprovals &&
pr.reviewRequests.totalCount === 0 &&
hasLabels(pr, condition) &&
minimatch(pr.baseRefName, condition.branchNamePattern)
minimatch(pr.baseRefName, condition.branchNamePattern ?? '*')
)
}

Expand Down