github-statistics 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 (86) hide show
  1. github_statistics/__init__.py +14 -0
  2. github_statistics/__main__.py +10 -0
  3. github_statistics/_version.py +24 -0
  4. github_statistics/cli/__init__.py +9 -0
  5. github_statistics/cli/app.py +104 -0
  6. github_statistics/cli/cache.py +159 -0
  7. github_statistics/cli/collect.py +219 -0
  8. github_statistics/cli/common.py +128 -0
  9. github_statistics/cli/config.py +80 -0
  10. github_statistics/cli/doctor.py +214 -0
  11. github_statistics/cli/export.py +111 -0
  12. github_statistics/cli/options.py +175 -0
  13. github_statistics/cli/render.py +126 -0
  14. github_statistics/cli/run.py +137 -0
  15. github_statistics/cli/scope.py +96 -0
  16. github_statistics/cli/site.py +150 -0
  17. github_statistics/client/__init__.py +40 -0
  18. github_statistics/client/accounting.py +99 -0
  19. github_statistics/client/budget.py +125 -0
  20. github_statistics/client/cooldown.py +113 -0
  21. github_statistics/client/errors.py +60 -0
  22. github_statistics/client/graphql.py +281 -0
  23. github_statistics/client/paging.py +92 -0
  24. github_statistics/client/policy.py +243 -0
  25. github_statistics/client/transport.py +437 -0
  26. github_statistics/collect/__init__.py +44 -0
  27. github_statistics/collect/common.py +69 -0
  28. github_statistics/collect/enrich_items.py +423 -0
  29. github_statistics/collect/items.py +238 -0
  30. github_statistics/collect/jobs.py +194 -0
  31. github_statistics/collect/listed.py +42 -0
  32. github_statistics/collect/members.py +70 -0
  33. github_statistics/collect/reader.py +124 -0
  34. github_statistics/collect/run.py +354 -0
  35. github_statistics/collect/runs.py +436 -0
  36. github_statistics/collect/slices.py +55 -0
  37. github_statistics/collect/steps.py +154 -0
  38. github_statistics/collect/sweep.py +70 -0
  39. github_statistics/config/__init__.py +37 -0
  40. github_statistics/config/loader.py +430 -0
  41. github_statistics/config/models.py +156 -0
  42. github_statistics/config/schema.py +245 -0
  43. github_statistics/export/__init__.py +11 -0
  44. github_statistics/export/csv.py +93 -0
  45. github_statistics/export/documents.py +189 -0
  46. github_statistics/export/json.py +33 -0
  47. github_statistics/py.typed +2 -0
  48. github_statistics/render/__init__.py +44 -0
  49. github_statistics/render/bars3d.py +420 -0
  50. github_statistics/render/charts.py +214 -0
  51. github_statistics/render/demo.py +133 -0
  52. github_statistics/render/images.py +31 -0
  53. github_statistics/render/layout.py +341 -0
  54. github_statistics/render/model.py +260 -0
  55. github_statistics/render/palette.py +41 -0
  56. github_statistics/scope/__init__.py +17 -0
  57. github_statistics/scope/apply.py +95 -0
  58. github_statistics/scope/resolver.py +228 -0
  59. github_statistics/series/__init__.py +22 -0
  60. github_statistics/series/actors.py +128 -0
  61. github_statistics/series/coverage.py +86 -0
  62. github_statistics/series/daily.py +229 -0
  63. github_statistics/series/leaderboard.py +221 -0
  64. github_statistics/series/repositories.py +154 -0
  65. github_statistics/site/__init__.py +9 -0
  66. github_statistics/site/assets/site.css +281 -0
  67. github_statistics/site/build.py +392 -0
  68. github_statistics/site/templates/base.html.j2 +25 -0
  69. github_statistics/site/templates/index.html.j2 +30 -0
  70. github_statistics/site/templates/macros.html.j2 +5 -0
  71. github_statistics/site/templates/site.js.j2 +66 -0
  72. github_statistics/site/templates/target.html.j2 +95 -0
  73. github_statistics/store/__init__.py +40 -0
  74. github_statistics/store/activity.py +311 -0
  75. github_statistics/store/aggregates.py +294 -0
  76. github_statistics/store/base.py +163 -0
  77. github_statistics/store/codec.py +263 -0
  78. github_statistics/store/models.py +136 -0
  79. github_statistics/store/paths.py +36 -0
  80. github_statistics/store/schema.py +169 -0
  81. github_statistics/store/sqlite.py +299 -0
  82. github_statistics-0.1.0.dist-info/METADATA +308 -0
  83. github_statistics-0.1.0.dist-info/RECORD +86 -0
  84. github_statistics-0.1.0.dist-info/WHEEL +4 -0
  85. github_statistics-0.1.0.dist-info/entry_points.txt +2 -0
  86. github_statistics-0.1.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,260 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """Plain data the chart renderer draws from, and the style it draws with.
4
+
5
+ Everything here is a frozen dataclass: the renderer reads no store, no
6
+ network and no global state, so a chart is a pure function of its
7
+ :class:`ChartSpec` and :class:`Style`.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import re
13
+ from dataclasses import dataclass
14
+ from datetime import date, timedelta
15
+ from enum import StrEnum
16
+ from pathlib import Path
17
+
18
+ from . import palette
19
+
20
+ _HEX_COLOUR = re.compile(r"^#[0-9A-Fa-f]{6}$")
21
+
22
+
23
+ class Coverage(StrEnum):
24
+ """How completely the store covers one day."""
25
+
26
+ COMPLETE = "complete"
27
+ PARTIAL = "partial"
28
+ NONE = "none"
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class Series:
33
+ """One row of bars: a daily count with its legend text and colour."""
34
+
35
+ key: str
36
+ label: str
37
+ colour: str
38
+ values: tuple[int, ...]
39
+
40
+ def __post_init__(self) -> None:
41
+ """Reject a malformed colour or a negative count."""
42
+ if not _HEX_COLOUR.match(self.colour):
43
+ raise ValueError(f"series {self.key!r}: colour must be #RRGGBB")
44
+ if any(value < 0 for value in self.values):
45
+ raise ValueError(f"series {self.key!r}: values must not be negative")
46
+
47
+
48
+ @dataclass(frozen=True)
49
+ class ChartSpec:
50
+ """Everything one chart shows: two series over consecutive UTC days."""
51
+
52
+ title: str
53
+ subtitle: str
54
+ footer: str
55
+ days: tuple[date, ...]
56
+ first: Series
57
+ second: Series
58
+ coverage: tuple[Coverage, ...]
59
+ back_on_tie: str
60
+
61
+ def __post_init__(self) -> None:
62
+ """Check that the days, values and coverage line up."""
63
+ count = len(self.days)
64
+ if count == 0:
65
+ raise ValueError("a chart needs at least one day")
66
+ for name, length in (
67
+ (self.first.key, len(self.first.values)),
68
+ (self.second.key, len(self.second.values)),
69
+ ("coverage", len(self.coverage)),
70
+ ):
71
+ if length != count:
72
+ raise ValueError(f"{name}: {length} entries for {count} days")
73
+ if self.first.key == self.second.key:
74
+ raise ValueError("the two series need distinct keys")
75
+ if self.back_on_tie not in (self.first.key, self.second.key):
76
+ raise ValueError(f"back_on_tie {self.back_on_tie!r} names neither series")
77
+ one_day = timedelta(days=1)
78
+ for earlier, later in zip(self.days, self.days[1:], strict=False):
79
+ if later - earlier != one_day:
80
+ raise ValueError(f"days are not consecutive at {later.isoformat()}")
81
+
82
+
83
+ @dataclass(frozen=True)
84
+ class Style:
85
+ """Every tunable number and colour of the chart.
86
+
87
+ Geometry is in design pixels on a ``canvas_width`` by
88
+ ``canvas_height`` canvas. ``dpi`` sets only the raster size: the
89
+ master is 3840x2160 at 240 dpi, and a lower ``dpi`` renders the same
90
+ picture smaller.
91
+ """
92
+
93
+ canvas_width: int = 3840
94
+ canvas_height: int = 2160
95
+ reference_dpi: int = 240
96
+ dpi: int = 240
97
+
98
+ margin_left: float = 280.0
99
+ margin_right: float = 210.0
100
+ margin_bottom: float = 300.0
101
+ margin_top: float = 350.0
102
+
103
+ bar_width: float = 0.62
104
+ depth_x: float = 0.75
105
+ depth_y: float = 0.45
106
+ # Short windows have a wide pitch; capping the pitch the depth vector
107
+ # follows keeps the floor and wall inside the right margin.
108
+ max_depth_pitch: float = 64.0
109
+ floor_depth: float = 2.8
110
+ target_ticks: int = 6
111
+
112
+ side_shade: float = 0.74
113
+ top_shade: float = 1.22
114
+ front_shade: float = 1.0
115
+ edge_shade: float = 0.62
116
+ edge_width_px: float = 0.5
117
+
118
+ shadow_rgba: tuple[float, float, float, float] = (0.1, 0.12, 0.18, 0.16)
119
+ shadow_ratio: float = 0.09
120
+ shadow_max_pitch: float = 2.5
121
+
122
+ gap_hatch: str = "////"
123
+ gap_alpha: float = 0.32
124
+ hatch_width_pt: float = 0.6
125
+ gridline_width_px: float = 2.0
126
+ separator_width_px: float = 2.0
127
+
128
+ text_x: float = 120.0
129
+ title_y: float = 2070.0
130
+ subtitle_y: float = 1960.0
131
+ footer_y: float = 70.0
132
+ legend_x: float = 3200.0
133
+ legend_y: float = 2010.0
134
+ legend_step: float = 64.0
135
+ month_label_gap: float = 26.0
136
+ tick_label_gap: float = 16.0
137
+ annotation_gap: float = 40.0
138
+
139
+ title_pt: float = 20.0
140
+ subtitle_pt: float = 9.0
141
+ footer_pt: float = 7.0
142
+ legend_pt: float = 9.0
143
+ month_pt: float = 8.0
144
+ tick_pt: float = 8.0
145
+ annotation_pt: float = 8.0
146
+
147
+ background: str = palette.BACKGROUND
148
+ floor: str = palette.FLOOR
149
+ wall: str = palette.WALL
150
+ gridline: str = palette.GRIDLINE
151
+ separator: str = palette.SEPARATOR
152
+ text: str = palette.TEXT
153
+ muted: str = palette.MUTED
154
+ no_data: str = palette.NO_DATA
155
+ partial_data: str = palette.PARTIAL_DATA
156
+ font_family: str = "DejaVu Sans"
157
+
158
+
159
+ @dataclass(frozen=True)
160
+ class Bar:
161
+ """One day's value of one series, placed in the front or back row."""
162
+
163
+ day: int
164
+ series: str
165
+ value: int
166
+
167
+
168
+ @dataclass(frozen=True)
169
+ class GapSpan:
170
+ """A run of consecutive days, ``start`` to ``stop`` exclusive, sharing a gap coverage."""
171
+
172
+ start: int
173
+ stop: int
174
+ coverage: Coverage
175
+
176
+
177
+ @dataclass(frozen=True)
178
+ class MonthLabel:
179
+ """A ``Mon YYYY`` label centred at ``centre``, measured in days from the first bar."""
180
+
181
+ centre: float
182
+ text: str
183
+
184
+
185
+ @dataclass(frozen=True)
186
+ class Peak:
187
+ """The highest day of a series and the row its bar stands in (1 is back)."""
188
+
189
+ series: str
190
+ day: int
191
+ value: int
192
+ row: int
193
+
194
+
195
+ @dataclass(frozen=True)
196
+ class Box:
197
+ """An axis-aligned rectangle in design pixels, ``x0 <= x1`` and ``y0 <= y1``."""
198
+
199
+ x0: float
200
+ y0: float
201
+ x1: float
202
+ y1: float
203
+
204
+ def overlaps(self, other: Box) -> bool:
205
+ """Whether this box and ``other`` share any area."""
206
+ return (
207
+ self.x0 < other.x1
208
+ and other.x0 < self.x1
209
+ and self.y0 < other.y1
210
+ and other.y0 < self.y1
211
+ )
212
+
213
+
214
+ @dataclass(frozen=True)
215
+ class PeakLabel:
216
+ """A peak annotation: its text, bottom-centre anchor and estimated bounds."""
217
+
218
+ series: str
219
+ text: str
220
+ x: float
221
+ y: float
222
+ box: Box
223
+
224
+
225
+ @dataclass(frozen=True)
226
+ class ChartPlan:
227
+ """The computed layout of a chart, independent of pixels.
228
+
229
+ ``back`` and ``front`` hold one bar per day, gap days included;
230
+ the renderer skips gap days and zero values when drawing.
231
+ """
232
+
233
+ back: tuple[Bar, ...]
234
+ front: tuple[Bar, ...]
235
+ ticks: tuple[int, ...]
236
+ gaps: tuple[GapSpan, ...]
237
+ month_starts: tuple[int, ...]
238
+ month_labels: tuple[MonthLabel, ...]
239
+ peaks: tuple[Peak, ...]
240
+ legend: tuple[str, ...]
241
+
242
+ @property
243
+ def y_max(self) -> int:
244
+ """The top tick, which the vertical scale maps to the wall's top."""
245
+ return self.ticks[-1]
246
+
247
+
248
+ @dataclass(frozen=True)
249
+ class RenderedChart:
250
+ """What :func:`render_chart` wrote and what it drew."""
251
+
252
+ path: Path
253
+ width: int
254
+ height: int
255
+ plan: ChartPlan
256
+ bar_polygons: int
257
+ gap_slabs: int
258
+ legend: tuple[str, ...]
259
+ legend_box: Box
260
+ peak_labels: tuple[PeakLabel, ...]
@@ -0,0 +1,41 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """Default colours for charts: Okabe-Ito series colours and chart furniture.
4
+
5
+ The series colours are colour-blind safe and stay distinct when two
6
+ series swap rows, which is how a chart shows that the smaller value of
7
+ a day changed hands.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from types import MappingProxyType
13
+
14
+ SERIES_COLOURS = MappingProxyType(
15
+ {
16
+ "opened": "#0072B2",
17
+ "closed": "#E69F00",
18
+ "runs": "#009E73",
19
+ "jobs": "#CC79A7",
20
+ "succeeded": "#009E73",
21
+ "failed": "#D55E00",
22
+ }
23
+ )
24
+
25
+ BACKGROUND = "#F6F7F9"
26
+ FLOOR = "#E3E7ED"
27
+ WALL = "#ECEFF3"
28
+ GRIDLINE = "#FFFFFF"
29
+ SEPARATOR = "#C9D0DA"
30
+ TEXT = "#2B3140"
31
+ MUTED = "#6B7280"
32
+ NO_DATA = "#7C8594"
33
+ PARTIAL_DATA = "#A9B0BC"
34
+
35
+
36
+ def series_colour(key: str) -> str:
37
+ """Return the default colour for the series named ``key``."""
38
+ try:
39
+ return SERIES_COLOURS[key]
40
+ except KeyError:
41
+ raise KeyError(f"no default colour for series {key!r}") from None
@@ -0,0 +1,17 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """Scope resolution: targets to public repositories, and the store side (design §5)."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from .apply import ScopeChanges, apply_scope
8
+ from .resolver import Dropped, Repository, ResolvedScope, resolve_scope
9
+
10
+ __all__ = [
11
+ "Dropped",
12
+ "Repository",
13
+ "ResolvedScope",
14
+ "ScopeChanges",
15
+ "apply_scope",
16
+ "resolve_scope",
17
+ ]
@@ -0,0 +1,95 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """Record a resolved scope in the store (design §5, §6.1).
4
+
5
+ Store keys are ``owner/name``. A repository dropped as ``not public``
6
+ or ``not found`` is purged: a token that cannot see a private
7
+ repository gets a ``404`` for it, so ``not found`` cannot be told apart
8
+ from a repository that turned private.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from dataclasses import dataclass
14
+ from datetime import date
15
+
16
+ from github_statistics.store import Store
17
+
18
+ from .resolver import NOT_FOUND, NOT_PUBLIC, ResolvedScope
19
+
20
+ PURGED_REASONS = frozenset({NOT_PUBLIC, NOT_FOUND})
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class ScopeChanges:
25
+ """What `apply_scope` did, each as sorted ``owner/name`` keys.
26
+
27
+ ``untouched`` holds repositories in scope before whose fate the
28
+ resolver could not determine; they stay as they were.
29
+ """
30
+
31
+ entered: tuple[str, ...]
32
+ left: tuple[str, ...]
33
+ purged: tuple[str, ...]
34
+ untouched: tuple[str, ...]
35
+
36
+
37
+ def apply_scope(
38
+ store: Store, scope: ResolvedScope, *, today: date, window_start: date
39
+ ) -> ScopeChanges:
40
+ """Bring the store's scope table in line with ``scope``.
41
+
42
+ A repository never seen before enters from ``window_start`` or its
43
+ creation day, whichever is later, so its backfilled history counts;
44
+ one that returns enters from ``today``. One in scope before that
45
+ ``scope`` drops leaves from ``today`` and keeps its history, unless
46
+ it is dropped as ``not public`` or ``not found``: then every row it
47
+ has is purged, under every spelling of its name the store holds,
48
+ since names compare without case. One in scope before
49
+ that ``scope`` neither keeps nor drops is left untouched and
50
+ reported. Pass ``store.stored_repositories()`` to
51
+ ``resolve_scope(known=...)`` so it accounts for each.
52
+ """
53
+ owner = scope.owner
54
+ current = {repo.lower(): repo for repo in store.in_scope(today)}
55
+ spellings: dict[str, set[str]] = {}
56
+ for repo in store.stored_repositories():
57
+ spellings.setdefault(repo.lower(), set()).add(repo)
58
+ entered: list[str] = []
59
+ kept: set[str] = set()
60
+ for repository in scope.repositories:
61
+ key = f"{owner}/{repository.name}"
62
+ kept.add(key.lower())
63
+ if key.lower() in current:
64
+ continue
65
+ created = date.fromisoformat(repository.created_at[:10])
66
+ start = today if key.lower() in spellings else max(window_start, created)
67
+ store.enter_scope(key, start)
68
+ entered.append(key)
69
+
70
+ reasons = {f"{owner}/{drop.name}".lower(): drop.reason for drop in scope.dropped}
71
+ purged: list[str] = []
72
+ for drop in scope.dropped:
73
+ if drop.reason in PURGED_REASONS:
74
+ key = f"{owner}/{drop.name}"
75
+ for spelling in sorted(spellings.get(key.lower(), set()) | {key}):
76
+ store.purge_repository(spelling)
77
+ purged.append(key)
78
+
79
+ left: list[str] = []
80
+ untouched: list[str] = []
81
+ for lowered, key in current.items():
82
+ if lowered in kept:
83
+ continue
84
+ reason = reasons.get(lowered)
85
+ if reason is None:
86
+ untouched.append(key)
87
+ elif reason not in PURGED_REASONS:
88
+ store.leave_scope(key, today)
89
+ left.append(key)
90
+ return ScopeChanges(
91
+ entered=tuple(sorted(entered)),
92
+ left=tuple(sorted(left)),
93
+ purged=tuple(sorted(purged)),
94
+ untouched=tuple(sorted(untouched)),
95
+ )
@@ -0,0 +1,228 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """Turn a target into the public repositories to read (design §5).
4
+
5
+ The resolver is where the privacy rule for repositories holds: every
6
+ repository whose ``visibility`` is not ``public``, listed or named, is
7
+ dropped with the reason ``not public``, and no option relaxes this.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import logging
13
+ from collections.abc import Iterable
14
+ from dataclasses import dataclass
15
+ from fnmatch import fnmatchcase
16
+ from typing import Any
17
+ from urllib.parse import quote
18
+
19
+ import httpx
20
+
21
+ from github_statistics.client import Transport, TransportError, get_paged
22
+ from github_statistics.config import Target
23
+
24
+ log = logging.getLogger(__name__)
25
+
26
+ NOT_PUBLIC = "not public"
27
+ ARCHIVED = "archived"
28
+ FORK = "fork"
29
+ TEMPLATE = "template"
30
+ EXCLUDED = "excluded"
31
+ NOT_INCLUDED = "not included"
32
+ NOT_FOUND = "not found"
33
+
34
+ _GLOB_CHARACTERS = frozenset("*?[")
35
+
36
+
37
+ @dataclass(frozen=True)
38
+ class Repository:
39
+ """One public repository in scope."""
40
+
41
+ name: str
42
+ created_at: str
43
+ archived: bool
44
+ fork: bool
45
+ is_template: bool
46
+ default_branch: str
47
+
48
+
49
+ @dataclass(frozen=True)
50
+ class Dropped:
51
+ """A repository left out of scope, and why."""
52
+
53
+ name: str
54
+ reason: str
55
+
56
+
57
+ @dataclass(frozen=True)
58
+ class ResolvedScope:
59
+ """The repositories one target resolves to.
60
+
61
+ ``repositories`` and ``dropped`` are sorted by name. ``unresolved``
62
+ names the repositories whose read failed, so their fate is unknown.
63
+ """
64
+
65
+ owner: str
66
+ owner_type: str
67
+ repositories: tuple[Repository, ...]
68
+ dropped: tuple[Dropped, ...]
69
+ unresolved: tuple[str, ...] = ()
70
+
71
+
72
+ def is_exact(entry: str) -> bool:
73
+ """Whether ``entry`` names one repository rather than a glob."""
74
+ return not _GLOB_CHARACTERS.intersection(entry)
75
+
76
+
77
+ def _path(*parts: str) -> str:
78
+ """An API path from ``parts``, each escaped as one path segment."""
79
+ return "/" + "/".join(quote(part, safe="") for part in parts)
80
+
81
+
82
+ def _matches(name: str, patterns: Iterable[str]) -> bool:
83
+ """Whether ``name`` matches any of ``patterns``, ignoring case."""
84
+ return any(fnmatchcase(name.lower(), pattern.lower()) for pattern in patterns)
85
+
86
+
87
+ def _is_public(data: dict[str, Any]) -> bool:
88
+ """Whether GitHub reports ``data`` as public, by both fields."""
89
+ return data.get("visibility") == "public" and not data.get("private", False)
90
+
91
+
92
+ def _listing_reason(data: dict[str, Any], target: Target) -> str | None:
93
+ """Why a listed repository is dropped, or ``None`` when it is kept."""
94
+ name = data["name"]
95
+ if not _is_public(data):
96
+ return NOT_PUBLIC
97
+ if data.get("archived") and not target.scan_archived:
98
+ return ARCHIVED
99
+ if data.get("fork") and not target.scan_forks:
100
+ return FORK
101
+ if data.get("is_template") and not target.scan_templates:
102
+ return TEMPLATE
103
+ if target.include and not _matches(name, target.include):
104
+ return NOT_INCLUDED
105
+ if _matches(name, target.exclude):
106
+ return EXCLUDED
107
+ return None
108
+
109
+
110
+ def _repository(data: dict[str, Any]) -> Repository:
111
+ """The fields of a repository the store and collectors use."""
112
+ return Repository(
113
+ name=data["name"],
114
+ created_at=data["created_at"],
115
+ archived=bool(data.get("archived")),
116
+ fork=bool(data.get("fork")),
117
+ is_template=bool(data.get("is_template")),
118
+ default_branch=data.get("default_branch") or "",
119
+ )
120
+
121
+
122
+ def _known_names(owner: str, known: Iterable[str]) -> list[str]:
123
+ """Bare names from ``known``, which may hold ``owner/name`` store keys.
124
+
125
+ A key under another owner is not this target's to resolve, so it is
126
+ left out.
127
+ """
128
+ names: list[str] = []
129
+ for entry in known:
130
+ prefix, slash, name = entry.rpartition("/")
131
+ if not slash:
132
+ names.append(entry)
133
+ elif prefix.lower() == owner.lower():
134
+ names.append(name)
135
+ return names
136
+
137
+
138
+ async def _lookup(transport: Transport, owner: str, name: str) -> dict[str, Any] | None:
139
+ """``GET /repos/{owner}/{name}``; ``None`` on a ``404``, a rename or a transfer."""
140
+ response = await transport.request("GET", _path("repos", owner, name))
141
+ if response.status_code == 404:
142
+ return None
143
+ response.raise_for_status()
144
+ data: dict[str, Any] = response.json()
145
+ # A renamed or transferred repository redirects to a different one.
146
+ full_name = str(data.get("full_name", ""))
147
+ return data if full_name.lower() == f"{owner}/{name}".lower() else None
148
+
149
+
150
+ async def _listing(
151
+ transport: Transport, owner: str, owner_type: str
152
+ ) -> list[dict[str, Any]]:
153
+ """Every repository the owner's listing returns, all pages."""
154
+ if owner_type == "Organization":
155
+ url, kind = _path("orgs", owner, "repos"), "public"
156
+ else:
157
+ url, kind = _path("users", owner, "repos"), "owner"
158
+ listed: list[dict[str, Any]] = []
159
+ async for items, _ in get_paged(transport, url, {"type": kind, "per_page": 100}):
160
+ listed.extend(items)
161
+ return listed
162
+
163
+
164
+ async def resolve_scope(
165
+ transport: Transport, target: Target, *, known: Iterable[str] = ()
166
+ ) -> ResolvedScope:
167
+ """Resolve ``target`` to its public repositories (design §5).
168
+
169
+ A non-empty ``include`` of exact names reads each name alone and
170
+ applies no ``scan_*`` toggle; anything else lists the owner's
171
+ repositories and filters them. ``known`` names repositories stored
172
+ by earlier runs, as bare names or ``owner/name`` store keys: each one the listing no longer returns is read
173
+ alone, so one that turned private is reported ``not public``, and
174
+ one GitHub no longer shows, ``not found``. A failed read of a single
175
+ repository leaves it in ``unresolved``. ``BudgetExhaustedError``
176
+ and ``AuthError`` propagate, as does a failed owner or listing read.
177
+ """
178
+ response = await transport.request("GET", _path("users", target.owner))
179
+ response.raise_for_status()
180
+ user = response.json()
181
+ owner, owner_type = user["login"], user["type"]
182
+
183
+ explicit = bool(target.include) and all(map(is_exact, target.include))
184
+ found: dict[str, dict[str, Any]] = {}
185
+ if not explicit:
186
+ for data in await _listing(transport, owner, owner_type):
187
+ found[data["name"].lower()] = data
188
+
189
+ drops: dict[str, Dropped] = {}
190
+ unresolved: list[str] = []
191
+ wanted = [*target.include] if explicit else []
192
+ for name in dict.fromkeys([*wanted, *_known_names(owner, known)]):
193
+ key = name.lower()
194
+ if key in found or key in drops or name in unresolved:
195
+ continue
196
+ try:
197
+ looked_up = await _lookup(transport, owner, name)
198
+ except (httpx.HTTPStatusError, TransportError) as exc:
199
+ log.warning("could not read %s/%s: %s", owner, name, exc)
200
+ unresolved.append(name)
201
+ continue
202
+ if looked_up is None:
203
+ log.warning("skipping %s/%s: not found", owner, name)
204
+ drops[key] = Dropped(name, NOT_FOUND)
205
+ else:
206
+ found[key] = looked_up
207
+
208
+ named = {name.lower() for name in wanted}
209
+ kept: list[Repository] = []
210
+ for key, data in found.items():
211
+ if key in named:
212
+ reason = None if _is_public(data) else NOT_PUBLIC
213
+ else:
214
+ reason = _listing_reason(data, target)
215
+ if reason == NOT_PUBLIC:
216
+ log.warning("skipping %s/%s: not public", owner, data["name"])
217
+ if reason is None:
218
+ kept.append(_repository(data))
219
+ else:
220
+ drops[key] = Dropped(data["name"], reason)
221
+
222
+ return ResolvedScope(
223
+ owner=owner,
224
+ owner_type=owner_type,
225
+ repositories=tuple(sorted(kept, key=lambda repo: repo.name.lower())),
226
+ dropped=tuple(sorted(drops.values(), key=lambda drop: drop.name.lower())),
227
+ unresolved=tuple(sorted(unresolved, key=str.lower)),
228
+ )
@@ -0,0 +1,22 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: 2026 The Linux Foundation
3
+ """Series: stored facts turned into what the charts draw (design §7)."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from .actors import ActorClass, classify, unclassified_bots
8
+ from .daily import TargetSeries, build_series
9
+ from .leaderboard import Contributor, build_leaderboard
10
+ from .repositories import RepositoryRow, build_repositories
11
+
12
+ __all__ = [
13
+ "ActorClass",
14
+ "Contributor",
15
+ "RepositoryRow",
16
+ "TargetSeries",
17
+ "build_leaderboard",
18
+ "build_repositories",
19
+ "build_series",
20
+ "classify",
21
+ "unclassified_bots",
22
+ ]