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 """A tool for listing branches with closed and abandoned issues.""" |
| 7 |
| 8 import os |
| 9 import sys |
| 10 import urllib2 |
| 11 |
| 12 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 13 DEPOT_TOOLS_DIR = os.path.dirname(BASE_DIR) |
| 14 sys.path.insert(0, DEPOT_TOOLS_DIR) |
| 15 |
| 16 import git_cl |
| 17 |
| 18 |
| 19 def get_branches(): |
| 20 """Get list of all local git branches.""" |
| 21 return [Branch(l[2:]) for l in git_cl.RunGit(["branch"]).splitlines()] |
| 22 |
| 23 |
| 24 class Branch(git_cl.Changelist): |
| 25 def __init__(self, name): |
| 26 git_cl.Changelist.__init__(self, branchref=name) |
| 27 self._issue_status = None |
| 28 |
| 29 def GetStatus(self): |
| 30 if not self._issue_status: |
| 31 if self.GetIssue(): |
| 32 try: |
| 33 issue_properties = self.RpcServer().get_issue_properties( |
| 34 self.GetIssue(), None) |
| 35 if issue_properties['closed']: |
| 36 self._issue_status = 'closed' |
| 37 else: |
| 38 self._issue_status = 'pending' |
| 39 except urllib2.HTTPError, e: |
| 40 if e.code == 404: |
| 41 self._issue_status = 'abandoned' |
| 42 else: |
| 43 self._issue_status = 'no-issue' |
| 44 return self._issue_status |
| 45 |
| 46 |
| 47 def main(argv): |
| 48 branches = get_branches() |
| 49 filtered = { 'closed' : [], |
| 50 'pending' : [], |
| 51 'abandoned' : [], |
| 52 'no-issue' : []} |
| 53 |
| 54 for branch in branches: |
| 55 filtered[branch.GetStatus()].append(branch) |
| 56 |
| 57 print "# Branches with closed issues" |
| 58 for branch in filtered['closed']: |
| 59 print "git branch -D %s # Issue %s is closed." % (branch.GetBranch(), |
| 60 branch.GetIssue()) |
| 61 |
| 62 print "\n# Pending Branches" |
| 63 for branch in filtered['pending']: |
| 64 print "# Branch %s - Issue %s" % (branch.GetBranch(), branch.GetIssue()) |
| 65 |
| 66 print "\n# Branches with abandoned issues" |
| 67 for branch in filtered['abandoned']: |
| 68 print "# Branch %s - was issue %s" % ( |
| 69 branch.GetBranch(), branch.GetIssue()) |
| 70 |
| 71 print "\n# Branches without associated issues" |
| 72 for branch in filtered['no-issue']: |
| 73 print "# Branch %s" % (branch.GetBranch()) |
| 74 |
| 75 return 0 |
| 76 |
| 77 |
| 78 if __name__ == '__main__': |
| 79 sys.exit(main(sys.argv[1:])) |
OLD | NEW |