Created
October 20, 2014 04:31
-
-
Save anguslees/1e567b5fee3f3e851f69 to your computer and use it in GitHub Desktop.
Simple script to check gerrit status of local git branches
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/python | |
import re | |
import requests | |
import sys | |
import git | |
from pygerrit.rest import GerritRestAPI | |
def main(args): | |
repo = git.Repo() | |
gerrit = GerritRestAPI(url='https://review.openstack.org/') | |
for branch in repo.branches: | |
# Change-Id: I1a51118d951d774bdf78d3944e801e2efc817646 | |
msg = branch.commit.message | |
m = re.search('^Change-Id: *(I[0-9a-f]+)', msg, flags=re.MULTILINE) | |
if m: | |
change_id = m.group(1) | |
# GET /changes/%(change_id)s => status | |
try: | |
change = gerrit.get('/changes/%s' % change_id) | |
status = change['status'] | |
except requests.exceptions.HTTPError as e: | |
status = e | |
else: | |
status = '*Unpushed*' | |
print('%s =>\t%s' % (branch.name, status)) | |
if __name__ == '__main__': | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment