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.
Files changed (41) hide show
  1. lupaxa/github_intel/__init__.py +13 -0
  2. lupaxa/github_intel/__main__.py +8 -0
  3. lupaxa/github_intel/app.py +493 -0
  4. lupaxa/github_intel/checks/__init__.py +1 -0
  5. lupaxa/github_intel/checks/base.py +17 -0
  6. lupaxa/github_intel/checks/releases.py +59 -0
  7. lupaxa/github_intel/checks/workflows.py +34 -0
  8. lupaxa/github_intel/cli.py +699 -0
  9. lupaxa/github_intel/config/__init__.py +1 -0
  10. lupaxa/github_intel/config/defaults.py +150 -0
  11. lupaxa/github_intel/config/editor.py +316 -0
  12. lupaxa/github_intel/config/loader.py +412 -0
  13. lupaxa/github_intel/config/models.py +310 -0
  14. lupaxa/github_intel/config/paths.py +84 -0
  15. lupaxa/github_intel/config/profiles.py +143 -0
  16. lupaxa/github_intel/constants.py +54 -0
  17. lupaxa/github_intel/dates.py +179 -0
  18. lupaxa/github_intel/errors.py +72 -0
  19. lupaxa/github_intel/github/__init__.py +1 -0
  20. lupaxa/github_intel/github/auth.py +40 -0
  21. lupaxa/github_intel/github/client.py +239 -0
  22. lupaxa/github_intel/github/rate_limit.py +107 -0
  23. lupaxa/github_intel/layout.py +141 -0
  24. lupaxa/github_intel/logging_setup.py +51 -0
  25. lupaxa/github_intel/present.py +361 -0
  26. lupaxa/github_intel/reports/__init__.py +1 -0
  27. lupaxa/github_intel/reports/render.py +113 -0
  28. lupaxa/github_intel/storage/__init__.py +1 -0
  29. lupaxa/github_intel/storage/database.py +419 -0
  30. lupaxa/github_intel/sync/__init__.py +1 -0
  31. lupaxa/github_intel/sync/engine.py +671 -0
  32. lupaxa/github_intel/sync/summary.py +308 -0
  33. lupaxa/github_intel/tui/__init__.py +1 -0
  34. lupaxa/github_intel/tui/application.py +487 -0
  35. lupaxa/github_intel/views.py +896 -0
  36. lupaxa_github_intel-0.1.0.dist-info/METADATA +180 -0
  37. lupaxa_github_intel-0.1.0.dist-info/RECORD +41 -0
  38. lupaxa_github_intel-0.1.0.dist-info/WHEEL +5 -0
  39. lupaxa_github_intel-0.1.0.dist-info/entry_points.txt +2 -0
  40. lupaxa_github_intel-0.1.0.dist-info/licenses/LICENCE +21 -0
  41. lupaxa_github_intel-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,308 @@
