A tool to merge, changelog and downbase your pull-requests.
# Preview the merge
$ contrib-merge --pr 123
# Do the merge
$ contrib-merge --pr 123 --merge$ contrib-merge --pr 123 --changelogContributors 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.xWhat it does, in order:
- Fetches the pull-request head branch into a throwaway git worktree.
- Resets the worktree hard onto the lower branch.
- Cherry-picks the pull-request's own commits.
- A conflict on
phpstan-baseline.neonorpsalm-baseline.xmlis expected and settled by regenerating the baselines:composer run update:baselines, run with thecomposer-phpX.Ywrapper matching the PHP version the lower branch'scomposer.jsonrequires. The result lands as its ownRegenerate the baselinescommit. If the wrapper is missing or the project has noupdate:baselinesscript, the run stops and says the baselines have to be regenerated by hand. - Any other conflict aborts the whole run, leaving the pull-request untouched.
- 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.
- PHP 8.1 or newer, with
curl. gitonPATH.- A GitHub token, either in
git config github.tokenor in theGITHUB_TOKEN/GH_TOKENenvironment 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");
--downbaserefuses otherwise.
$ composer install
$ composer run test # PHPUnit
$ composer run phpstan # PHPStan, level max