|
16 | 16 | from typer_config.decorators import use_yaml_config
|
17 | 17 |
|
18 | 18 |
|
19 |
| -app = typer.Typer() |
| 19 | +class TyperApp(typer.Typer): |
| 20 | + """Our App.""" |
20 | 21 |
|
| 22 | + repos: list[str] |
21 | 23 |
|
22 |
| -@app.command() |
| 24 | + |
| 25 | +app = TyperApp() |
| 26 | +console = Console() |
| 27 | + |
| 28 | + |
| 29 | +@app.callback(invoke_without_command=True) |
23 | 30 | @use_yaml_config(
|
24 | 31 | default_value=os.path.expanduser("~/pre.yml"),
|
25 | 32 | param_help="Configuration file (~/pre.yml).",
|
26 | 33 | )
|
27 |
| -def main(repos: Annotated[Optional[list[str]], typer.Option()] = None) -> None: |
28 |
| - """Pre helps you chain releases on github.""" |
| 34 | +def default(repos: Annotated[Optional[list[str]], typer.Option()] = None) -> None: |
| 35 | + """Implicit entry point.""" |
29 | 36 | if repos is None:
|
30 | 37 | repos = []
|
31 |
| - console = Console() |
32 |
| - for repo in repos: |
| 38 | + app.repos = repos |
| 39 | + |
| 40 | + |
| 41 | +@app.command() |
| 42 | +def main() -> None: |
| 43 | + """Pre helps you chain releases on github.""" |
| 44 | + for repo in app.repos: |
33 | 45 | repo_link = f"[markdown.link][link=https://github.com/{repo}]{repo}[/][/]"
|
34 | 46 | result = run(
|
35 | 47 | f'gh api repos/{repo}/releases --jq "[.[] | select(.draft)"]',
|
@@ -63,6 +75,51 @@ def main(repos: Annotated[Optional[list[str]], typer.Option()] = None) -> None:
|
63 | 75 | console.print(md, style="dim")
|
64 | 76 |
|
65 | 77 |
|
| 78 | +@app.command() |
| 79 | +def prs() -> None: |
| 80 | + """List pending pull-request.""" |
| 81 | + # for user in TEAM: |
| 82 | + # --review-requested=@{user} |
| 83 | + # --owner=ansible --owner=ansible-community |
| 84 | + cmd = ( |
| 85 | + "GH_PAGER= gh search prs --draft=false --state=open --limit=100 --sort=updated" |
| 86 | + ) |
| 87 | + cmd += "".join(f" --repo={repo}" for repo in app.repos) |
| 88 | + cmd += ( |
| 89 | + " --template '{{range .}}{{tablerow .repository.nameWithOwner (timeago .updatedAt) " |
| 90 | + '.title (hyperlink .url (printf "#%v" .number) ) }}{{end}}{{tablerender}}\' ' |
| 91 | + "--json title,url,repository,updatedAt,number" |
| 92 | + ) |
| 93 | + console.print(f"[dim]{cmd}[/]", highlight=False) |
| 94 | + os.system(cmd) |
| 95 | + |
| 96 | + |
| 97 | +@app.command() |
| 98 | +def alerts() -> None: |
| 99 | + """List open alerts.""" |
| 100 | + for repo in app.repos: |
| 101 | + cmd = "GH_PAGER= gh " |
| 102 | + cmd += f"api /repos/{repo}/dependabot/alerts" |
| 103 | + cmd += " --jq='.[] | select(.state!=\"fixed\") | .html_url'" |
| 104 | + result = run( |
| 105 | + cmd, |
| 106 | + text=True, |
| 107 | + shell=True, |
| 108 | + capture_output=True, |
| 109 | + check=False, |
| 110 | + ) |
| 111 | + if result.returncode: |
| 112 | + console.print( |
| 113 | + f"[dim]{cmd}[/dim] failed with {result.returncode}\n" |
| 114 | + f"{result.stdout}\n\n{result.stderr}" |
| 115 | + ) |
| 116 | + else: |
| 117 | + if result.stdout: |
| 118 | + console.print(result.stdout) |
| 119 | + if result.stderr: |
| 120 | + console.print(result.stderr) |
| 121 | + |
| 122 | + |
66 | 123 | if __name__ == "__main__":
|
67 | 124 | # execute only if run as a script
|
68 | 125 | app()
|
0 commit comments