lupaxa-github-intel 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lupaxa/github_intel/__init__.py +13 -0
- lupaxa/github_intel/__main__.py +8 -0
- lupaxa/github_intel/app.py +493 -0
- lupaxa/github_intel/checks/__init__.py +1 -0
- lupaxa/github_intel/checks/base.py +17 -0
- lupaxa/github_intel/checks/releases.py +59 -0
- lupaxa/github_intel/checks/workflows.py +34 -0
- lupaxa/github_intel/cli.py +699 -0
- lupaxa/github_intel/config/__init__.py +1 -0
- lupaxa/github_intel/config/defaults.py +150 -0
- lupaxa/github_intel/config/editor.py +316 -0
- lupaxa/github_intel/config/loader.py +412 -0
- lupaxa/github_intel/config/models.py +310 -0
- lupaxa/github_intel/config/paths.py +84 -0
- lupaxa/github_intel/config/profiles.py +143 -0
- lupaxa/github_intel/constants.py +54 -0
- lupaxa/github_intel/dates.py +179 -0
- lupaxa/github_intel/errors.py +72 -0
- lupaxa/github_intel/github/__init__.py +1 -0
- lupaxa/github_intel/github/auth.py +40 -0
- lupaxa/github_intel/github/client.py +239 -0
- lupaxa/github_intel/github/rate_limit.py +107 -0
- lupaxa/github_intel/layout.py +141 -0
- lupaxa/github_intel/logging_setup.py +51 -0
- lupaxa/github_intel/present.py +361 -0
- lupaxa/github_intel/reports/__init__.py +1 -0
- lupaxa/github_intel/reports/render.py +113 -0
- lupaxa/github_intel/storage/__init__.py +1 -0
- lupaxa/github_intel/storage/database.py +419 -0
- lupaxa/github_intel/sync/__init__.py +1 -0
- lupaxa/github_intel/sync/engine.py +671 -0
- lupaxa/github_intel/sync/summary.py +308 -0
- lupaxa/github_intel/tui/__init__.py +1 -0
- lupaxa/github_intel/tui/application.py +487 -0
- lupaxa/github_intel/views.py +896 -0
- lupaxa_github_intel-0.1.0.dist-info/METADATA +180 -0
- lupaxa_github_intel-0.1.0.dist-info/RECORD +41 -0
- lupaxa_github_intel-0.1.0.dist-info/WHEEL +5 -0
- lupaxa_github_intel-0.1.0.dist-info/entry_points.txt +2 -0
- lupaxa_github_intel-0.1.0.dist-info/licenses/LICENCE +21 -0
- lupaxa_github_intel-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Command-line interface for GitHub Intel.
|
|
3
|
+
|
|
4
|
+
Human output uses Rich. JSON and CSV are written to stdout alone.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
from collections.abc import Callable, Coroutine
|
|
11
|
+
import csv
|
|
12
|
+
import io
|
|
13
|
+
import json
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
import sys
|
|
16
|
+
from typing import Any, TypeVar
|
|
17
|
+
|
|
18
|
+
import typer
|
|
19
|
+
|
|
20
|
+
from lupaxa.github_intel.app import Service
|
|
21
|
+
from lupaxa.github_intel.config.defaults import generate_default_files
|
|
22
|
+
from lupaxa.github_intel.config.paths import config_directory
|
|
23
|
+
from lupaxa.github_intel.constants import (
|
|
24
|
+
EXIT_CONFIG,
|
|
25
|
+
EXIT_SYNC,
|
|
26
|
+
PROGRAM_NAME,
|
|
27
|
+
PROGRAM_VERSION_STRING,
|
|
28
|
+
)
|
|
29
|
+
from lupaxa.github_intel.errors import (
|
|
30
|
+
AuthError,
|
|
31
|
+
ChecksFailed,
|
|
32
|
+
ConfigError,
|
|
33
|
+
IntelError,
|
|
34
|
+
SyncIncomplete,
|
|
35
|
+
)
|
|
36
|
+
from lupaxa.github_intel.layout import Layout, resolve_layout
|
|
37
|
+
from lupaxa.github_intel.present import (
|
|
38
|
+
print_detail,
|
|
39
|
+
print_profile,
|
|
40
|
+
print_repos,
|
|
41
|
+
print_sync,
|
|
42
|
+
stderr_console,
|
|
43
|
+
stdout_console,
|
|
44
|
+
syncing,
|
|
45
|
+
)
|
|
46
|
+
from lupaxa.github_intel.reports.render import render_report
|
|
47
|
+
from lupaxa.github_intel.sync.engine import SyncReport
|
|
48
|
+
from lupaxa.github_intel.tui.application import run_tui
|
|
49
|
+
from lupaxa.github_intel.views import RepositoryView, detail_rows
|
|
50
|
+
|
|
51
|
+
__all__ = ["app", "main"]
|
|
52
|
+
|
|
53
|
+
app = typer.Typer(
|
|
54
|
+
name=PROGRAM_NAME,
|
|
55
|
+
invoke_without_command=True,
|
|
56
|
+
pretty_exceptions_enable=False,
|
|
57
|
+
no_args_is_help=False,
|
|
58
|
+
)
|
|
59
|
+
repo_app = typer.Typer(help="Manage the configured repository list.")
|
|
60
|
+
profile_app = typer.Typer(help="Inspect monitoring profiles.")
|
|
61
|
+
config_app = typer.Typer(help="Show, validate, and create configuration.")
|
|
62
|
+
cache_app = typer.Typer(help="Inspect and clear the local cache.")
|
|
63
|
+
app.add_typer(repo_app, name="repo")
|
|
64
|
+
app.add_typer(profile_app, name="profile")
|
|
65
|
+
app.add_typer(config_app, name="config")
|
|
66
|
+
app.add_typer(cache_app, name="cache")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class _State:
|
|
70
|
+
def __init__(self, config: Path | None, verbose: bool, debug: bool) -> None:
|
|
71
|
+
self.service = Service(config)
|
|
72
|
+
self.service.log_level = "DEBUG" if verbose or debug else None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _version(value: bool) -> None:
|
|
76
|
+
if value:
|
|
77
|
+
typer.echo(PROGRAM_VERSION_STRING)
|
|
78
|
+
raise typer.Exit
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@app.callback(invoke_without_command=True)
|
|
82
|
+
def root(
|
|
83
|
+
ctx: typer.Context,
|
|
84
|
+
config: Path | None = typer.Option(
|
|
85
|
+
None,
|
|
86
|
+
"--config",
|
|
87
|
+
help="Main configuration file.",
|
|
88
|
+
),
|
|
89
|
+
verbose: bool = typer.Option(
|
|
90
|
+
False,
|
|
91
|
+
"--verbose",
|
|
92
|
+
help="Write debug logs to stderr.",
|
|
93
|
+
),
|
|
94
|
+
debug: bool = typer.Option(False, "--debug", help="Write debug logs to stderr."),
|
|
95
|
+
version: bool = typer.Option(
|
|
96
|
+
False,
|
|
97
|
+
"--version",
|
|
98
|
+
callback=_version,
|
|
99
|
+
is_eager=True,
|
|
100
|
+
help="Show the version and exit.",
|
|
101
|
+
),
|
|
102
|
+
) -> None:
|
|
103
|
+
"""Monitor an explicit collection of GitHub repositories."""
|
|
104
|
+
|
|
105
|
+
del version
|
|
106
|
+
|
|
107
|
+
ctx.obj = _State(config, verbose, debug)
|
|
108
|
+
if ctx.invoked_subcommand is not None:
|
|
109
|
+
return
|
|
110
|
+
if sys.stdin.isatty() and sys.stdout.isatty():
|
|
111
|
+
run_tui(ctx.obj.service)
|
|
112
|
+
return
|
|
113
|
+
typer.echo(ctx.get_help())
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@repo_app.command("list")
|
|
117
|
+
def repo_list(
|
|
118
|
+
ctx: typer.Context,
|
|
119
|
+
group: str | None = typer.Option(None, "--group"),
|
|
120
|
+
profile: str | None = typer.Option(None, "--profile"),
|
|
121
|
+
tag: str | None = typer.Option(None, "--tag"),
|
|
122
|
+
status: str | None = typer.Option(None, "--status"),
|
|
123
|
+
sort: str = typer.Option("name", "--sort"),
|
|
124
|
+
output_format: str = typer.Option("table", "--format"),
|
|
125
|
+
offline: bool = typer.Option(False, "--offline", help="Read the cache only."),
|
|
126
|
+
view: str | None = typer.Option(None, "--view"),
|
|
127
|
+
) -> None:
|
|
128
|
+
"""List configured repositories."""
|
|
129
|
+
|
|
130
|
+
del offline
|
|
131
|
+
views = _run(
|
|
132
|
+
ctx.obj.service.views(group=group, profile=profile, tag=tag, status=status),
|
|
133
|
+
)
|
|
134
|
+
views = _sort(views, sort)
|
|
135
|
+
layout, date_format = _layout(ctx, views, view)
|
|
136
|
+
_emit_views(views, output_format, date_format, layout)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@app.command("list")
|
|
140
|
+
def list_alias(
|
|
141
|
+
ctx: typer.Context,
|
|
142
|
+
group: str | None = typer.Option(None, "--group"),
|
|
143
|
+
profile: str | None = typer.Option(None, "--profile"),
|
|
144
|
+
tag: str | None = typer.Option(None, "--tag"),
|
|
145
|
+
status: str | None = typer.Option(None, "--status"),
|
|
146
|
+
sort: str = typer.Option("name", "--sort"),
|
|
147
|
+
output_format: str = typer.Option("table", "--format"),
|
|
148
|
+
offline: bool = typer.Option(False, "--offline"),
|
|
149
|
+
view: str | None = typer.Option(None, "--view"),
|
|
150
|
+
) -> None:
|
|
151
|
+
"""List configured repositories."""
|
|
152
|
+
|
|
153
|
+
repo_list(
|
|
154
|
+
ctx,
|
|
155
|
+
group,
|
|
156
|
+
profile,
|
|
157
|
+
tag,
|
|
158
|
+
status,
|
|
159
|
+
sort,
|
|
160
|
+
output_format,
|
|
161
|
+
offline,
|
|
162
|
+
view,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
@repo_app.command("add")
|
|
167
|
+
def repo_add(
|
|
168
|
+
ctx: typer.Context,
|
|
169
|
+
repo: str = typer.Argument(...),
|
|
170
|
+
group: str | None = typer.Option(None, "--group"),
|
|
171
|
+
profile: str | None = typer.Option(None, "--profile"),
|
|
172
|
+
tag: list[str] | None = typer.Option(None, "--tag"),
|
|
173
|
+
validate: bool = typer.Option(
|
|
174
|
+
False,
|
|
175
|
+
"--validate",
|
|
176
|
+
help="Ask GitHub whether the repository is visible.",
|
|
177
|
+
),
|
|
178
|
+
) -> None:
|
|
179
|
+
"""Add a repository. This does not call GitHub unless --validate is set."""
|
|
180
|
+
|
|
181
|
+
service = ctx.obj.service
|
|
182
|
+
service.config_path = service.ensure_config()
|
|
183
|
+
if validate:
|
|
184
|
+
_run(service.check_remote(repo))
|
|
185
|
+
_call(service.add, repo, group, profile, tag or [])
|
|
186
|
+
stdout_console().print(f"Added {repo}.")
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@repo_app.command("remove")
|
|
190
|
+
def repo_remove(ctx: typer.Context, repo: str = typer.Argument(...)) -> None:
|
|
191
|
+
"""Remove a repository from configuration. Cached data is kept."""
|
|
192
|
+
|
|
193
|
+
_call(ctx.obj.service.remove, repo)
|
|
194
|
+
stdout_console().print(f"Removed {repo}.")
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@repo_app.command("enable")
|
|
198
|
+
def repo_enable(ctx: typer.Context, repo: str = typer.Argument(...)) -> None:
|
|
199
|
+
"""Include a repository in synchronisation."""
|
|
200
|
+
|
|
201
|
+
_call(ctx.obj.service.set_fields, repo, enabled=True)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@repo_app.command("disable")
|
|
205
|
+
def repo_disable(ctx: typer.Context, repo: str = typer.Argument(...)) -> None:
|
|
206
|
+
"""Keep a repository in configuration but skip synchronisation."""
|
|
207
|
+
|
|
208
|
+
_call(ctx.obj.service.set_fields, repo, enabled=False)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@repo_app.command("set-profile")
|
|
212
|
+
def repo_set_profile(
|
|
213
|
+
ctx: typer.Context,
|
|
214
|
+
repo: str = typer.Argument(...),
|
|
215
|
+
profile: str = typer.Argument(...),
|
|
216
|
+
) -> None:
|
|
217
|
+
"""Assign a monitoring profile."""
|
|
218
|
+
|
|
219
|
+
_call(ctx.obj.service.set_fields, repo, profile=profile)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@repo_app.command("set-group")
|
|
223
|
+
def repo_set_group(
|
|
224
|
+
ctx: typer.Context,
|
|
225
|
+
repo: str = typer.Argument(...),
|
|
226
|
+
group: str = typer.Argument(...),
|
|
227
|
+
) -> None:
|
|
228
|
+
"""Assign a group. Groups do not change which checks run."""
|
|
229
|
+
|
|
230
|
+
_call(ctx.obj.service.set_fields, repo, group=group)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@repo_app.command("show")
|
|
234
|
+
def repo_show(
|
|
235
|
+
ctx: typer.Context,
|
|
236
|
+
org: str = typer.Argument(..., metavar="ORG"),
|
|
237
|
+
name: str | None = typer.Argument(None, metavar="REPO"),
|
|
238
|
+
offline: bool = typer.Option(False, "--offline"),
|
|
239
|
+
output_format: str = typer.Option("table", "--format"),
|
|
240
|
+
view: str | None = typer.Option(None, "--view"),
|
|
241
|
+
) -> None:
|
|
242
|
+
"""Show one repository. Pass the organisation and the repository name."""
|
|
243
|
+
|
|
244
|
+
del offline
|
|
245
|
+
shown, _resolved, _documents = _run(ctx.obj.service.show(_identifier(org, name)))
|
|
246
|
+
layout, pattern = _layout(ctx, [shown], view)
|
|
247
|
+
if output_format in {"json", "csv"}:
|
|
248
|
+
typer.echo(
|
|
249
|
+
_render_show(shown, output_format, pattern, layout.detail_fields),
|
|
250
|
+
nl=False,
|
|
251
|
+
)
|
|
252
|
+
return
|
|
253
|
+
print_detail(shown, date_format=pattern, fields=layout.detail_fields)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@profile_app.command("list")
|
|
257
|
+
def profile_list(ctx: typer.Context) -> None:
|
|
258
|
+
"""List profile names."""
|
|
259
|
+
|
|
260
|
+
loaded = _call(ctx.obj.service.load)
|
|
261
|
+
for name in loaded.profiles:
|
|
262
|
+
stdout_console().print(name)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
@profile_app.command("show")
|
|
266
|
+
def profile_show(
|
|
267
|
+
ctx: typer.Context,
|
|
268
|
+
name: str = typer.Argument(...),
|
|
269
|
+
resolved: bool = typer.Option(False, "--resolved"),
|
|
270
|
+
) -> None:
|
|
271
|
+
"""Show a profile. --resolved includes the source of each flag."""
|
|
272
|
+
|
|
273
|
+
from lupaxa.github_intel.config.profiles import check_defaults, resolve_profile
|
|
274
|
+
|
|
275
|
+
loaded = _call(ctx.obj.service.load)
|
|
276
|
+
print_profile(
|
|
277
|
+
resolve_profile(
|
|
278
|
+
loaded.profiles,
|
|
279
|
+
name,
|
|
280
|
+
{},
|
|
281
|
+
**check_defaults(loaded.config.defaults),
|
|
282
|
+
),
|
|
283
|
+
show_sources=resolved,
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
@profile_app.command("tree")
|
|
288
|
+
def profile_tree(ctx: typer.Context) -> None:
|
|
289
|
+
"""Print each profile's inheritance chain."""
|
|
290
|
+
|
|
291
|
+
from lupaxa.github_intel.config.profiles import check_defaults, resolve_profile
|
|
292
|
+
|
|
293
|
+
loaded = _call(ctx.obj.service.load)
|
|
294
|
+
for name in loaded.profiles:
|
|
295
|
+
chain = " -> ".join(
|
|
296
|
+
resolve_profile(
|
|
297
|
+
loaded.profiles,
|
|
298
|
+
name,
|
|
299
|
+
{},
|
|
300
|
+
**check_defaults(loaded.config.defaults),
|
|
301
|
+
).chain
|
|
302
|
+
)
|
|
303
|
+
stdout_console().print(f"{name}: {chain}")
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
@profile_app.command("validate")
|
|
307
|
+
def profile_validate(ctx: typer.Context) -> None:
|
|
308
|
+
"""Validate every profile, including inheritance."""
|
|
309
|
+
|
|
310
|
+
from lupaxa.github_intel.config.profiles import check_defaults, resolve_profile
|
|
311
|
+
|
|
312
|
+
loaded = _call(ctx.obj.service.load)
|
|
313
|
+
for name in loaded.profiles:
|
|
314
|
+
resolve_profile(
|
|
315
|
+
loaded.profiles,
|
|
316
|
+
name,
|
|
317
|
+
{},
|
|
318
|
+
**check_defaults(loaded.config.defaults),
|
|
319
|
+
)
|
|
320
|
+
stdout_console().print(f"Validated {len(loaded.profiles)} profiles.")
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
@config_app.command("init")
|
|
324
|
+
def config_init(
|
|
325
|
+
ctx: typer.Context,
|
|
326
|
+
force: bool = typer.Option(
|
|
327
|
+
False,
|
|
328
|
+
"--force",
|
|
329
|
+
help="Overwrite existing files with the defaults.",
|
|
330
|
+
),
|
|
331
|
+
) -> None:
|
|
332
|
+
"""Write config.yml, profiles.yml, and repositories.yml filled with defaults."""
|
|
333
|
+
|
|
334
|
+
paths = _default_paths(ctx.obj.service.config_path)
|
|
335
|
+
written, kept = generate_default_files(paths, force=force)
|
|
336
|
+
for path in written:
|
|
337
|
+
stdout_console().print(f"Wrote {path}.")
|
|
338
|
+
for path in kept:
|
|
339
|
+
stdout_console().print(f"Kept {path}. Use --force to overwrite.")
|
|
340
|
+
if not written:
|
|
341
|
+
raise typer.Exit(code=EXIT_CONFIG)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def _default_paths(config: Path | None) -> tuple[Path, Path, Path]:
|
|
345
|
+
if config is None:
|
|
346
|
+
directory = config_directory()
|
|
347
|
+
main = directory / "config.yml"
|
|
348
|
+
else:
|
|
349
|
+
main = config
|
|
350
|
+
directory = config.parent
|
|
351
|
+
return main, directory / "profiles.yml", directory / "repositories.yml"
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
@config_app.command("show")
|
|
355
|
+
def config_show(ctx: typer.Context) -> None:
|
|
356
|
+
"""Print the resolved settings. Secrets are not part of the configuration."""
|
|
357
|
+
|
|
358
|
+
loaded = _call(ctx.obj.service.load)
|
|
359
|
+
stdout_console().print_json(data=loaded.config.model_dump())
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
@config_app.command("validate")
|
|
363
|
+
def config_validate(ctx: typer.Context) -> None:
|
|
364
|
+
"""Validate configuration files."""
|
|
365
|
+
|
|
366
|
+
loaded = _call(ctx.obj.service.load)
|
|
367
|
+
stdout_console().print(
|
|
368
|
+
f"Configuration is valid ({len(loaded.repositories)} repositories).",
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
@config_app.command("paths")
|
|
373
|
+
def config_paths(ctx: typer.Context) -> None:
|
|
374
|
+
"""Print configuration and cache paths."""
|
|
375
|
+
|
|
376
|
+
from lupaxa.github_intel.config.paths import data_directory
|
|
377
|
+
|
|
378
|
+
loaded = _call(ctx.obj.service.load)
|
|
379
|
+
stdout_console().print(f"config: {loaded.path}")
|
|
380
|
+
stdout_console().print(f"profiles: {loaded.profiles_path}")
|
|
381
|
+
stdout_console().print(f"repositories: {loaded.repositories_path}")
|
|
382
|
+
stdout_console().print(f"cache: {data_directory() / 'cache.sqlite'}")
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
@app.command("sync")
|
|
386
|
+
def sync_command(
|
|
387
|
+
ctx: typer.Context,
|
|
388
|
+
force: bool = typer.Option(
|
|
389
|
+
False,
|
|
390
|
+
"--force",
|
|
391
|
+
help="Ignore cache freshness and sync.interval.",
|
|
392
|
+
),
|
|
393
|
+
group: str | None = typer.Option(None, "--group"),
|
|
394
|
+
profile: str | None = typer.Option(None, "--profile"),
|
|
395
|
+
repo: str | None = typer.Option(None, "--repo"),
|
|
396
|
+
stats: bool = typer.Option(False, "--stats"),
|
|
397
|
+
concurrency: int | None = typer.Option(None, "--concurrency"),
|
|
398
|
+
fail_on_checks: bool = typer.Option(False, "--fail-on-checks"),
|
|
399
|
+
) -> None:
|
|
400
|
+
"""Refresh stale or missing information. Ctrl+C cancels the run."""
|
|
401
|
+
|
|
402
|
+
del stats
|
|
403
|
+
try:
|
|
404
|
+
_run(ctx.obj.service.assert_sync_allowed(force=force))
|
|
405
|
+
with syncing() as on_progress:
|
|
406
|
+
report = _run(
|
|
407
|
+
ctx.obj.service.sync(
|
|
408
|
+
force=force,
|
|
409
|
+
group=group,
|
|
410
|
+
profile=profile,
|
|
411
|
+
repo=repo,
|
|
412
|
+
concurrency=concurrency,
|
|
413
|
+
on_progress=on_progress,
|
|
414
|
+
)
|
|
415
|
+
)
|
|
416
|
+
except KeyboardInterrupt:
|
|
417
|
+
stderr_console().print("Synchronisation cancelled.")
|
|
418
|
+
raise typer.Exit(code=EXIT_SYNC) from None
|
|
419
|
+
print_sync(report)
|
|
420
|
+
_call(_finish_sync, report, fail_on_checks)
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
@app.command("report")
|
|
424
|
+
def report_command(
|
|
425
|
+
ctx: typer.Context,
|
|
426
|
+
output_format: str = typer.Option("markdown", "--format"),
|
|
427
|
+
group: str | None = typer.Option(None, "--group"),
|
|
428
|
+
profile: str | None = typer.Option(None, "--profile"),
|
|
429
|
+
output: Path | None = typer.Option(None, "--output"),
|
|
430
|
+
offline: bool = typer.Option(False, "--offline"),
|
|
431
|
+
view: str | None = typer.Option(None, "--view"),
|
|
432
|
+
) -> None:
|
|
433
|
+
"""Export repository information."""
|
|
434
|
+
|
|
435
|
+
del offline
|
|
436
|
+
views = _run(ctx.obj.service.views(group=group, profile=profile))
|
|
437
|
+
layout, pattern = _layout(ctx, views, view)
|
|
438
|
+
text = render_report(
|
|
439
|
+
views,
|
|
440
|
+
output_format,
|
|
441
|
+
date_format=pattern,
|
|
442
|
+
fields=layout.list_fields,
|
|
443
|
+
detail=False,
|
|
444
|
+
)
|
|
445
|
+
if output is None:
|
|
446
|
+
sys.stdout.write(text)
|
|
447
|
+
return
|
|
448
|
+
output.write_text(text, encoding="utf-8")
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
@app.command("audit")
|
|
452
|
+
def audit_command(
|
|
453
|
+
ctx: typer.Context,
|
|
454
|
+
output_format: str = typer.Option("table", "--format"),
|
|
455
|
+
fail_on_checks: bool = typer.Option(False, "--fail-on-checks"),
|
|
456
|
+
view: str | None = typer.Option(None, "--view"),
|
|
457
|
+
) -> None:
|
|
458
|
+
"""Show cached check results."""
|
|
459
|
+
|
|
460
|
+
views = _run(ctx.obj.service.views())
|
|
461
|
+
failing = [item for item in views if any(check.failure for check in item.checks)]
|
|
462
|
+
layout, pattern = _layout(ctx, failing, view)
|
|
463
|
+
if output_format == "json":
|
|
464
|
+
typer.echo(
|
|
465
|
+
render_report(
|
|
466
|
+
failing,
|
|
467
|
+
"json",
|
|
468
|
+
date_format=pattern,
|
|
469
|
+
fields=layout.list_fields,
|
|
470
|
+
detail=False,
|
|
471
|
+
),
|
|
472
|
+
nl=False,
|
|
473
|
+
)
|
|
474
|
+
else:
|
|
475
|
+
print_repos(failing, date_format=pattern, fields=layout.list_fields)
|
|
476
|
+
if fail_on_checks and failing:
|
|
477
|
+
raise ChecksFailed(f"{len(failing)} repositories have failing checks.")
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
@app.command("releases")
|
|
481
|
+
def releases_command(ctx: typer.Context) -> None:
|
|
482
|
+
"""Show cached release check results."""
|
|
483
|
+
|
|
484
|
+
_print_named_checks(ctx, "releases")
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
@app.command("workflows")
|
|
488
|
+
def workflows_command(ctx: typer.Context) -> None:
|
|
489
|
+
"""Show cached workflow check results."""
|
|
490
|
+
|
|
491
|
+
_print_named_checks(ctx, "workflows")
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
@cache_app.command("info")
|
|
495
|
+
def cache_info(ctx: typer.Context) -> None:
|
|
496
|
+
"""Show cache size and row counts."""
|
|
497
|
+
|
|
498
|
+
info = _run(ctx.obj.service.cache_info())
|
|
499
|
+
for key, value in info.items():
|
|
500
|
+
stdout_console().print(f"{key}: {value}")
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
@cache_app.command("clear")
|
|
504
|
+
def cache_clear(
|
|
505
|
+
ctx: typer.Context,
|
|
506
|
+
repo: str | None = typer.Option(None, "--repo"),
|
|
507
|
+
yes: bool = typer.Option(False, "--yes"),
|
|
508
|
+
) -> None:
|
|
509
|
+
"""Delete cached data. Interactive runs ask for confirmation."""
|
|
510
|
+
|
|
511
|
+
target = "all cached data" if repo is None else repo
|
|
512
|
+
_confirm(f"Clear {target}?", yes)
|
|
513
|
+
_run(ctx.obj.service.clear_cache(repo))
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
@cache_app.command("vacuum")
|
|
517
|
+
def cache_vacuum(ctx: typer.Context) -> None:
|
|
518
|
+
"""Rebuild the SQLite file."""
|
|
519
|
+
|
|
520
|
+
_run(ctx.obj.service.vacuum())
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
@app.command("reset")
|
|
524
|
+
def reset_command(
|
|
525
|
+
ctx: typer.Context,
|
|
526
|
+
yes: bool = typer.Option(False, "--yes"),
|
|
527
|
+
) -> None:
|
|
528
|
+
"""Delete the cache. Configuration and the repository list stay."""
|
|
529
|
+
|
|
530
|
+
_confirm("Delete the cache? Configuration is kept.", yes)
|
|
531
|
+
removed = _call(ctx.obj.service.reset)
|
|
532
|
+
if removed:
|
|
533
|
+
stdout_console().print(f"Deleted {len(removed)} cache file(s).")
|
|
534
|
+
return
|
|
535
|
+
stdout_console().print("The cache is already empty.")
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
@app.command("tui")
|
|
539
|
+
def tui_command(
|
|
540
|
+
ctx: typer.Context,
|
|
541
|
+
view: str | None = typer.Option(None, "--view"),
|
|
542
|
+
) -> None:
|
|
543
|
+
"""Open the interactive interface."""
|
|
544
|
+
|
|
545
|
+
if view is not None:
|
|
546
|
+
try:
|
|
547
|
+
loaded = ctx.obj.service.load()
|
|
548
|
+
except ConfigError:
|
|
549
|
+
loaded = None # The interface explains a configuration problem.
|
|
550
|
+
if loaded is not None:
|
|
551
|
+
_call(resolve_layout, loaded.config.display, view, [])
|
|
552
|
+
run_tui(ctx.obj.service, view)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def main(argv: list[str] | None = None) -> None:
|
|
556
|
+
"""
|
|
557
|
+
Run the command-line interface.
|
|
558
|
+
|
|
559
|
+
Args:
|
|
560
|
+
argv: Arguments excluding the program name. None reads the process arguments.
|
|
561
|
+
|
|
562
|
+
"""
|
|
563
|
+
|
|
564
|
+
app(args=argv)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
ResultT = TypeVar("ResultT")
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
def _call(func: Callable[..., ResultT], *args: object, **kwargs: object) -> ResultT:
|
|
571
|
+
try:
|
|
572
|
+
return func(*args, **kwargs)
|
|
573
|
+
except IntelError as exc:
|
|
574
|
+
stderr_console().print(str(exc))
|
|
575
|
+
raise typer.Exit(code=exc.exit_code) from exc
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
def _run(coro: Coroutine[Any, Any, ResultT]) -> ResultT:
|
|
579
|
+
try:
|
|
580
|
+
return asyncio.run(coro)
|
|
581
|
+
except IntelError as exc:
|
|
582
|
+
stderr_console().print(str(exc))
|
|
583
|
+
raise typer.Exit(code=exc.exit_code) from exc
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def _layout(
|
|
587
|
+
ctx: typer.Context,
|
|
588
|
+
views: list[Any],
|
|
589
|
+
view: str | None,
|
|
590
|
+
) -> tuple[Layout, str]:
|
|
591
|
+
loaded = _call(ctx.obj.service.load)
|
|
592
|
+
name = view or loaded.config.display.view
|
|
593
|
+
layout = _call(resolve_layout, loaded.config.display, name, views)
|
|
594
|
+
return layout, loaded.config.display.date_format
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
def _emit_views(
|
|
598
|
+
views: list[Any],
|
|
599
|
+
output_format: str,
|
|
600
|
+
date_format: str,
|
|
601
|
+
layout: Layout,
|
|
602
|
+
) -> None:
|
|
603
|
+
if output_format in {"json", "csv", "markdown"}:
|
|
604
|
+
sys.stdout.write(
|
|
605
|
+
render_report(
|
|
606
|
+
views,
|
|
607
|
+
output_format,
|
|
608
|
+
date_format=date_format,
|
|
609
|
+
fields=layout.list_fields,
|
|
610
|
+
detail=False,
|
|
611
|
+
),
|
|
612
|
+
)
|
|
613
|
+
return
|
|
614
|
+
print_repos(views, date_format=date_format, fields=layout.list_fields)
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
def _render_show(
|
|
618
|
+
shown: RepositoryView,
|
|
619
|
+
output_format: str,
|
|
620
|
+
date_format: str,
|
|
621
|
+
fields: tuple[str, ...] | None,
|
|
622
|
+
) -> str:
|
|
623
|
+
if fields is None:
|
|
624
|
+
return _format_detail_pairs(
|
|
625
|
+
detail_rows(shown, date_format=date_format),
|
|
626
|
+
output_format,
|
|
627
|
+
)
|
|
628
|
+
return render_report(
|
|
629
|
+
[shown],
|
|
630
|
+
output_format,
|
|
631
|
+
date_format=date_format,
|
|
632
|
+
fields=fields,
|
|
633
|
+
detail=True,
|
|
634
|
+
)
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def _format_detail_pairs(
|
|
638
|
+
pairs: tuple[tuple[str, str], ...],
|
|
639
|
+
output_format: str,
|
|
640
|
+
) -> str:
|
|
641
|
+
record = dict(pairs)
|
|
642
|
+
if output_format == "json":
|
|
643
|
+
return json.dumps(record, indent=2) + "\n"
|
|
644
|
+
buffer = io.StringIO()
|
|
645
|
+
writer = csv.DictWriter(buffer, fieldnames=list(record))
|
|
646
|
+
writer.writeheader()
|
|
647
|
+
writer.writerow(record)
|
|
648
|
+
return buffer.getvalue()
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
def _sort(views: list[Any], key: str) -> list[Any]:
|
|
652
|
+
if key == "group":
|
|
653
|
+
return sorted(views, key=lambda view: (view.group, view.repo))
|
|
654
|
+
if key == "profile":
|
|
655
|
+
return sorted(views, key=lambda view: (view.profile, view.repo))
|
|
656
|
+
if key == "updated":
|
|
657
|
+
return sorted(views, key=lambda view: (view.updated_at or 0, view.repo))
|
|
658
|
+
return sorted(views, key=lambda view: view.repo.casefold())
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def _finish_sync(report: SyncReport, fail_on_checks: bool) -> None:
|
|
662
|
+
if report.auth_failed and report.successful == 0:
|
|
663
|
+
raise AuthError("GitHub rejected the credentials.")
|
|
664
|
+
if report.cancelled or report.failed:
|
|
665
|
+
raise SyncIncomplete("Synchronisation did not finish cleanly.")
|
|
666
|
+
if fail_on_checks and report.check_failures:
|
|
667
|
+
raise ChecksFailed(f"{report.check_failures} checks failed.")
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
def _identifier(org: str, name: str | None) -> str:
|
|
671
|
+
if name:
|
|
672
|
+
return f"{org}/{name}"
|
|
673
|
+
if "/" in org:
|
|
674
|
+
return org
|
|
675
|
+
message = "Pass the organisation and the repository name."
|
|
676
|
+
raise typer.BadParameter(message)
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
def _print_named_checks(ctx: typer.Context, name: str) -> None:
|
|
680
|
+
views = _run(ctx.obj.service.views())
|
|
681
|
+
for view in views:
|
|
682
|
+
for item in view.checks:
|
|
683
|
+
if item.name == name:
|
|
684
|
+
stdout_console().print(f"{view.repo}: {item.status} — {item.summary}")
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
def _confirm(message: str, yes: bool) -> None:
|
|
688
|
+
if yes:
|
|
689
|
+
return
|
|
690
|
+
if not sys.stdin.isatty():
|
|
691
|
+
stderr_console().print(f"{message} Re-run with --yes.")
|
|
692
|
+
raise typer.Exit(code=2)
|
|
693
|
+
answer = input(f"{message} [y/N] ")
|
|
694
|
+
if answer.strip().casefold() != "y":
|
|
695
|
+
raise typer.Exit(code=2)
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
if __name__ == "__main__":
|
|
699
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Configuration loading, profiles, and repository edits."""
|