2015-10-04 18:56:26 +02:00
|
|
|
#!/usr/bin/env python2.7
|
2013-08-14 21:05:02 +02:00
|
|
|
# encoding: utf-8
|
2012-10-30 18:38:08 +01:00
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Ksplice, Inc.
|
2015-09-20 09:10:54 +02:00
|
|
|
# Copyright (C) 2012-2015 Zulip, Inc.
|
2012-10-30 18:38:08 +01:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
# Author: Greg Price <price@ksplice.com>
|
|
|
|
|
2013-08-14 21:05:02 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2012-10-30 18:38:08 +01:00
|
|
|
## CC_EMAIL: All review requests will be CC'd here.
|
2015-09-20 09:10:54 +02:00
|
|
|
CC_EMAIL = 'listname@example.com'
|
2012-10-30 18:38:08 +01:00
|
|
|
|
|
|
|
## DOMAIN: Reviewers without an '@' will be assumed to be localparts here.
|
2015-09-20 09:10:54 +02:00
|
|
|
DOMAIN = 'example.com'
|
2012-10-30 18:38:08 +01:00
|
|
|
|
2013-05-30 22:17:01 +02:00
|
|
|
## TEST_SCRIPT: Test file to run; path relative to root of the working tree, or absolute.
|
|
|
|
TEST_SCRIPT = "tools/test-all"
|
|
|
|
|
2012-10-30 18:38:08 +01:00
|
|
|
##### END CONFIG #####
|
|
|
|
## But you might want to change behavior below.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import optparse
|
|
|
|
import posixpath
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
import git
|
|
|
|
import shlex
|
|
|
|
import codecs
|
2013-05-30 22:17:01 +02:00
|
|
|
import fcntl
|
2012-10-30 18:38:08 +01:00
|
|
|
from StringIO import StringIO
|
|
|
|
from email.message import Message
|
|
|
|
from email.header import Header
|
2013-05-30 22:17:01 +02:00
|
|
|
from shutil import rmtree, copyfile, copytree
|
|
|
|
from time import sleep
|
|
|
|
from signal import SIGINT, SIGTERM
|
|
|
|
from errno import EAGAIN
|
2012-10-30 18:38:08 +01:00
|
|
|
|
2013-10-07 21:23:26 +02:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../api'))
|
|
|
|
import zulip
|
|
|
|
|
2012-10-30 18:38:08 +01:00
|
|
|
usage = """
|
2013-07-03 17:25:15 +02:00
|
|
|
%%prog -r <reviewer> [-r <another-reviewer>] [-T <alt tmp dir>] [-s <summary>] [-m <message>] [options] {<since>|<revision-range>}
|
2012-10-30 18:38:08 +01:00
|
|
|
|
2013-07-03 17:25:15 +02:00
|
|
|
Send a patch series for review, after optionally successfully running test-all (if you specify '-T').
|
|
|
|
If requested, tests will run in /tmp, and thus you can continue to work in your own working tree.
|
2013-05-30 22:17:01 +02:00
|
|
|
Sends mail to the reviewer, CC %s, identifying the commits to be reviewed.
|
2012-10-30 18:38:08 +01:00
|
|
|
|
|
|
|
Name a range of commits, or name a single commit (e.g., 'HEAD^' or
|
|
|
|
'origin/master') to identify all commits on HEAD since that commit.
|
2012-11-02 20:44:14 +01:00
|
|
|
|
|
|
|
If you set REVIEW_USE_SENDMAIL to be nonempty, /usr/bin/sendmail will
|
|
|
|
be used to mail the review request. Otherwise, msmtp will be used by
|
|
|
|
default.
|
2012-10-30 18:38:08 +01:00
|
|
|
""".strip() % CC_EMAIL
|
|
|
|
|
|
|
|
|
|
|
|
def parse_options(args):
|
2013-08-14 21:05:02 +02:00
|
|
|
parser = optparse.OptionParser(usage)
|
2012-10-30 18:38:08 +01:00
|
|
|
parser.add_option('--first-parent', action='store_true', dest='first_parent',
|
|
|
|
help='follow first parents only')
|
2013-08-14 21:05:02 +02:00
|
|
|
parser.add_option('-r', '--reviewer', type='string', dest='reviewers', action="append",
|
2012-10-30 18:38:08 +01:00
|
|
|
help='the person you are asking to do the review')
|
|
|
|
parser.add_option('--stdout', action='store_true', dest='stdout',
|
|
|
|
help='send to standard output rather than send mail')
|
|
|
|
parser.add_option('--format', type='choice', dest='format',
|
|
|
|
choices=['oneline', 'message', 'patch'],
|
|
|
|
help="'patch' (default for one commit), 'message' (default for more), or 'oneline'")
|
2013-08-14 21:05:02 +02:00
|
|
|
parser.add_option('-s', '--summary', type='string', dest='summary',
|
2012-10-30 18:38:08 +01:00
|
|
|
help='summary for subject line')
|
2013-08-14 21:05:02 +02:00
|
|
|
parser.add_option('-m', '--message', type='string', dest='message',
|
2012-10-30 18:38:08 +01:00
|
|
|
help='message for body of email')
|
2013-08-14 21:05:02 +02:00
|
|
|
parser.add_option('-t', '--testing', type='string', dest='testing',
|
2012-10-30 18:38:08 +01:00
|
|
|
help='extent and methods of testing employed')
|
|
|
|
parser.add_option('-e', '--edit', action='store_true', dest='edit',
|
|
|
|
help='spawn $EDITOR and edit review request')
|
2013-05-30 22:17:01 +02:00
|
|
|
parser.add_option('-T', '--run-tests', action='store_true', dest='run_tests',
|
|
|
|
help='run test before sending the review')
|
2013-08-14 21:05:02 +02:00
|
|
|
parser.add_option('--testing-tmp-directory', type='string', dest="tmp_dir", default="/tmp",
|
2013-05-30 22:17:01 +02:00
|
|
|
help="specify different temp directory for testing (default /tmp)")
|
|
|
|
|
2012-10-30 18:38:08 +01:00
|
|
|
options, args = parser.parse_args(args)
|
|
|
|
if not options.reviewers:
|
2012-10-30 18:39:37 +01:00
|
|
|
parser.error('reviewer required')
|
2012-10-30 18:38:08 +01:00
|
|
|
reviewers_fixed = []
|
|
|
|
for reviewer in options.reviewers:
|
|
|
|
if '@' not in reviewer:
|
|
|
|
reviewers_fixed.append(reviewer + '@' + DOMAIN)
|
|
|
|
else:
|
|
|
|
reviewers_fixed.append(reviewer)
|
|
|
|
options.reviewers = reviewers_fixed
|
|
|
|
if len(args) < 2:
|
|
|
|
parser.error('must specify revision(s) to be reviewed')
|
|
|
|
return options, args
|
|
|
|
|
|
|
|
|
|
|
|
def get_default_remote(repo):
|
|
|
|
try:
|
|
|
|
return repo.git.config('--get', 'remotes.default')
|
2012-10-30 18:56:52 +01:00
|
|
|
except git.exc.GitCommandError:
|
2012-10-30 18:38:08 +01:00
|
|
|
try:
|
|
|
|
branch = repo.active_branch
|
2013-01-30 17:09:38 +01:00
|
|
|
except TypeError:
|
|
|
|
return 'origin'
|
|
|
|
try:
|
2013-08-14 21:05:02 +02:00
|
|
|
return repo.git.config('--get', ('branch.%s.remote' % unicode(str(branch), "utf-8")).encode("utf-8"))
|
2012-10-30 18:56:52 +01:00
|
|
|
except git.exc.GitCommandError:
|
2012-10-30 18:38:08 +01:00
|
|
|
return 'origin'
|
|
|
|
|
|
|
|
|
|
|
|
def get_reponame(repo):
|
|
|
|
remote = get_default_remote(repo)
|
|
|
|
|
|
|
|
try:
|
|
|
|
url = repo.git.config('--get', 'remote.%s.url' % remote)
|
2012-10-30 18:56:52 +01:00
|
|
|
except git.exc.GitCommandError:
|
2012-10-30 18:38:08 +01:00
|
|
|
url = repo.wd
|
|
|
|
|
|
|
|
name = posixpath.basename(posixpath.normpath(url.split(':', 1)[-1]))
|
|
|
|
if name.endswith('.git'):
|
|
|
|
name = name[:-len('.git')]
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
|
|
|
def parse_revs(repo, opts, args):
|
|
|
|
args = repo.git.rev_parse(*args).splitlines()
|
|
|
|
if len(args) == 1:
|
|
|
|
args = ['^' + args[0].lstrip('^'), 'HEAD']
|
|
|
|
if opts.first_parent:
|
|
|
|
args[:0] = ['--first-parent']
|
|
|
|
return [repo.commit(c) for c in repo.git.rev_list('--reverse', *args).split()]
|
|
|
|
|
|
|
|
|
2012-11-05 19:30:07 +01:00
|
|
|
def get_current_user(repo):
|
2012-10-30 18:38:08 +01:00
|
|
|
ident = unicode(repo.git.var('GIT_AUTHOR_IDENT'), 'utf-8', 'replace')
|
2012-11-05 19:30:07 +01:00
|
|
|
return ident[:ident.rindex('>') + 1]
|
|
|
|
|
2013-01-30 16:53:18 +01:00
|
|
|
def get_current_user_email(repo):
|
|
|
|
me = get_current_user(repo)
|
|
|
|
return me[me.index("<") + 1:me.index('>')]
|
|
|
|
|
2012-11-05 19:30:07 +01:00
|
|
|
def make_header(repo, opts, revs):
|
|
|
|
me = get_current_user(repo)
|
2012-10-30 18:38:08 +01:00
|
|
|
reponame = get_reponame(repo)
|
|
|
|
|
|
|
|
remote = get_default_remote(repo)
|
2012-10-30 18:56:52 +01:00
|
|
|
(sha, name) = repo.git.name_rev(revs[-1].hexsha,
|
2012-10-30 18:38:08 +01:00
|
|
|
refs='refs/remotes/%s/*' % (remote,),
|
|
|
|
always=True).split()
|
2013-08-14 21:05:02 +02:00
|
|
|
name = unicode(name, "utf-8")
|
2012-10-30 18:38:08 +01:00
|
|
|
prefix = 'remotes/' + remote + "/"
|
|
|
|
if name.startswith(prefix):
|
|
|
|
name = name[len(prefix):]
|
2012-10-30 18:56:52 +01:00
|
|
|
tip_name = '%s (%s)' % (name, revs[-1].hexsha[:7])
|
2012-10-30 18:38:08 +01:00
|
|
|
else:
|
2013-01-23 18:05:11 +01:00
|
|
|
(_, local_name) = repo.git.name_rev(revs[-1].hexsha,
|
|
|
|
refs='refs/heads/*',
|
|
|
|
always=True).split()
|
2013-08-14 21:05:02 +02:00
|
|
|
local_name = unicode(local_name, "utf-8")
|
2013-01-23 18:05:11 +01:00
|
|
|
if local_name == "undefined":
|
|
|
|
print >>sys.stderr, "ERROR: Can't find this commit in remote or identify local branch!"
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
email_basename = get_current_user_email(repo).split("@")[0]
|
|
|
|
if local_name.startswith("%s-" % (email_basename,)):
|
|
|
|
# Try to push the local branch to the remote automatically
|
|
|
|
try:
|
|
|
|
print "Attempting to push %s to remote %s" % (local_name, remote)
|
|
|
|
repo.git.push(remote, local_name)
|
|
|
|
tip_name = '%s (%s)' % (local_name, revs[-1].hexsha[:7])
|
|
|
|
except git.GitCommandError, e:
|
|
|
|
print >>sys.stderr, "ERROR: Couldn't push %s to remote" % (local_name,)
|
|
|
|
print >>sys.stderr, e
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print >>sys.stderr, "ERROR: Can't find this commit in remote -- did you push %s?" % (local_name)
|
|
|
|
sys.exit(1)
|
2012-10-30 18:38:08 +01:00
|
|
|
|
|
|
|
objective_summary = '%d commit(s) to %s' % (len(revs), tip_name)
|
|
|
|
summary = ('%s (%s)' % (opts.summary, objective_summary) if opts.summary
|
|
|
|
else objective_summary)
|
|
|
|
|
2013-08-14 21:05:02 +02:00
|
|
|
return [('From', Header(me.encode("utf-8"), "utf-8")),
|
|
|
|
('To', Header(', '.join(opts.reviewers), "utf-8")),
|
|
|
|
('Cc', Header(CC_EMAIL, "utf-8")),
|
|
|
|
('Subject', Header('%s review: %s' % (
|
|
|
|
reponame, summary), "utf-8"))]
|
2012-10-30 18:38:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
def write_template(target, repo, opts):
|
2012-11-05 19:30:07 +01:00
|
|
|
me = get_current_user(repo)
|
2012-10-30 18:38:08 +01:00
|
|
|
|
|
|
|
print >>target, 'Dear %s,' % ", ".join(opts.reviewers)
|
|
|
|
print >>target
|
|
|
|
print >>target, 'At your convenience, please review the following commits.'
|
|
|
|
print >>target
|
|
|
|
if opts.message:
|
|
|
|
print >>target, opts.message
|
|
|
|
print >>target
|
2013-06-05 20:27:16 +02:00
|
|
|
print >>target, 'Testing:'
|
2012-10-30 18:38:08 +01:00
|
|
|
if opts.testing:
|
|
|
|
print >>target, opts.testing
|
|
|
|
else:
|
|
|
|
print >>target, '(No formal testing done, or none specified.)'
|
|
|
|
print >>target
|
|
|
|
print >>target, 'Thanks,'
|
|
|
|
print >>target, me
|
|
|
|
|
|
|
|
|
|
|
|
def write_commitmsg(target, repo, opts, revs):
|
|
|
|
|
|
|
|
if opts.format == 'oneline':
|
|
|
|
for r in revs:
|
|
|
|
print >>target, unicode(repo.git.log('-n1', '--oneline', r), 'utf-8', 'replace')
|
|
|
|
elif opts.format == 'message' or opts.format is None and len(revs) > 1:
|
|
|
|
for r in revs:
|
|
|
|
if opts.first_parent:
|
|
|
|
print >>target, unicode(repo.git.log('-n1', r), 'utf-8', 'replace')
|
|
|
|
print >>target, unicode(repo.git.diff('--stat', str(r)+'^', r), 'utf-8', 'replace')
|
|
|
|
else:
|
|
|
|
print >>target, unicode(repo.git.log('-n1', '--stat', r), 'utf-8', 'replace')
|
|
|
|
print >>target
|
|
|
|
elif opts.format == 'patch' or opts.format is None and len(revs) == 1:
|
|
|
|
for r in revs:
|
|
|
|
if opts.first_parent:
|
|
|
|
print >>target, unicode(repo.git.log('-n1', r), 'utf-8', 'replace')
|
|
|
|
print >>target, unicode(repo.git.diff('--stat', '-p', str(r)+'^', r), 'utf-8', 'replace')
|
|
|
|
else:
|
|
|
|
print >>target, unicode(repo.git.log('-n1', '--stat', '-p', r), 'utf-8', 'replace')
|
|
|
|
print >>target
|
|
|
|
else:
|
|
|
|
raise Exception("Bad format option.")
|
|
|
|
|
|
|
|
|
2013-01-31 22:15:16 +01:00
|
|
|
def edit(repo, opts, revs, headers):
|
2012-10-30 18:38:08 +01:00
|
|
|
template = StringIO()
|
|
|
|
commitmsg = StringIO()
|
2012-10-30 18:39:37 +01:00
|
|
|
|
2012-10-30 18:38:08 +01:00
|
|
|
write_template(template, repo, opts)
|
|
|
|
write_commitmsg(commitmsg, repo, opts, revs)
|
2012-10-30 18:39:37 +01:00
|
|
|
|
2012-10-30 18:38:08 +01:00
|
|
|
temp = codecs.getwriter('utf-8')(tempfile.NamedTemporaryFile(prefix="review-"))
|
|
|
|
|
|
|
|
# Prepare editable buffer.
|
|
|
|
|
|
|
|
print >>temp, """# This is an editable review request. All lines beginning with # will
|
|
|
|
# be ignored. To abort the commit, remove all lines from this buffer."""
|
|
|
|
print >>temp, "#"
|
|
|
|
for (key, value) in headers:
|
|
|
|
print >>temp, u"# %s: %s" % (key, value)
|
|
|
|
print >>temp
|
|
|
|
print >>temp, template.getvalue()
|
|
|
|
for line in commitmsg.getvalue().splitlines():
|
|
|
|
print >>temp, "# " + line
|
|
|
|
temp.flush()
|
|
|
|
|
|
|
|
# Open EDITOR to edit buffer.
|
|
|
|
|
|
|
|
editor = os.getenv('EDITOR','emacs')
|
|
|
|
subprocess.check_call(shlex.split(editor) + [temp.name])
|
|
|
|
|
|
|
|
# Check if buffer is empty, and if so abort.
|
2012-10-30 18:39:37 +01:00
|
|
|
|
2012-10-30 18:38:08 +01:00
|
|
|
if (os.path.getsize(temp.name) == 0):
|
|
|
|
print >>sys.stderr, "Aborting due to empty buffer."
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
# Reopen temp file, slurp it in, and reconstruct mail.
|
|
|
|
|
|
|
|
final = codecs.open(temp.name, 'r', 'utf-8')
|
|
|
|
msg = Message()
|
|
|
|
for (key, value) in headers:
|
|
|
|
msg[key] = value
|
|
|
|
msg.set_payload(
|
|
|
|
("".join(line for line in final if not line.startswith("#")).strip() +
|
|
|
|
"\n\n" + commitmsg.getvalue()).encode('utf-8'),
|
|
|
|
'utf-8')
|
|
|
|
|
|
|
|
# Clean up.
|
|
|
|
|
|
|
|
temp.close()
|
|
|
|
final.close()
|
|
|
|
try:
|
|
|
|
os.unlink(temp.name)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
return msg
|
|
|
|
|
2013-05-30 22:17:01 +02:00
|
|
|
def clone_to_tmp(repo, tmp_path, test_existence_only=False):
|
|
|
|
print "Cloning into", tmp_path
|
|
|
|
assert not os.path.exists(tmp_path), \
|
|
|
|
'Path ' + tmp_path + ' exists. Either another test is running there ' \
|
|
|
|
'or it was left there so that you could view the testing log. If you are sure ' \
|
|
|
|
'another test is not running there, remove this directory before proceeding.'
|
|
|
|
if test_existence_only:
|
|
|
|
return
|
|
|
|
clone = repo.clone(tmp_path)
|
|
|
|
clone.git.checkout(repo.commit().hexsha)
|
|
|
|
return clone
|
|
|
|
|
|
|
|
def cleanup_tmp(cloned_repo):
|
|
|
|
print "Cleaning up..."
|
|
|
|
assert os.path.exists(cloned_repo.working_tree_dir), "could not find " + cloned_repo.working_tree_dir
|
|
|
|
rmtree(cloned_repo.working_tree_dir)
|
|
|
|
return
|
|
|
|
|
|
|
|
def run_test_script(repo, tmp_path):
|
2013-10-31 19:09:30 +01:00
|
|
|
# Copy over relevant files to $tmp_dir/zulip_test.git
|
2013-05-30 22:17:01 +02:00
|
|
|
working_dir = os.getcwd()
|
|
|
|
clone = clone_to_tmp(repo, tmp_path)
|
2013-07-29 23:03:31 +02:00
|
|
|
for filename in ['zerver/fixtures/available-migrations',
|
|
|
|
'zerver/fixtures/migration-status',
|
|
|
|
'zerver/fixtures/messages.json',
|
2013-05-30 22:17:01 +02:00
|
|
|
'event_queues.pickle']:
|
|
|
|
if os.path.isfile(filename):
|
|
|
|
copyfile(filename, clone.working_tree_dir + "/" + filename)
|
|
|
|
for directory in ['event_log', 'stats']:
|
|
|
|
if os.path.isdir(directory):
|
|
|
|
copytree(directory, clone.working_tree_dir + "/" + directory)
|
|
|
|
|
|
|
|
# Go to $tmp_path and run TEST_SCRIPT
|
|
|
|
os.chdir(clone.working_tree_dir)
|
|
|
|
os.environ["PWD"] = os.getcwd()
|
|
|
|
log = open("test.log", 'w')
|
|
|
|
log_path = os.getcwd() + "/" + log.name
|
2013-06-27 20:15:19 +02:00
|
|
|
print "Testing [log=%s] ..." % (log_path,)
|
2013-05-30 22:17:01 +02:00
|
|
|
try:
|
|
|
|
proc = subprocess.Popen(TEST_SCRIPT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=sys.stdin)
|
|
|
|
# Set the proc.stdout.read() to be non-blocking
|
|
|
|
fcntl.fcntl(proc.stdout, fcntl.F_SETFL, os.O_NONBLOCK)
|
|
|
|
while proc.poll() is None:
|
|
|
|
try:
|
|
|
|
buf = proc.stdout.read(1024)
|
|
|
|
if buf != "":
|
|
|
|
sys.stdout.write(buf)
|
|
|
|
sys.stdout.flush()
|
|
|
|
log.write(buf)
|
|
|
|
log.flush()
|
|
|
|
except IOError as e:
|
|
|
|
#ignore EAGAIN errors caused by non-blocking prod.stdout
|
|
|
|
if e.errno != EAGAIN:
|
|
|
|
raise e
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
sleep(.5)
|
|
|
|
except KeyboardInterrupt as e:
|
|
|
|
print "\nkilling tests..."
|
|
|
|
print "You may find the testing log in", log_path
|
|
|
|
proc.send_signal(SIGINT)
|
|
|
|
sleep(2)
|
|
|
|
proc.send_signal(SIGTERM)
|
|
|
|
proc.wait()
|
|
|
|
buf = proc.stdout.read()
|
|
|
|
log.write(buf)
|
|
|
|
sys.stdout.write(buf)
|
|
|
|
raise e
|
|
|
|
buf = proc.stdout.read()
|
|
|
|
sys.stdout.write(buf)
|
|
|
|
log.write(buf)
|
|
|
|
if proc.returncode!=0:
|
|
|
|
print TEST_SCRIPT, "exited with status code", proc.returncode
|
|
|
|
print "You may find the testing log in", log_path
|
|
|
|
else:
|
|
|
|
os.chdir(working_dir)
|
|
|
|
os.environ["PWD"] = os.getcwd()
|
|
|
|
cleanup_tmp(clone)
|
|
|
|
return proc.returncode
|
2012-10-30 18:38:08 +01:00
|
|
|
|
|
|
|
def main(args):
|
|
|
|
opts, args = parse_options(args)
|
|
|
|
repo = git.Repo()
|
|
|
|
revs = parse_revs(repo, opts, args[1:])
|
|
|
|
if not revs:
|
|
|
|
print >>sys.stderr, '%s: no revisions specified' % os.path.basename(args[0])
|
|
|
|
return 2
|
|
|
|
|
2013-10-06 19:52:11 +02:00
|
|
|
if not opts.stdout:
|
2013-12-06 23:50:55 +01:00
|
|
|
client = zulip.Client(verbose=True, client="ZulipReview/0.1")
|
2013-10-06 19:52:11 +02:00
|
|
|
|
2015-02-06 07:00:10 +01:00
|
|
|
if 'staging' in client.base_url:
|
2013-10-06 19:52:11 +02:00
|
|
|
print '''
|
|
|
|
|
2015-02-06 07:00:10 +01:00
|
|
|
HEY! You still have your .zuliprc pointing to staging.
|
2013-10-06 19:52:11 +02:00
|
|
|
ABORTING
|
|
|
|
|
|
|
|
'''
|
|
|
|
sys.exit(1)
|
|
|
|
|
2013-05-30 22:17:01 +02:00
|
|
|
# Attempt to catch permissions/invalid paths early for tmp_dir
|
|
|
|
if opts.run_tests:
|
2013-10-31 19:09:30 +01:00
|
|
|
tmp_path = opts.tmp_dir + "/zulip_test.git"
|
2013-05-30 22:17:01 +02:00
|
|
|
clone_to_tmp(repo, tmp_path, test_existence_only=True)
|
|
|
|
os.mkdir(tmp_path)
|
|
|
|
os.rmdir(tmp_path)
|
|
|
|
|
|
|
|
# Also pushes the branch to your remote
|
2013-01-31 22:15:16 +01:00
|
|
|
headers = make_header(repo, opts, revs)
|
2012-10-30 18:38:08 +01:00
|
|
|
if opts.edit:
|
2013-01-31 22:15:16 +01:00
|
|
|
msg = edit(repo, opts, revs, headers)
|
2012-10-30 18:38:08 +01:00
|
|
|
|
2012-10-30 18:39:37 +01:00
|
|
|
else:
|
2012-10-30 18:38:08 +01:00
|
|
|
# Just build the message.
|
|
|
|
msg = Message()
|
2013-01-31 22:15:16 +01:00
|
|
|
for (key, value) in headers:
|
2012-10-30 18:38:08 +01:00
|
|
|
msg[key] = value
|
|
|
|
|
|
|
|
template = StringIO()
|
|
|
|
commitmsg = StringIO()
|
|
|
|
|
|
|
|
write_template(template, repo, opts)
|
|
|
|
write_commitmsg(commitmsg, repo, opts, revs)
|
|
|
|
msg.set_payload(
|
|
|
|
(template.getvalue() + "\n" + commitmsg.getvalue()).encode('utf-8'),
|
|
|
|
'utf-8')
|
|
|
|
|
2013-05-30 22:17:01 +02:00
|
|
|
# Run TEST_SCRIPT on HEAD, if desired.
|
|
|
|
if opts.run_tests:
|
|
|
|
testing_status_code = None
|
|
|
|
try:
|
|
|
|
testing_status_code = run_test_script(repo, tmp_path)
|
|
|
|
if testing_status_code != 0:
|
|
|
|
sys.exit(testing_status_code)
|
|
|
|
finally:
|
|
|
|
if testing_status_code != 0:
|
|
|
|
commit_message_path = opts.tmp_dir + "/commit.msg"
|
|
|
|
open(commit_message_path, 'w').write(msg.get_payload(decode=True))
|
|
|
|
print "You may find your commit message at", commit_message_path
|
|
|
|
|
|
|
|
print "Processing review message..."
|
2012-10-30 18:38:08 +01:00
|
|
|
# Send or print the message, as appropriate.
|
|
|
|
if opts.stdout:
|
|
|
|
for (key, value) in msg.items():
|
|
|
|
print >>sys.stdout, u"%s: %s" % (key, value)
|
|
|
|
print >>sys.stdout
|
|
|
|
print >>sys.stdout, msg.get_payload(decode=True),
|
|
|
|
else:
|
2013-02-05 21:31:02 +01:00
|
|
|
reviewer_usernames = [x.split("@")[0] for x in opts.reviewers]
|
|
|
|
|
|
|
|
content = ("Sent a review request to %s for\n%s" %
|
|
|
|
(' '.join('@'+x for x in reviewer_usernames),
|
|
|
|
msg.get('Subject', '<unknown>')))
|
|
|
|
subject = "Reviews for " + ", ".join(reviewer_usernames)
|
|
|
|
|
2013-02-01 22:16:49 +01:00
|
|
|
client.send_message({'type': "stream",
|
|
|
|
'subject': subject[:60],
|
|
|
|
'to': "review",
|
2013-01-31 22:15:16 +01:00
|
|
|
'content': content})
|
2012-11-05 19:31:10 +01:00
|
|
|
|
2012-11-02 20:44:14 +01:00
|
|
|
if os.environ.get('REVIEW_USE_SENDMAIL', ''):
|
|
|
|
command = ['/usr/sbin/sendmail', '-bm', '-t']
|
|
|
|
else:
|
|
|
|
command = ['msmtp', '-t']
|
|
|
|
subprocess.Popen(command,
|
2012-10-30 18:38:08 +01:00
|
|
|
stdin=subprocess.PIPE).communicate(msg.as_string())
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|