Mercurial > mozilla > hg > bzgit
annotate bzgit.py @ 7:b951b70aa952 default tip
cleanin up round 1
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 17 Dec 2012 12:28:16 -0800 |
parents | 7138a453ecf7 |
children |
rev | line source |
---|---|
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 | |
6 | 13 from bzconsole.command import read_dotfile # XXX to be moved |
0 | 14 |
15 def path_segments(path): | |
16 """return path segments""" | |
17 segments = path.strip('/').split('/') | |
18 if segments == ['']: | |
19 return [] | |
20 return segments | |
21 | |
22 def add_options(parser): | |
23 """add bzgit options to an OptionParser instance""" | |
24 | |
25 | |
26 def main(args=sys.argv[1:]): | |
27 | |
28 # parse command line arguments | |
5 | 29 usage = '%prog [options] http://github.com/url/of/pull/request' |
0 | 30 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): |
31 """description formatter""" | |
32 def format_description(self, description): | |
33 if description: | |
34 return description.strip() + '\n' | |
35 else: | |
36 return '' | |
37 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) | |
38 add_options(parser) | |
39 options, args = parser.parse_args(args) | |
40 if not args: | |
41 parser.print_usage() | |
42 parser.exit() | |
43 | |
44 # parse resource | |
45 assert len(args) == 1 # for now | |
46 resource = args[0] | |
47 scheme, hostspec, path, query, anchor = urlparse.urlsplit(resource) | |
48 segments = path_segments(path) | |
49 assert len(segments) > 2 # for now | |
50 github_user = segments[0] | |
51 github_project = segments[1] | |
52 | |
53 assert len(segments) == 4 # for now | |
54 assert segments[2] == 'pull' | |
55 pull_request = int(segments[3]) | |
56 | |
57 # connect to gh | |
58 gh = Github() # TODO: auth | |
4
9fb08361ac8d
what the hell is wrong with me?
Jeff Hammel <jhammel@mozilla.com>
parents:
1
diff
changeset
|
59 pull = gh.pull_requests.get(pull_request, github_user, github_project) |
6 | 60 title = pull.title |
61 diff = pull.diff_url | |
0 | 62 |
5 | 63 # move all the things |
6 | 64 bz_options = read_dotfile() |
65 assert set(['username', 'password']).issubset(bz_options) | |
66 bz = bzconsole.BZapi(**bz_options) | |
67 | |
68 description = """From %s: | |
69 | |
70 %s | |
71 """ % (resource, title) | |
72 | |
73 # TODO: add CC of github user if possible | |
74 cc = [':wlach'] | |
75 new = bz.new('Mozbase', title=title, description=description, cc=cc) | |
76 bug = int(new.strip().rsplit('/')[-1]) | |
7 | 77 print 'https://bugzilla.mozilla.org/show_bug.cgi?id=%s' % bug |
78 attachment = bz.attach(bug, diff, reviewer=':wlach') | |
0 | 79 |
1 | 80 # comment on pull request wrt bugzilla.m.o issue location |
81 # TODO | |
82 | |
83 # close pull request | |
84 # TODO | |
85 | |
0 | 86 if __name__ == '__main__': |
87 main() | |
88 |