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:
print("PROBLEM!")
2017-09-08 04:41:25 -04:00
print(message)
sys.exit(1)
def run(command: str) -> None:
print("\n>>> " + command)
2017-09-08 04:41:25 -04:00
subprocess.check_call(command.split())
def check_output(command: str) -> str:
return subprocess.check_output(command.split()).decode("ascii")
2017-09-08 04:41:25 -04:00
def get_git_branch() -> str:
command = "git rev-parse --abbrev-ref HEAD"
2017-09-08 04:41:25 -04:00
output = check_output(command)
return output.strip()
def check_git_pristine() -> None:
command = "git status --porcelain"
2017-09-08 04:41:25 -04:00
output = check_output(command)
if output.strip():
exit("Git is not pristine:\n" + output)
2017-09-08 04:41:25 -04:00
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,))
2017-09-08 04:41:25 -04:00
check_git_pristine()
run("git fetch upstream master")
run("git rebase upstream/master")
2017-09-08 04:41:25 -04:00
def create_pull_branch(pull_id: int) -> None:
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")
2017-09-08 04:41:25 -04:00
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")
2017-09-08 04:41:25 -04:00
ensure_on_clean_master()
create_pull_branch(pull_id)
if __name__ == "__main__":
2017-09-08 04:41:25 -04:00
review_pr()