py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2017-01-06 18:54:52 +01:00
|
|
|
|
2018-07-18 23:42:53 +02:00
|
|
|
import shlex
|
2017-01-06 18:54:52 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2018-07-18 23:42:53 +02:00
|
|
|
from typing import List
|
2017-01-06 18:54:52 +01:00
|
|
|
|
|
|
|
def exit(message):
|
|
|
|
# type: (str) -> None
|
|
|
|
print('PROBLEM!')
|
|
|
|
print(message)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def run(command):
|
2018-07-18 23:42:53 +02:00
|
|
|
# type: (List[str]) -> None
|
|
|
|
print('\n>>> ' + ' '.join(map(shlex.quote, command)))
|
|
|
|
subprocess.check_call(command)
|
2017-01-06 18:54:52 +01:00
|
|
|
|
2017-08-17 23:39:35 +02:00
|
|
|
def check_output(command):
|
2018-07-18 23:42:53 +02:00
|
|
|
# type: (List[str]) -> str
|
|
|
|
return subprocess.check_output(command).decode('ascii')
|
2017-08-17 23:39:35 +02:00
|
|
|
|
2017-01-06 18:54:52 +01:00
|
|
|
def get_git_branch():
|
|
|
|
# type: () -> str
|
2018-07-18 23:42:53 +02:00
|
|
|
command = ['git', 'rev-parse', '--abbrev-ref', 'HEAD']
|
2017-08-17 23:39:35 +02:00
|
|
|
output = check_output(command)
|
2017-01-06 18:54:52 +01:00
|
|
|
return output.strip()
|
|
|
|
|
|
|
|
def check_git_pristine():
|
|
|
|
# type: () -> None
|
2018-07-18 23:42:53 +02:00
|
|
|
command = ['git', 'status', '--porcelain']
|
2017-08-17 23:39:35 +02:00
|
|
|
output = check_output(command)
|
2017-01-06 18:54:52 +01:00
|
|
|
if output.strip():
|
|
|
|
exit('Git is not pristine:\n' + output)
|
|
|
|
|
|
|
|
def ensure_on_clean_master():
|
|
|
|
# type: () -> None
|
|
|
|
branch = get_git_branch()
|
|
|
|
if branch != 'master':
|
|
|
|
exit('You are still on a feature branch: %s' % (branch,))
|
|
|
|
check_git_pristine()
|
2018-07-18 23:42:53 +02:00
|
|
|
run(['git', 'fetch', 'upstream', 'master'])
|
|
|
|
run(['git', 'rebase', 'upstream/master'])
|
2017-01-06 18:54:52 +01:00
|
|
|
|
|
|
|
def create_pull_branch(pull_id):
|
|
|
|
# type: (int) -> None
|
2018-07-18 23:42:53 +02:00
|
|
|
run(['git', 'fetch', 'upstream', 'pull/%d/head' % (pull_id,)])
|
|
|
|
run(['git', 'checkout', '-B', 'review-%s' % (pull_id,), 'FETCH_HEAD'])
|
|
|
|
run(['git', 'rebase', 'upstream/master'])
|
|
|
|
run(['git', 'log', 'upstream/master..', '--oneline'])
|
|
|
|
run(['git', 'diff', 'upstream/master..', '--name-status'])
|
2017-01-06 18:54:52 +01:00
|
|
|
|
|
|
|
print()
|
|
|
|
print('PR: %d' % (pull_id,))
|
2017-01-24 06:21:14 +01:00
|
|
|
print(subprocess.check_output(['git', 'log', 'HEAD~..',
|
2017-01-06 18:54:52 +01:00
|
|
|
'--pretty=format:Author: %an']))
|
|
|
|
|
|
|
|
def review_pr():
|
|
|
|
# type: () -> None
|
|
|
|
try:
|
|
|
|
pull_id = int(sys.argv[1])
|
2017-03-05 10:25:27 +01:00
|
|
|
except Exception:
|
2017-01-06 18:54:52 +01:00
|
|
|
exit('please provide an integer pull request id')
|
|
|
|
|
|
|
|
ensure_on_clean_master()
|
|
|
|
create_pull_branch(pull_id)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
review_pr()
|