Skip to content

Instantly share code, notes, and snippets.

@anguslees
Created October 20, 2014 04:31
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 anguslees/1e567b5fee3f3e851f69 to your computer and use it in GitHub Desktop.
Save anguslees/1e567b5fee3f3e851f69 to your computer and use it in GitHub Desktop.
Simple script to check gerrit status of local git branches
#!/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