Skip to content

About

A tool to merge your pull-requests

Resources

Stars

2 stars

Watchers

2 watching

Forks

Repository files navigation

contrib-merge

A tool to merge, changelog and downbase your pull-requests.

How to use it ?

Merge a pull-request

# Preview the merge
$ contrib-merge --pr 123
# Do the merge
$ contrib-merge --pr 123 --merge

Changelog a pull-request

$ contrib-merge --pr 123 --changelog

Move a pull-request down to a lower branch

Contributors sometimes target the default branch (master) when the fix belongs on a maintenance branch (5.11.x). --downbase replays their commits onto that lower branch and retargets the pull-request, without asking the contributor to redo anything.

# See what would happen, changing nothing
$ contrib-merge --pr 672 --downbase 5.11.x --dry-run
# Do it
$ contrib-merge --pr 672 --downbase 5.11.x

What it does, in order:

  1. Fetches the pull-request head branch into a throwaway git worktree.
  2. Resets the worktree hard onto the lower branch.
  3. Cherry-picks the pull-request's own commits.
  4. A conflict on phpstan-baseline.neon or psalm-baseline.xml is expected and settled by regenerating the baselines: composer run update:baselines, run with the composer-phpX.Y wrapper matching the PHP version the lower branch's composer.json requires. The result lands as its own Regenerate the baselines commit. If the wrapper is missing or the project has no update:baselines script, the run stops and says the baselines have to be regenerated by hand.
  5. Any other conflict aborts the whole run, leaving the pull-request untouched.
  6. Edits the pull-request base to the lower branch, then force-pushes the replayed branch back to the contributor's fork (--force-with-lease, so a branch that moved under us fails instead of being overwritten). If that push fails, the base is put back.

It is atomic: either the pull-request is moved onto the lower branch, or nothing on GitHub changes.

--dry-run runs every step above except the two GitHub writes, and prints the PATCH and the git push it would have made.

Requirements

  • PHP 8.1 or newer, with curl.
  • git on PATH.
  • A GitHub token, either in git config github.token or in the GITHUB_TOKEN / GH_TOKEN environment variable (optional for public repositories, required to retarget a pull-request).
  • The contributor's fork must allow maintainers to edit the branch ("Allow edits by maintainers"); --downbase refuses otherwise.

Development

$ composer install
$ composer run test      # PHPUnit
$ composer run phpstan   # PHPStan, level max

About

A tool to merge your pull-requests

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages