OLD | NEW |
1 import BaseHTTPServer | 1 import BaseHTTPServer |
2 import os | 2 import os |
3 import re | 3 import re |
4 import socket | 4 import socket |
5 import sys | 5 import sys |
6 import urllib | 6 import urllib |
7 | 7 |
8 from mercurial import cmdutil, error | 8 from mercurial import cmdutil, error |
9 | 9 |
10 SERVER = 'https://codereview.adblockplus.org' | 10 SERVER = 'https://codereview.adblockplus.org' |
11 UPLOADTOOL_URL = SERVER + '/static/upload.py' | 11 UPLOADTOOL_URL = SERVER + '/static/upload.py' |
12 | 12 |
13 cmdtable = {} | 13 cmdtable = {} |
14 command = cmdutil.command(cmdtable) | 14 command = cmdutil.command(cmdtable) |
15 | 15 |
16 | 16 |
17 @command('review', | 17 @command('review', |
18 [ | 18 [ |
19 ('i', 'issue', '', 'If given, adds a patch set to this review, othe
rwise create a new one.', 'ISSUE'), | 19 ('i', 'issue', '', 'If given, adds a patch set to this review, othe
rwise create a new one.', 'ISSUE'), |
20 ('r', 'revision', '', 'Revision to diff against or a revision range
to upload.', 'REV'), | 20 ('r', 'revision', '', 'Revision to diff against or a revision range
to upload.', 'REV'), |
21 ('c', 'change', '', 'A single revision to upload.', 'REV'), | 21 ('c', 'change', '', 'A single revision to upload.', 'REV'), |
22 ('t', 'title', '', 'New review subject or new patch set title.', 'T
ITLE'), | 22 ('t', 'title', '', 'New review subject or new patch set title.', 'T
ITLE'), |
23 ('m', 'message', '', 'New review description or new patch set messa
ge.', 'MESSAGE'), | 23 ('m', 'message', '', 'New review description or new patch set messa
ge.', 'MESSAGE'), |
24 ('w', 'reviewers', '', 'Add reviewers (comma separated email addres
ses or @adblockplus.org user names).', 'REVIEWERS'), | 24 ('w', 'reviewers', '', 'Add reviewers (comma separated email addres
ses or @adblockplus.org user names).', 'REVIEWERS'), |
25 ('', 'cc', '', 'Add CC (comma separated email addresses or @adblock
plus.org user names).', 'CC'), | 25 ('', 'cc', '', 'Add CC (comma separated email addresses or @adblock
plus.org user names).', 'CC'), |
26 ('', 'private', None, 'Make the review restricted to reviewers and
those CCed.'), | 26 ('', 'private', None, 'Make the review restricted to reviewers and
those CCed.'), |
27 ('y', 'assume_yes', None, 'Assume that the answer to yes/no questio
ns is \'yes\'.'), | 27 ('y', 'assume_yes', None, 'Assume that the answer to yes/no questio
ns is \'yes\'.'), |
28 ('', 'print_diffs', None, 'Print full diffs.'), | 28 ('', 'print_diffs', None, 'Print full diffs.'), |
| 29 ('', 'no_mail', None, 'Don\'t send an email after uploading.'), |
29 ], '[options] [path...]') | 30 ], '[options] [path...]') |
30 def review(ui, repo, *paths, **opts): | 31 def review(ui, repo, *paths, **opts): |
31 ''' | 32 ''' |
32 Uploads a review to https://codereview.adblockplus.org/ or updates an | 33 Uploads a review to https://codereview.adblockplus.org/ or updates an |
33 existing review request. This will always send mails for new reviews, when | 34 existing review request. This will always send mails for new reviews, when |
34 updating a review mails will only be sent if a message is given. | 35 updating a review mails will only be sent if a message is given. |
35 ''' | 36 ''' |
36 args = ['--oauth2', '--server', SERVER] | 37 args = ['--oauth2', '--server', SERVER] |
37 if ui.debugflag: | 38 if ui.debugflag: |
38 args.append('--noisy') | 39 args.append('--noisy') |
39 elif ui.verbose: | 40 elif ui.verbose: |
40 args.append('--verbose') | 41 args.append('--verbose') |
41 elif ui.quiet: | 42 elif ui.quiet: |
42 args.append('--quiet') | 43 args.append('--quiet') |
43 | 44 |
44 if not opts.get('issue') or opts.get('message'): | 45 if (not opts.get('no_mail') and |
| 46 (not opts.get('issue') or opts.get('message'))): |
45 args.append('--send_mail') | 47 args.append('--send_mail') |
46 | 48 |
47 if opts.get('revision') and opts.get('change'): | 49 if opts.get('revision') and opts.get('change'): |
48 raise error.Abort('Ambiguous revision range, only one of --revision and
--change can be specified.') | 50 raise error.Abort('Ambiguous revision range, only one of --revision and
--change can be specified.') |
49 if opts.get('change'): | 51 if opts.get('change'): |
50 rev = repo[opts['change']] | 52 rev = repo[opts['change']] |
51 args.extend(['--rev', '{}:{}'.format(rev.parents()[0], rev)]) | 53 args.extend(['--rev', '{}:{}'.format(rev.parents()[0], rev)]) |
52 elif opts.get('revision'): | 54 elif opts.get('revision'): |
53 args.extend(['--rev', opts['revision']]) | 55 args.extend(['--rev', opts['revision']]) |
54 else: | 56 else: |
(...skipping 14 matching lines...) Expand all Loading... |
69 path = (ui.config('paths', 'default-push') | 71 path = (ui.config('paths', 'default-push') |
70 or ui.config('paths', 'default') | 72 or ui.config('paths', 'default') |
71 or '') | 73 or '') |
72 match = re.search(r'^(?:https://|ssh://hg@)(.*)', path) | 74 match = re.search(r'^(?:https://|ssh://hg@)(.*)', path) |
73 if match: | 75 if match: |
74 opts['base_url'] = 'https://' + match.group(1) | 76 opts['base_url'] = 'https://' + match.group(1) |
75 | 77 |
76 # Make sure there is at least one reviewer | 78 # Make sure there is at least one reviewer |
77 if not opts.get('reviewers'): | 79 if not opts.get('reviewers'): |
78 opts['reviewers'] = ui.prompt('Reviewers (comma-separated): ', '') | 80 opts['reviewers'] = ui.prompt('Reviewers (comma-separated): ', '') |
79 if not opts['reviewers'].strip(): | 81 if not opts.get('no_mail') and not opts['reviewers'].strip(): |
80 raise error.Abort('No reviewers given.') | 82 raise error.Abort('No reviewers given.') |
81 | 83 |
82 for opt in ('reviewers', 'cc'): | 84 for opt in ('reviewers', 'cc'): |
83 if opts.get(opt): | 85 if opts.get(opt): |
84 users = [u if '@' in u else u + '@adblockplus.org' | 86 users = [u if '@' in u else u + '@adblockplus.org' |
85 for u in re.split(r'\s*,\s*', opts[opt])] | 87 for u in re.split(r'\s*,\s*', opts[opt])] |
86 opts[opt] = ','.join(users) | 88 opts[opt] = ','.join(users) |
87 | 89 |
88 for opt in ('issue', 'title', 'message', 'reviewers', 'cc', 'base_url'): | 90 for opt in ('issue', 'title', 'message', 'reviewers', 'cc', 'base_url'): |
89 if opts.get(opt, ''): | 91 if opts.get(opt, ''): |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 </body> | 151 </body> |
150 </html> | 152 </html> |
151 ''' % port | 153 ''' % port |
152 | 154 |
153 # Run the upload tool | 155 # Run the upload tool |
154 issue, patchset = scope['RealMain']([upload_path] + args) | 156 issue, patchset = scope['RealMain']([upload_path] + args) |
155 | 157 |
156 # Wait for the page to check in and retrieve issue URL | 158 # Wait for the page to check in and retrieve issue URL |
157 if server: | 159 if server: |
158 server.handle_request() | 160 server.handle_request() |
OLD | NEW |