Skip to content

A GitHub action to rebase pull requests in a repository

License

Notifications You must be signed in to change notification settings

Broadshield/rebase

 
 

Repository files navigation

Rebase

CI GitHub Marketplace

A GitHub action to rebase pull requests in a repository.

Usage

The default behavior 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.

Action inputs

- uses: peter-evans/[email protected]
  with:
    # GitHub auth token
    # Default: ${{ github.token }}
    token: ''

    # The target GitHub repository
    # Default: ${{ github.repository }}
    repository: ''

    # Filter pull requests by head user or head organization and branch name in the
    # format user:ref-name or organization:ref-name. For example:
    # github:new-script-format or octocat:test-branch.
    head: ''

    # Filter pull requests by base branch name. Example: gh-pages.
    base: ''

    # Run this command within the branch before rebasing against `base`
    command-to-run-before-rebase: ''

    # Run this command when a conflict is found, and try to merge again.
    command-to-run-on-conflict: ''

    # The default branch for the repo, defaults to master
    # Default: master
    default-branch: ''

    # The Dependabot PR's require a PR Comment to rebase them. When this is `true` a
    # comment will be added: `@dependabot rebase`
    # Default: true
    handle-dependabot: ''

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-20.04
    steps:
      - uses: peter-evans/[email protected]

Rebase all pull requests on push to the base branch

name: Rebase
on:
  push:
    branches: [master]
jobs:
  rebase:
    runs-on: Ubuntu-20.04
    steps:
      - uses: peter-evans/[email protected]
        with:
          base: master

Run commands before and after a rebase to handle rebase conflicts

name: Rebase Open PR's after a Merge to Dev
on:
  push:
    branches:
      - dev
jobs:
  rebase:
    runs-on: Ubuntu-20.04
    steps:
      - uses: peter-evans/[email protected]
        with:
          base: dev
          default-branch: dev
          command-to-run-before-rebase: bash -c "grep -m 1 -Po '<version>\K[^<]*' pom.xml > version.tmp"
          command-to-run-on-conflict: bash -c ".github/scripts/fix_version_conflicts.rb -s git -v $(cat version.tmp);git add pom.xml;git commit -m \"Fix merge conflict\""

NOTE: This example is using the ruby script for fixing conflicting version numbers in a pom file for maven projects found here

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-20.04
    steps:
      - name: Slash Command Dispatch
        uses: peter-evans/slash-command-dispatch@v1
        with:
          token: ${{ secrets.PAT }}
          commands: rebase
          permission: write
          issue-type: pull-request

Action inputs

Name Description Default
token GITHUB_TOKEN or a repo scoped PAT. 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. For example: github:new-script-format or octocat:test-branch.
base Filter pull requests by base branch name. Example: gh-pages.
command-to-run-before-rebase Run this command within the branch before rebasing against base
command-to-run-on-conflict Run this command when a conflict is found, and try to merge again.
default-branch The default branch for the repo, defaults to master master

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-20.04
    steps:
      - uses: peter-evans/[email protected]
        with:
          token: ${{ secrets.PAT }}
          repository: ${{ matrix.repo }}

License

MIT

About

A GitHub action to rebase pull requests in a repository

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.1%
  • JavaScript 0.9%