| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Lists branches with closed and abandoned issues.""" | |
| 7 | |
| 8 import optparse | |
| 9 import os | |
| 10 import sys | |
| 11 import urllib2 | |
| 12 | |
| 13 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| 14 DEPOT_TOOLS_DIR = os.path.dirname(BASE_DIR) | |
| 15 sys.path.insert(0, DEPOT_TOOLS_DIR) | |
| 16 | |
| 17 import git_cl | |
| 18 | |
| 19 | |
| 20 def get_branches(): | |
| 21 """Get list of all local git branches.""" | |
| 22 return [Branch(l[2:]) for l in git_cl.RunGit(["branch"]).splitlines()] | |
| 23 | |
| 24 | |
| 25 class Branch(git_cl.Changelist): | |
| 26 def __init__(self, name): | |
| 27 git_cl.Changelist.__init__(self, branchref=name) | |
| 28 self._issue_status = None | |
| 29 | |
| 30 def GetStatus(self): | |
| 31 if not self._issue_status: | |
| 32 if self.GetIssue(): | |
| 33 try: | |
| 34 issue_properties = self.RpcServer().get_issue_properties( | |
| 35 self.GetIssue(), None) | |
| 36 if issue_properties['closed']: | |
| 37 self._issue_status = 'closed' | |
| 38 else: | |
| 39 self._issue_status = 'pending' | |
| 40 except urllib2.HTTPError, e: | |
| 41 if e.code == 404: | |
| 42 self._issue_status = 'abandoned' | |
| 43 else: | |
| 44 self._issue_status = 'no-issue' | |
| 45 return self._issue_status | |
| 46 | |
| 47 | |
| 48 def main(): | |
| 49 parser = optparse.OptionParser(usage=sys.modules['__main__'].__doc__) | |
| 50 options, args = parser.parse_args() | |
| 51 if args: | |
| 52 parser.error('Unsupported arg: %s' % args) | |
| 53 | |
| 54 branches = get_branches() | |
| 55 filtered = { 'closed' : [], | |
| 56 'pending' : [], | |
| 57 'abandoned' : [], | |
| 58 'no-issue' : []} | |
| 59 | |
| 60 for branch in branches: | |
| 61 filtered[branch.GetStatus()].append(branch) | |
| 62 | |
| 63 print "# Branches with closed issues" | |
| 64 for branch in filtered['closed']: | |
| 65 print "git branch -D %s # Issue %s is closed." % (branch.GetBranch(), | |
| 66 branch.GetIssue()) | |
| 67 | |
| 68 print "\n# Pending Branches" | |
| 69 for branch in filtered['pending']: | |
| 70 print "# Branch %s - Issue %s" % (branch.GetBranch(), branch.GetIssue()) | |
| 71 | |
| 72 print "\n# Branches with abandoned issues" | |
| 73 for branch in filtered['abandoned']: | |
| 74 print "# Branch %s - was issue %s" % ( | |
| 75 branch.GetBranch(), branch.GetIssue()) | |
| 76 | |
| 77 print "\n# Branches without associated issues" | |
| 78 for branch in filtered['no-issue']: | |
| 79 print "# Branch %s" % (branch.GetBranch()) | |
| 80 | |
| 81 return 0 | |
| 82 | |
| 83 | |
| 84 if __name__ == '__main__': | |
| 85 sys.exit(main()) | |
| OLD | NEW |