A GitHub action to rebase pull requests in a repository.
The default behaviour of the action with no configured inputs is to check the current repository for rebaseable pull requests and rebase them. Pull requests from forks are rebaseable only if they allow edits from maintainers.
- uses: peter-evans/rebase@v3
The simplest way to use this action is to schedule it to run periodically.
name: Rebase
on:
schedule:
- cron: '0 0 * * *'
jobs:
rebase:
runs-on: ubuntu-latest
steps:
- uses: peter-evans/rebase@v3
name: Rebase
on:
push:
branches: [main]
jobs:
rebase:
runs-on: ubuntu-latest
steps:
- uses: peter-evans/rebase@v3
with:
base: main
- uses: peter-evans/rebase@v3
with:
exclude-labels: |
no-rebase
dependencies
- uses: peter-evans/rebase@v3
with:
head: 'my-org:*'
Name | Description | Default |
---|---|---|
token |
GITHUB_TOKEN or a repo scoped PAT. The workflow scope may also be required if rebasing pull requests containing changes to workflows under .github/workflows . |
GITHUB_TOKEN |
repository |
The target GitHub repository containing the pull request. | github.repository (Current repository) |
head |
Filter pull requests by head user or head organization and branch name in the format user:ref-name or organization:ref-name . Use the * wildcard match any ref. e.g. my-org:new-script-format or octocat:* . |
|
base |
Filter pull requests by base branch name. Example: gh-pages . |
|
include-labels |
A comma or newline separated list of pull request labels to include. Allows any labels if unspecified. | |
exclude-labels |
A comma or newline separated list of pull request labels to exclude. | |
exclude-drafts |
Exclude draft pull requests. | false |
rebase-options |
A comma or newline separated list of options to pass to the git rebase command. For example, -Xtheirs . |
Use the following two workflows and a repo
scoped PAT to add a /rebase
slash command to pull request comments.
The slash-command-dispatch action makes sure that the command is only executable by users with write
access to the repository.
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v3
with:
token: ${{ secrets.PAT }}
commands: rebase
permission: write
issue-type: pull-request
name: rebase-command
on:
repository_dispatch:
types: [rebase-command]
jobs:
rebase:
runs-on: ubuntu-latest
steps:
- uses: peter-evans/rebase@v3
id: rebase
with:
head: ${{ github.event.client_payload.pull_request.head.label }}
- name: Add reaction
if: steps.rebase.outputs.rebased-count == 1
uses: peter-evans/create-or-update-comment@v1
with:
token: ${{ secrets.PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: hooray
You can rebase requests in another repository by using a repo
scoped PAT instead of GITHUB_TOKEN
.
The user associated with the PAT must have write access to the repository.
This example targets multiple repositories.
name: Rebase
on:
schedule:
- cron: '0 0 * * *'
jobs:
rebase:
strategy:
matrix:
repo: ['my-org/repo1', 'my-org/repo2', 'my-org/repo3']
runs-on: ubuntu-latest
steps:
- uses: peter-evans/rebase@v3
with:
token: ${{ secrets.PAT }}
repository: ${{ matrix.repo }}