Files
zulip/tools/review
Anders Kaseorg 5901e7ba7e python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:

-    def __init__(self, token: Token, parent: Optional[Node]) -> None:
+    def __init__(self, token: Token, parent: "Optional[Node]") -> None:

-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":

-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":

-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:

-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:

-    method_kwarg_pairs: List[FuncKwargPair],
+    method_kwarg_pairs: "List[FuncKwargPair]",

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-18 20:42:48 -07:00

62 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
import shlex
import subprocess
import sys
from typing import List
def exit(message: str) -> None:
print('PROBLEM!')
print(message)
sys.exit(1)
def run(command: List[str]) -> None:
print('\n>>> ' + ' '.join(map(shlex.quote, command)))
subprocess.check_call(command)
def check_output(command: List[str]) -> str:
return subprocess.check_output(command).decode('ascii')
def get_git_branch() -> str:
command = ['git', 'rev-parse', '--abbrev-ref', 'HEAD']
output = check_output(command)
return output.strip()
def check_git_pristine() -> None:
command = ['git', 'status', '--porcelain']
output = check_output(command)
if output.strip():
exit('Git is not pristine:\n' + output)
def ensure_on_clean_master() -> None:
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:
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'])
print()
print('PR: %d' % (pull_id,))
print(subprocess.check_output(['git', 'log', 'HEAD~..',
'--pretty=format:Author: %an']))
def review_pr() -> None:
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)
if __name__ == '__main__':
review_pr()