Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit 1b55446

Browse files
authored
Add ability to report dependabot alerts (#9)
1 parent 0bab831 commit 1b55446

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

.config/dictionary.txt

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ notest
1414
pycontribs
1515
pypa
1616
setuptools
17+
tablerender
18+
timeago
1719
typer

src/gh_pre/__main__.py

+63-6
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,32 @@
1616
from typer_config.decorators import use_yaml_config
1717

1818

19-
app = typer.Typer()
19+
class TyperApp(typer.Typer):
20+
"""Our App."""
2021

22+
repos: list[str]
2123

22-
@app.command()
24+
25+
app = TyperApp()
26+
console = Console()
27+
28+
29+
@app.callback(invoke_without_command=True)
2330
@use_yaml_config(
2431
default_value=os.path.expanduser("~/pre.yml"),
2532
param_help="Configuration file (~/pre.yml).",
2633
)
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."""
2936
if repos is None:
3037
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:
3345
repo_link = f"[markdown.link][link=https://github.com/{repo}]{repo}[/][/]"
3446
result = run(
3547
f'gh api repos/{repo}/releases --jq "[.[] | select(.draft)"]',
@@ -63,6 +75,51 @@ def main(repos: Annotated[Optional[list[str]], typer.Option()] = None) -> None:
6375
console.print(md, style="dim")
6476

6577

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+
66123
if __name__ == "__main__":
67124
# execute only if run as a script
68125
app()

0 commit comments

Comments
 (0)