Automate backport PR
Requires installation of PyGithub
pip install pygithub
Token is provided from Github. Scope with repo/public_repo
is required.
Script requires authentication to github.com via SSH. Directions here.
usage: backport.py [-h] --repo {chainer,cupy} --token TOKEN --pr PR
[--branch BRANCH] [--debug] [--continue]
[--abort-before-push]
optional arguments:
-h, --help show this help message and exit
--repo {chainer,cupy}
chainer or cupy
--token TOKEN GitHub access token.
--pr PR The original PR number to be backported.
--branch BRANCH Target branch to make a backport
--debug
--continue Continues the process suspended by conflict situation.
Run from the working tree directory.
--abort-before-push Abort the procedure before making an push. Useful if
you want to make some modification to the backport
branch. Use --continue to make an actual push after
making modification.
$ python backport.py --repo chainer --token abcdefghijklmn --pr 1234
Basically it follows this procedure:
- Clone the target branch (e.g.
v5
) of the target repository (e.g.chainer/chainer
) to a temporary directory. - Create a local temporary branch and cherry-pick the merge commit of the original PR.
- Push it to the user repository.
- Make a backport PR.
If conflict has occurred during backporting, you have to resolve conflict yourself,
and rerun the command with additional --continue
option.
$ python backport.py --repo chainer --token abcdefghijklmn --pr 1234
...
Cherry-pick failed.
Working tree is saved at: /tmp/bp-FktJXG5R
Go to the working tree, resolve the conflict and type `git cherry-pick --continue`,
then run this script with --continue option.
$ cd /tmp/bp-FktJXG5R
$ <resolve conflict>
$ git cherry-pick --continue
$ python backport.py --repo chainer --token abcdefghijklmn --pr 1234 --continue