Created
January 12, 2012 01:34
-
-
Save rhelmer/1597922 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # | |
| # gitzilla | |
| # | |
| # give me a list of git log messages and a target milestone, and I'll show you | |
| # the difference. | |
| # | |
| # Example: ./gitzilla.py -t 2.4 v2.3.5..master | |
| import re | |
| import sys | |
| import optparse | |
| import urllib2 | |
| import csv | |
| import subprocess | |
| bug_pattern = re.compile(r'bug\s?\d+', flags=re.IGNORECASE) | |
| bz_baseurl = 'https://bugzilla.mozilla.org/buglist.cgi?query_format=advanced&target_milestone=%s&product=Socorro&ctype=csv' | |
| def compare(git_bug_nums, target_milestone): | |
| bz_url = bz_baseurl % target_milestone | |
| bug_reports = csv.DictReader(urllib2.urlopen(bz_url)) | |
| bz_bug_nums = set(x['bug_id'] for x in bug_reports) | |
| for num in (git_bug_nums & bz_bug_nums): | |
| print 'OK %s in git is in target milestone %s' % (num, target_milestone) | |
| for num in (bz_bug_nums - git_bug_nums): | |
| print 'WARNING %s is in target milestone %s but not in git' % (num, target_milestone) | |
| for num in (git_bug_nums - bz_bug_nums): | |
| print 'ERROR %s is in git but not in target milestone %s' % (num, target_milestone) | |
| def main(target_milestone, args): | |
| git_log_args = ['git', 'log', '--oneline', ' '.join(args)] | |
| print 'Running: %s' % ' '.join(git_log_args) | |
| process = subprocess.Popen(git_log_args, stdout=subprocess.PIPE) | |
| process.wait() | |
| if process.returncode != 0: | |
| print 'git exited non-zero: %s' % process.returncode | |
| sys.exit(1) | |
| git_bug_nums = set() | |
| for line in process.stdout: | |
| commit_msg = line.strip() | |
| bug_msg = bug_pattern.findall(commit_msg) | |
| if bug_msg is None: | |
| print 'ERROR missing bug message in git log: %s' % commit_msg | |
| else: | |
| git_bug_nums = git_bug_nums.union( | |
| set(x.lower().split('bug')[1].strip() for x in bug_msg)) | |
| compare(git_bug_nums, target_milestone) | |
| if __name__ == '__main__': | |
| usage = ''' | |
| %prog [options] args_for_git_log | |
| Example: ./gitzilla.py -t 2.4 v2.3.5..master | |
| ''' | |
| parser = optparse.OptionParser(usage) | |
| parser.add_option('-t', '--target_milestone', dest='target_milestone', | |
| type='string', help='target_milestone to check on bz') | |
| (options, args) = parser.parse_args() | |
| target_milestone = options.target_milestone | |
| if target_milestone is None: | |
| parser.print_help() | |
| sys.exit(1) | |
| main(target_milestone, args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment