python-zulip-api/tools/review

68 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python3
2017-09-08 04:41:25 -04:00
import subprocess
import sys
2021-05-28 05:00:04 -04:00
def exit(message: str) -> None:
2017-09-08 04:41:25 -04:00
print('PROBLEM!')
print(message)
sys.exit(1)
def run(command: str) -> None:
2017-09-08 04:41:25 -04:00
print('\n>>> ' + command)
subprocess.check_call(command.split())
def check_output(command: str) -> str:
2017-09-08 04:41:25 -04:00
return subprocess.check_output(command.split()).decode('ascii')
def get_git_branch() -> str:
2017-09-08 04:41:25 -04:00
command = 'git rev-parse --abbrev-ref HEAD'
output = check_output(command)
return output.strip()
def check_git_pristine() -> None:
2017-09-08 04:41:25 -04:00
command = 'git status --porcelain'
output = check_output(command)
if output.strip():
exit('Git is not pristine:\n' + output)
def ensure_on_clean_master() -> None:
2017-09-08 04:41:25 -04:00
branch = get_git_branch()
if branch != 'master':
exit('You are still on a feature branch: %s' % (branch,))
check_git_pristine()
run('git fetch upstream master')
run('git rebase upstream/master')
def create_pull_branch(pull_id: int) -> None:
2017-09-08 04:41:25 -04:00
run('git fetch upstream pull/%d/head' % (pull_id,))
run('git checkout -B review-%s FETCH_HEAD' % (pull_id,))
run('git rebase upstream/master')
run('git log upstream/master.. --oneline')
run('git diff upstream/master.. --name-status')
print()
print('PR: %d' % (pull_id,))
print(subprocess.check_output(['git', 'log', 'HEAD~..', '--pretty=format:Author: %an']))
2017-09-08 04:41:25 -04:00
def review_pr() -> None:
2017-09-08 04:41:25 -04:00
try:
pull_id = int(sys.argv[1])
except Exception:
exit('please provide an integer pull request id')
ensure_on_clean_master()
create_pull_branch(pull_id)
2017-09-08 04:41:25 -04:00
if __name__ == '__main__':
review_pr()