comparison bzgit.py @ 0:89e0c87f09ca

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