Skip to content

Instantly share code, notes, and snippets.

@cmouse
Created August 27, 2017 12:25
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 cmouse/52e1b92475f35162a93f08f5ef3291c8 to your computer and use it in GitHub Desktop.
Save cmouse/52e1b92475f35162a93f08f5ef3291c8 to your computer and use it in GitHub Desktop.
Sending a change to buildbot
#!/usr/bin/env python
import requests
import subprocess
import sys
PRIVATE_TOKEN="<removed>"
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:
send_change(sys.argv[1],sys.argv[2],change)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment