https://github.com/codytseng/merge-branches-github-action
Merge all PRs with the specified label into a branch.
https://github.com/codytseng/merge-branches-github-action
Last synced: about 2 months ago
JSON representation
Merge all PRs with the specified label into a branch.
- Host: GitHub
- URL: https://github.com/codytseng/merge-branches-github-action
- Owner: CodyTseng
- License: mit
- Created: 2023-01-11T08:32:00.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-08T01:19:50.000Z (about 2 years ago)
- Last Synced: 2025-03-05T03:46:37.533Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.29 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# merge-branches-github-action
> Merge all PRs with the specified label into a branch.
## List of input options
See [action.yml](./action.yml)
| input | description | required | default |
| :--------- | :--------------------------------------------------------------------------------------------------------- | :------: | :---------------------------- |
| token | GitHub token. | true | |
| base | The name of the base branch. Merge operations will be performed on the basis of this branch. | true | |
| target | The name of the target branch. This branch will be checked out from the base branch and accept all merges. | true | |
| label-name | The name of a label to find PRs to merge. | true | |
| email | The email of the committer. | false | [email protected] |
| name | The name of the committer. | false | merge-branches-bot |## Example
```yml
name: 'merge-branches'
on:
workflow_dispatch:
inputs:
base:
description: 'The name of the base branch. Merge operations will be performed on the basis of this branch.'
required: true
default: 'main'
type: string
target:
description: 'The name of the target branch. This branch will be checked out from the base branch and accept all merges.'
required: true
type: string
label-name:
description: 'The name of a label to find PRs to merge.'
required: true
type: stringpermissions: write-all
jobs:
merge-branches:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: codytseng/merge-branches-github-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
base: ${{ inputs.base }}
target: ${{ inputs.target }}
label-name: ${{ inputs.label-name }}
```## How does it work?
1. Get all open PRs.
2. Find PRs containing the specified label.
3. `git config --global user.email ${email}`
4. `git config --global user.name ${name}`
5. `git fetch origin`
6. `git checkout ${base}`
7. `git pull origin ${base}`
8. `git branch ${target} -D`
9. `git checkout -b ${target}`
10. Loop branches `git merge origin/${branchName}` (Abort the merge if an error occurs.)
11. `git push origin ${target} -f`