annotate bzgit.py @ 1:240f98f19ee3

notes to self
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 12 Dec 2012 10:05:57 -0800
parents 89e0c87f09ca
children 9fb08361ac8d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 """
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 bzgit
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 github <-> bugzilla.m.o bridge
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 """
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 import bzconsole
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 import optparse
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 import sys
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 import urlparse
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 from pygithub3 import Github
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 def path_segments(path):
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 """return path segments"""
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 segments = path.strip('/').split('/')
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 if segments == ['']:
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 return []
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 return segments
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 def add_options(parser):
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 """add bzgit options to an OptionParser instance"""
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 def main(args=sys.argv[1:]):
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 # parse command line arguments
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 usage = '%prog [options] ...'
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 """description formatter"""
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 def format_description(self, description):
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 if description:
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 return description.strip() + '\n'
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 else:
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 return ''
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 add_options(parser)
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 options, args = parser.parse_args(args)
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 if not args:
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 parser.print_usage()
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 parser.exit()
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 # parse resource
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 assert len(args) == 1 # for now
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 resource = args[0]
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 scheme, hostspec, path, query, anchor = urlparse.urlsplit(resource)
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 segments = path_segments(path)
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48 assert len(segments) > 2 # for now
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 github_user = segments[0]
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 github_project = segments[1]
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 assert len(segments) == 4 # for now
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53 assert segments[2] == 'pull'
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 pull_request = int(segments[3])
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 # connect to gh
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 gh = Github() # TODO: auth
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58 pull = gh.pull_requests.get(44, github_user, github_project)
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59
1
240f98f19ee3 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
60 # move all the things [TODO]
0
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61 bz = bzconsole
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62
1
240f98f19ee3 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
63 # comment on pull request wrt bugzilla.m.o issue location
240f98f19ee3 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
64 # TODO
240f98f19ee3 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
65
240f98f19ee3 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
66 # close pull request
240f98f19ee3 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
67 # TODO
240f98f19ee3 notes to self
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
68
0
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69 if __name__ == '__main__':
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70 main()
89e0c87f09ca initial (STUB) commit
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
71