1
+ """Values shown beside each repository in the list."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from lupaxa.github_intel.dates import normalize_instant
8
+
9
+ __all__ = [
10
+ "ahead_count",
11
+ "codeql_reading",
12
+ "collection_count",
13
+ "dependabot_reading",
14
+ "format_count",
15
+ "issue_count",
16
+ "latest_published",
17
+ "latest_tag",
18
+ "workflow_activity",
19
+ "workflow_definitions",
20
+ "workflow_label",
21
+ ]
22
+
23
+ _LAST_PAGE = re.compile(r"""[?&]page=(\d+)[^>]*>;\s*rel="last\"""")
24
+
25
+
26
+ def latest_published(body: object) -> str:
27
+ """
28
+ Return the publish time of the newest published release.
29
+
30
+ Args:
31
+ body: Release list from GitHub, newest first.
32
+
33
+ Returns:
34
+ An ISO instant, or an empty string when no published release exists.
35
+
36
+ """
37
+
38
+ if not isinstance(body, list):
39
+ return ""
40
+ for item in body:
41
+ if not isinstance(item, dict) or item.get("draft"):
42
+ continue
43
+ return normalize_instant(item.get("published_at"))
44
+ return ""
45
+
46
+
47
+ def latest_tag(body: object) -> str:
48
+ """
49
+ Return the newest published release tag.
50
+
51
+ Args:
52
+ body: Release list from GitHub, newest first.
53
+
54
+ Returns:
55
+ Tag text, or an empty string when no published release exists.
56
+
57
+ """
58
+
59
+ if not isinstance(body, list):
60
+ return ""
61
+ for item in body:
62
+ if not isinstance(item, dict) or item.get("draft"):
63
+ continue
64
+ tag = item.get("tag_name")
65
+ return tag if isinstance(tag, str) else ""
66
+ return ""
67
+
68
+
69
+ def collection_count(*, body: object, link: str | None, failed: bool) -> int | None:
70
+ """
71
+ Return how many items a one-item page represents.
72
+
73
+ Args:
74
+ body: JSON list from the first page.
75
+ link: Value of the Link header, if GitHub sent one.
76
+ failed: The request did not succeed.
77
+
78
+ Returns:
79
+ The collection size, or None when it cannot be known.
80
+
81
+ """
82
+
83
+ if failed or not isinstance(body, list):
84
+ return None
85
+ if link:
86
+ match = _LAST_PAGE.search(link)
87
+ if match:
88
+ return int(match.group(1))
89
+ if 'rel="next"' in link:
90
+ return None
91
+ return len(body)
92
+
93
+
94
+ def codeql_reading(
95
+ *,
96
+ status: int,
97
+ error: str | None,
98
+ body: object,
99
+ link: str | None,
100
+ ) -> tuple[int | None, str]:
101
+ """
102
+ Return the open CodeQL count, or a short reason when it is missing.
103
+
104
+ Args:
105
+ status: HTTP status. Zero means the request did not complete.
106
+ error: Client error text, or None for a successful response.
107
+ body: JSON body from a successful response.
108
+ link: Link header from a successful response.
109
+
110
+ Returns:
111
+ The count and an empty reason, or None and ``No scanning``,
112
+ ``Forbidden``, or ``Unknown``.
113
+
114
+ """
115
+
116
+ if error is None:
117
+ count = collection_count(body=body, link=link, failed=False)
118
+ if count is None:
119
+ return None, "Unknown"
120
+ return count, ""
121
+ folded = error.casefold()
122
+ if status == 404 or _scanning_is_off(folded):
123
+ return None, "No scanning"
124
+ if status in {401, 403}:
125
+ return None, "Forbidden"
126
+ return None, "Unknown"
127
+
128
+
129
+ def dependabot_reading(
130
+ *,
131
+ status: int,
132
+ error: str | None,
133
+ body: object,
134
+ link: str | None,
135
+ ) -> tuple[int | None, str]:
136
+ """
137
+ Return the open Dependabot count, or a short reason when it is missing.
138
+
139
+ Args:
140
+ status: HTTP status. Zero means the request did not complete.
141
+ error: Client error text, or None for a successful response.
142
+ body: JSON body from a successful response.
143
+ link: Link header from a successful response.
144
+
145
+ Returns:
146
+ The count and an empty reason, or None and ``Disabled``,
147
+ ``Forbidden``, or ``Unknown``.
148
+
149
+ """
150
+
151
+ if error is None:
152
+ count = collection_count(body=body, link=link, failed=False)
153
+ if count is None:
154
+ return None, "Unknown"
155
+ return count, ""
156
+ folded = error.casefold()
157
+ if "disabled" in folded or "not enabled" in folded or "must be enabled" in folded:
158
+ return None, "Disabled"
159
+ if status in {401, 403, 404}:
160
+ return None, "Forbidden"
161
+ return None, "Unknown"
162
+
163
+
164
+ def _scanning_is_off(message: str) -> bool:
165
+ return any(
166
+ phrase in message
167
+ for phrase in (
168
+ "no analysis",
169
+ "not enabled",
170
+ "must be enabled",
171
+ "advanced security",
172
+ "code security",
173
+ )
174
+ )
175
+
176
+
177
+ def issue_count(open_issues_count: object) -> int | None:
178
+ """
179
+ Return GitHub's open issue total.
180
+
181
+ Args:
182
+ open_issues_count: Repository field. GitHub includes open pull requests.
183
+
184
+ Returns:
185
+ That total, or None when GitHub did not send a count.
186
+
187
+ """
188
+
189
+ if isinstance(open_issues_count, bool) or not isinstance(open_issues_count, int):
190
+ return None
191
+ return open_issues_count
192
+
193
+
194
+ def ahead_count(body: object) -> int | None:
195
+ """
196
+ Return commits on the default branch that are not in the release.
197
+
198
+ Args:
199
+ body: Compare payload from GitHub.
200
+
201
+ Returns:
202
+ The ahead count, or None when GitHub did not report one.
203
+
204
+ """
205
+
206
+ if not isinstance(body, dict):
207
+ return None
208
+ value = body.get("ahead_by")
209
+ if isinstance(value, bool) or not isinstance(value, int):
210
+ return None
211
+ return value
212
+
213
+
214
+ def workflow_activity(state: object) -> str:
215
+ """
216
+ Return a display label for a workflow list entry.
217
+
218
+ Args:
219
+ state: GitHub workflow ``state``.
220
+
221
+ Returns:
222
+ ``Active``, a specific disabled reason, the state's own words, or
223
+ ``Unknown`` when GitHub sent no state.
224
+
225
+ """
226
+
227
+ text = str(state or "").strip().casefold()
228
+ if text == "active":
229
+ return "Active"
230
+ if text.startswith("disabled_"):
231
+ reason = text.removeprefix("disabled_").replace("_", " ").title()
232
+ return f"{reason} Disabled"
233
+ if text == "disabled":
234
+ return "Disabled"
235
+ if not text:
236
+ return "Unknown"
237
+ return text.replace("_", " ").title()
238
+
239
+
240
+ def workflow_definitions(items: object) -> tuple[tuple[str, str], ...]:
241
+ """
242
+ Return each workflow's name and activity.
243
+
244
+ Args:
245
+ items: The ``workflows`` array from GitHub.
246
+
247
+ Returns:
248
+ Name and activity pairs, sorted by name.
249
+
250
+ """
251
+
252
+ if not isinstance(items, list):
253
+ return ()
254
+ found: list[tuple[str, str]] = []
255
+ for item in items:
256
+ if not isinstance(item, dict):
257
+ continue
258
+ name = item.get("name")
259
+ if not isinstance(name, str) or name == "":
260
+ path = item.get("path")
261
+ workflow_id = item.get("id")
262
+ if isinstance(path, str) and path:
263
+ name = path
264
+ elif isinstance(workflow_id, int) and not isinstance(workflow_id, bool):
265
+ name = f"Workflow {workflow_id}"
266
+ else:
267
+ continue
268
+ found.append((name, workflow_activity(item.get("state"))))
269
+ found.sort(key=lambda item: item[0].casefold())
270
+ return tuple(found)
271
+
272
+
273
+ def workflow_label(body: object, *, failed: bool) -> str:
274
+ """
275
+ Return the workflow-list headline from a stored workflow payload.
276
+
277
+ Args:
278
+ body: Workflow list payload.
279
+ failed: The request did not succeed.
280
+
281
+ Returns:
282
+ ``Listed``, ``No workflows``, or an empty string.
283
+
284
+ """
285
+
286
+ if failed or not isinstance(body, dict):
287
+ return ""
288
+ pairs = workflow_definitions(body.get("workflows"))
289
+ if not pairs:
290
+ return "No workflows"
291
+ return "Listed"
292
+
293
+
294
+ def format_count(value: int | None) -> str:
295
+ """
296
+ Format a count for a table cell.
297
+
298
+ Args:
299
+ value: Count, or None when it is unknown.
300
+
301
+ Returns:
302
+ Decimal text, or an empty string.
303
+
304
+ """
305
+
306
+ if value is None:
307
+ return ""
308
+ return str(value)
@@ -0,0 +1 @@
1
+ """Interactive terminal interface."""