Created
April 13, 2021 18:15
-
-
Save jdurgin/15fc85f83cd72533fdb03833cd0cdf13 to your computer and use it in GitHub Desktop.
reset_branch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this, install githubpy and use the sha1 of the current stable release branch, e.g.: