Created
June 18, 2019 06:20
-
-
Save cmouse/64dafa24a1680bd510440b471376385b to your computer and use it in GitHub Desktop.
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 | |
import requests | |
import subprocess | |
import sys | |
PRIVATE_TOKEN="<redacted>" | |
def get_branch_head(repo, branch): | |
repo = repo.replace("/","%2f") | |
r = requests.get("https://git/api/v4/projects/%s/repository/commits" % (repo,), params={"ref_name":branch}, headers = {"PRIVATE-TOKEN": PRIVATE_TOKEN}) | |
if r.status_code != 200: | |
return None | |
change = r.json()[0] | |
r = requests.get("https://git/api/v4/projects/%s/repository/commits/%s/diff" % (repo,branch), params={"sha":change["id"]}, headers = {"PRIVATE-TOKEN": PRIVATE_TOKEN}) | |
if r.status_code != 200: | |
return None | |
diffs=r.json() | |
change["files"] = [] | |
for d in diffs: | |
if d["new_path"]: | |
change["files"] = change["files"] + [d["new_path"]] | |
else: | |
change["files"] = change["files"] + [d["old_path"]] | |
return change | |
def send_change(repo, branch, change): | |
parm = ["buildbot","sendchange","--master","localhost:9999","--branch",branch,"--repository","git@git:%s.git" % (repo,), "-W", change['author_email'],"-s","git","--auth","admin:admin","-r",change["id"],"-c",change["title"]] | |
parm = parm + change["files"] | |
subprocess.call(parm, stdout=sys.stdout, stderr=sys.stderr) | |
if __name__ == '__main__': | |
change = get_branch_head(sys.argv[1], sys.argv[2]) | |
if change: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment