Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: hgreview.py

Issue 29338096: Issue 3783 - Redirect auth page to review after upload (Closed)
Patch Set: Try different ports Created March 11, 2016, 10:10 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import BaseHTTPServer
1 import os 2 import os
2 import re 3 import re
3 import subprocess 4 import socket
4 import sys 5 import sys
5 import urllib 6 import urllib
6 7
7 from mercurial import cmdutil, error 8 from mercurial import cmdutil, error
8 9
10 SERVER = 'https://codereview.adblockplus.org'
11 UPLOADTOOL_URL = SERVER + '/static/upload.py'
12
9 cmdtable = {} 13 cmdtable = {}
10 command = cmdutil.command(cmdtable) 14 command = cmdutil.command(cmdtable)
11 15
12 @command('review', 16 @command('review',
13 [ 17 [
14 ('i', 'issue', '', 'If given, adds a patch set to this review, otherwise cre ate a new one.', 'ISSUE'), 18 ('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'), 19 ('r', 'revision', '', 'Revision to diff against or a revision range to uploa d.', 'REV'),
16 ('c', 'change', '', 'A single revision to upload.', 'REV'), 20 ('c', 'change', '', 'A single revision to upload.', 'REV'),
17 ('t', 'title', '', 'New review subject or new patch set title.', 'TITLE'), 21 ('t', 'title', '', 'New review subject or new patch set title.', 'TITLE'),
18 ('m', 'message', '', 'New review description or new patch set message.', 'ME SSAGE'), 22 ('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'), 23 ('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'), 24 ('', '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.'), 25 ('', '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\'.'), 26 ('y', 'assume_yes', None, 'Assume that the answer to yes/no questions is \'y es\'.'),
23 ('', 'print_diffs', None, 'Print full diffs.'), 27 ('', 'print_diffs', None, 'Print full diffs.'),
24 ], '[options] [path...]') 28 ], '[options] [path...]')
25 def review(ui, repo, *paths, **opts): 29 def review(ui, repo, *paths, **opts):
26 ''' 30 '''
27 Uploads a review to https://codereview.adblockplus.org/ or updates an 31 Uploads a review to https://codereview.adblockplus.org/ or updates an
28 existing review request. This will always send mails for new reviews, when 32 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. 33 updating a review mails will only be sent if a message is given.
30 ''' 34 '''
31 args = ['--oauth2'] 35 args = ['--oauth2', '--server', SERVER]
32 if ui.debugflag: 36 if ui.debugflag:
33 args.append('--noisy') 37 args.append('--noisy')
34 elif ui.verbose: 38 elif ui.verbose:
35 args.append('--verbose') 39 args.append('--verbose')
36 elif ui.quiet: 40 elif ui.quiet:
37 args.append('--quiet') 41 args.append('--quiet')
38 42
39 if not opts.get('issue') or opts.get('message'): 43 if not opts.get('issue') or opts.get('message'):
40 args.append('--send_mail') 44 args.append('--send_mail')
41 45
(...skipping 24 matching lines...) Expand all
66 for opt in ('private', 'assume_yes', 'print_diffs'): 70 for opt in ('private', 'assume_yes', 'print_diffs'):
67 if opts.get(opt, False): 71 if opts.get(opt, False):
68 args.append('--' + opt) 72 args.append('--' + opt)
69 73
70 args.extend(paths) 74 args.extend(paths)
71 75
72 upload_path = ui.config('review', 'uploadtool_path', 76 upload_path = ui.config('review', 'uploadtool_path',
73 os.path.join('~', '.hgreview_upload.py')) 77 os.path.join('~', '.hgreview_upload.py'))
74 upload_path = os.path.expanduser(upload_path) 78 upload_path = os.path.expanduser(upload_path)
75 if not os.path.exists(upload_path): 79 if not os.path.exists(upload_path):
76 url = 'https://codereview.adblockplus.org/static/upload.py' 80 ui.status('Downloading {0} to {1}.\n'.format(UPLOADTOOL_URL, upload_path))
77 ui.status('Downloading {0} to {1}.\n'.format(url, upload_path)) 81 urllib.urlretrieve(UPLOADTOOL_URL, upload_path)
78 urllib.urlretrieve(url, upload_path)
79 82
80 subprocess.call([sys.executable, upload_path] + args) 83 # Find an available port for our local server
84 issue = None
85 class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
86 def do_GET(self):
87 self.send_response(200)
88 self.send_header('Content-type', 'text/javascript')
89 self.end_headers()
90 self.wfile.write('location.href = "{0}";'.format(SERVER + '/' + issue))
91 def log_message(*args, **kwargs):
92 pass
93 for port in range(54770, 54780):
94 try:
95 server = BaseHTTPServer.HTTPServer(('localhost', port), RequestHandler)
96 break
97 except socket.error:
98 pass
99
100 # Modify upload tool's auth response in order to redirect to the issue
101 scope = {}
102 execfile(upload_path, scope)
103 if server:
104 scope['AUTH_HANDLER_RESPONSE'] = '''\
105 <html>
106 <head>
107 <title>Authentication Status</title>
108 <script>
109 window.onload = function()
110 {
111 setInterval(function()
112 {
113 var script = document.createElement("script");
114 script.src = "http://localhost:%s/?" + (new Date().getTime());
115 document.body.appendChild(script);
116 }, 1000)
117 }
118 </script>
119 </head>
120 <body>
121 <p>
122 The authentication flow has completed. This page will redirect to your
123 review shortly.
124 </p>
125 </body>
126 </html>
127 ''' % port
128
129 # Run the upload tool
130 issue, patchset = scope['RealMain']([upload_path] + args)
131
132 # Wait for the page to check in and retrieve issue URL
133 if server:
134 server.handle_request()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld