-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcli.py
59 lines (42 loc) · 1.56 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
from typing import List
import click
from click_default_group import DefaultGroup
from danger_python.decorators import danger_command
from danger_python.exceptions import DangerfileException
from danger_python.shell import execute_dangerfile, invoke_danger
@click.group(cls=DefaultGroup, default="run", default_if_no_args=True)
def cli() -> None:
pass
@cli.command()
def run() -> None:
"""Runs dangerfile.py as a danger process"""
runner()
@danger_command(cli, "runner")
def runner(arguments: List[str]) -> None:
"""Runs dangerfile.py as a danger process, ignoring unknown options"""
with open("dangerfile.py", "r") as dangerfile:
try:
execute_dangerfile(dangerfile.read())
except DangerfileException as exc:
click.echo(exc, err=True)
sys.exit(-1)
@danger_command(cli, "pr")
def pr(arguments: List[str]) -> None:
"""Runs your local Dangerfile against an existing GitHub PR.
Will not post on the PR"""
_execute_danger_js("pr", arguments)
@danger_command(cli, "local")
def local(arguments: List[str]) -> None:
"""Runs danger standalone on a repo, useful for git hooks"""
_execute_danger_js("local", arguments)
@danger_command(cli, "ci")
def ci(arguments: List[str]) -> None:
"""Runs Danger on CI"""
_execute_danger_js("ci", arguments)
def _execute_danger_js(command_name: str, arguments: List[str]) -> None:
command = [command_name]
command.extend(arguments)
process = invoke_danger(command)
click.echo(process.stdout)
sys.exit(process.returncode)