Goal
github-backport
backports a pull request using the GitHub REST API.
See Backport to backport a pull request by simply commenting it.
Usage
; const example = async { const backportedPullRequestNumber = await ;};
github-backport
can run on Node.js and in recent browsers.
Troubleshooting
github-backport
uses debug
to log helpful information at different steps of the backport process. To enable these logs, set the DEBUG
environment variable to github-backport
.
How it Works
Backporting a pull request consists in cherry-picking all its commits to another branch.
The GitHub REST API doesn't provide direct endpoints to backport a pull request or even to cherry-pick commits.
github-backport
thus relies on github-cherry-pick
to perform all the relevant cherry-pick operations needed to perform a backport.
Step by Step
Let's say we have this Git state:
* 0d40af8 (feature) D
* 8a846f6 C
* b3c3b70 (dev) B
* 55356b7 (HEAD -> master) A
and a pull request numbered #1337
where dev
is the base branch and feature
the head branch. GitHub would say: "The user wants to merge 2 commits into dev
from feature
".
To backport #1337
to master
, github-backport
would then take the following steps:
- Find out that
#1337
is composed of8a846f6
and0d40af8
with GET /repos/:owner/:repo/pulls/:number/commits. - Create a
backport-1337-to-master
branch frommaster
with POST /repos/:owner/:repo/git/refs.* 0d40af8 (feature) D * 8a846f6 C * b3c3b70 (dev) B * 55356b7 (HEAD -> backport-1337-to-master, master) A
- Cherry-pick
8a846f6
and0d40af8
onbackport-1337-to-master
withgithub-cherry-pick
.* 1ec51e5 (HEAD -> backport-1337-to-master) D * e99200a C | * 0d40af8 (feature) D | * 8a846f6 C | * b3c3b70 (dev) B |/ * 55356b7 (master) A
- Create a pull request where
master
is the base branch andbackport-1337-to-master
the head branch with POST /repos/:owner/:repo/pulls.
Atomicity
github-backport
is atomic.
It will either successfully cherry-pick all the commits and create the backported pull request or delete the head branch created at the beginning of the backport process.
There are tests for it.