Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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