Skip to content

Instantly share code, notes, and snippets.

@jdurgin
Created April 13, 2021 18:15
Show Gist options
  • Save jdurgin/15fc85f83cd72533fdb03833cd0cdf13 to your computer and use it in GitHub Desktop.
Save jdurgin/15fc85f83cd72533fdb03833cd0cdf13 to your computer and use it in GitHub Desktop.
reset_branch.py
#!/usr/bin/env python
# do a `pip install githubpy` before running the script
import os
import github
import argparse
import sys
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("target_sha", metavar="target_sha",
help="sha1 of the branch to update to")
parser.add_argument("base_branch", metavar="base_branch",
help="name of the branch to retarget")
token = os.getenv("GITHUB_ACCESS_TOKEN")
if not token:
print('No GITHUB_ACCESS_TOKEN set')
sys.exit(1)
gh = github.GitHub(access_token=token)
args = parser.parse_args()
print(args.target_sha)
print(args.base_branch)
prs = gh.repos("ceph")("ceph").pulls.get(state="open",
base=args.base_branch)
for pr in prs:
if pr['base']['sha'] != args.target_sha:
print("Turning pr off & on again...", pr['number'])
gh.repos("ceph")("ceph").pulls(pr['number']).patch(base=args.base_branch + "-saved")
gh.repos("ceph")("ceph").pulls(pr['number']).patch(base=args.base_branch)
@jdurgin
Copy link
Author

jdurgin commented May 14, 2021

To use this, install githubpy and use the sha1 of the current stable release branch, e.g.:

virtualenv venv
./venv/bin/pip install githubpy
./venvbin/python reset_branch.py 92c182eab2abd731b513f46b416f657a9cca7426 nautilus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment