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_main() -> None:
2017-09-08 04:41:25 -04:00
branch = get_git_branch()
if branch != "main":
exit(f"You are still on a feature branch: {branch}")
2017-09-08 04:41:25 -04:00
check_git_pristine()
run("git fetch upstream main")
run("git rebase upstream/main")
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(f"git checkout -B review-{pull_id} FETCH_HEAD")
run("git rebase upstream/main")
run("git log upstream/main.. --oneline")
run("git diff upstream/main.. --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_main()
2017-09-08 04:41:25 -04:00
create_pull_branch(pull_id)
if __name__ == "__main__":
2017-09-08 04:41:25 -04:00
review_pr()