| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 import os | |
| 2 import re | |
| 3 import subprocess | |
| 4 import sys | |
| 5 import urllib | |
| 6 | |
| 7 from mercurial import cmdutil, error | |
| 8 | |
| 9 cmdtable = {} | |
| 10 command = cmdutil.command(cmdtable) | |
| 11 | |
| 12 @command('review', | |
|
Sebastian Noack
2016/03/10 12:31:05
Note that cmdutil isn't a standard library. IMO th
Wladimir Palant
2016/03/10 12:36:36
No, it isn't a standard library but it is document
Sebastian Noack
2016/03/10 12:44:28
I just realized that this is a Mercurial extension
| |
| 13 [ | |
| 14 ('i', 'issue', '', 'If given, adds a patch set to this review, otherwise cre ate a new one.', 'ISSUE'), | |
| 15 ('r', 'revision', '', 'Revision to diff against or a revision range to uploa d.', 'REV'), | |
| 16 ('c', 'change', '', 'A single revision to upload.', 'REV'), | |
| 17 ('t', 'title', '', 'New review subject or new patch set title.', 'TITLE'), | |
| 18 ('m', 'message', '', 'New review description or new patch set message.', 'ME SSAGE'), | |
| 19 ('w', 'reviewers', '', 'Add reviewers (comma separated email addresses or @a dblockplus.org user names).', 'REVIEWERS'), | |
| 20 ('', 'cc', '', 'Add CC (comma separated email addresses or @adblockplus.org user names).', 'CC'), | |
| 21 ('', 'private', None, 'Make the review restricted to reviewers and those CCe d.'), | |
| 22 ('y', 'assume_yes', None, 'Assume that the answer to yes/no questions is \'y es\'.'), | |
| 23 ('', 'print_diffs', None, 'Print full diffs.'), | |
| 24 ], '[options] [path...]') | |
| 25 def review(ui, repo, *paths, **opts): | |
| 26 ''' | |
| 27 Uploads a review to https://codereview.adblockplus.org/ or updates an | |
| 28 existing review request. This will always send mails for new reviews, when | |
| 29 updating a review mails will only be sent if a message is given. | |
| 30 ''' | |
| 31 args = ['--oauth2'] | |
| 32 if ui.debugflag: | |
| 33 args.append('--noisy') | |
| 34 elif ui.verbose: | |
| 35 args.append('--verbose') | |
| 36 elif ui.quiet: | |
| 37 args.append('--quiet') | |
| 38 | |
| 39 if opts.get('issue') or opts.get('message'): | |
| 40 args.append('--send_mail') | |
| 41 | |
| 42 if opts.get('revision') and opts.get('change'): | |
| 43 raise error.Abort('Ambiguous revision range, only one of --revision and --ch ange can be specified.') | |
| 44 if opts.get('change'): | |
| 45 args.extend(['--rev', '{0}^:{0}'.format(opts['change'])]) | |
| 46 elif opts.get('revision'): | |
| 47 args.extend(['--rev', opts['revision']]) | |
| 48 else: | |
| 49 raise error.Abort('What should be reviewed? Either --revision or --change is required.') | |
| 50 | |
| 51 if not opts.get('title') and not opts.get('issue') and opts.get('change'): | |
| 52 opts['title'] = repo[opts['change']].description() | |
| 53 | |
| 54 if not opts.get('issue') and not opts.get('reviewers'): | |
| 55 raise error.Abort('Please specify --reviewers for your new review.') | |
| 56 for opt in ('reviewers', 'cc'): | |
| 57 if opts.get(opt): | |
| 58 users = [u if '@' in u else u + '@adblockplus.org' | |
| 59 for u in re.split(r'\s*,\s*', opts[opt])] | |
| 60 opts[opt] = ','.join(users) | |
| 61 | |
| 62 for opt in ('issue', 'title', 'message', 'reviewers', 'cc'): | |
| 63 if opts.get(opt, ''): | |
| 64 args.extend(['--' + opt, opts[opt]]) | |
| 65 | |
| 66 for opt in ('private', 'assume_yes', 'print_diffs'): | |
| 67 if opts.get(opt, False): | |
| 68 args.append('--' + opt) | |
| 69 | |
| 70 args += paths | |
|
Sebastian Noack
2016/03/10 12:31:05
Nit: Why not modifying args inline as above using
Wladimir Palant
2016/03/10 12:36:36
Done.
| |
| 71 | |
| 72 upload_path = ui.config('review', 'uploadtool_path', | |
| 73 os.path.join('~', '.hgreview_upload.py')) | |
| 74 upload_path = os.path.expanduser(upload_path) | |
| 75 if not os.path.exists(upload_path): | |
| 76 url = 'https://codereview.adblockplus.org/static/upload.py' | |
| 77 ui.status('Downloading {0} to {1}.\n'.format(url, upload_path)) | |
| 78 urllib.urlretrieve(url, upload_path) | |
| 79 | |
| 80 subprocess.call([sys.executable, upload_path] + args) | |
| OLD | NEW |