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