0
|
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
|
1
|
60 # move all the things [TODO]
|
0
|
61 bz = bzconsole
|
|
62
|
1
|
63 # comment on pull request wrt bugzilla.m.o issue location
|
|
64 # TODO
|
|
65
|
|
66 # close pull request
|
|
67 # TODO
|
|
68
|
0
|
69 if __name__ == '__main__':
|
|
70 main()
|
|
71
|