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