rebase
rebase copied to clipboard
A GitHub action to rebase pull requests in a repository
Rebase
A GitHub action to rebase pull requests in a repository.
Usage
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
Periodically rebase all pull requests
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
Rebase all pull requests on push to the base branch
name: Rebase
on:
push:
branches: [main]
jobs:
rebase:
runs-on: ubuntu-latest
steps:
- uses: peter-evans/rebase@v3
with:
base: main
Exclude pull requests with specific labels
- uses: peter-evans/rebase@v3
with:
exclude-labels: |
no-rebase
dependencies
Exclude pull request forks with head filter
- uses: peter-evans/rebase@v3
with:
head: 'my-org:*'
Action inputs
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 slash command
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
Target other repositories
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 }}
License
MIT