Skip to content

Instantly share code, notes, and snippets.

@goneri
Created March 2, 2020 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goneri/09fbfd6d3464bf1772772172064006cb to your computer and use it in GitHub Desktop.
Save goneri/09fbfd6d3464bf1772772172064006cb to your computer and use it in GitHub Desktop.
Automagically pick ansible/ansible PR
#!/usr/bin/python
import re
import urllib.request
import argparse
import subprocess
parser = argparse.ArgumentParser()
parser.add_argument("pr_id", type=int)
args = parser.parse_args()
url = "https://patch-diff.githubusercontent.com/raw/ansible/ansible/pull/{pr_id}.patch".format(
pr_id=args.pr_id
)
r = urllib.request.urlopen(url)
content = (
r.read()
.decode()
.replace("lib/ansible/modules/cloud/vmware/", "plugins/modules/")
.replace("test/integration/targets", "tests/integration/targets")
.replace("lib/ansible/plugins/inventory", "plugins/inventory")
)
subprocess.call(["git", "am", "--abort"])
subprocess.call(
[
"git",
"checkout",
"-B",
"migrated_pr{pr_id}".format(pr_id=args.pr_id),
"origin/master",
]
)
for patch in content.split("\nFrom "):
with open("/tmp/my.patch", "w") as fd:
fd.write("From ")
fd.write(patch)
subprocess.check_call(["git", "am", "/tmp/my.patch"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment