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.
- github_statistics/__init__.py +14 -0
- github_statistics/__main__.py +10 -0
- github_statistics/_version.py +24 -0
- github_statistics/cli/__init__.py +9 -0
- github_statistics/cli/app.py +104 -0
- github_statistics/cli/cache.py +159 -0
- github_statistics/cli/collect.py +219 -0
- github_statistics/cli/common.py +128 -0
- github_statistics/cli/config.py +80 -0
- github_statistics/cli/doctor.py +214 -0
- github_statistics/cli/export.py +111 -0
- github_statistics/cli/options.py +175 -0
- github_statistics/cli/render.py +126 -0
- github_statistics/cli/run.py +137 -0
- github_statistics/cli/scope.py +96 -0
- github_statistics/cli/site.py +150 -0
- github_statistics/client/__init__.py +40 -0
- github_statistics/client/accounting.py +99 -0
- github_statistics/client/budget.py +125 -0
- github_statistics/client/cooldown.py +113 -0
- github_statistics/client/errors.py +60 -0
- github_statistics/client/graphql.py +281 -0
- github_statistics/client/paging.py +92 -0
- github_statistics/client/policy.py +243 -0
- github_statistics/client/transport.py +437 -0
- github_statistics/collect/__init__.py +44 -0
- github_statistics/collect/common.py +69 -0
- github_statistics/collect/enrich_items.py +423 -0
- github_statistics/collect/items.py +238 -0
- github_statistics/collect/jobs.py +194 -0
- github_statistics/collect/listed.py +42 -0
- github_statistics/collect/members.py +70 -0
- github_statistics/collect/reader.py +124 -0
- github_statistics/collect/run.py +354 -0
- github_statistics/collect/runs.py +436 -0
- github_statistics/collect/slices.py +55 -0
- github_statistics/collect/steps.py +154 -0
- github_statistics/collect/sweep.py +70 -0
- github_statistics/config/__init__.py +37 -0
- github_statistics/config/loader.py +430 -0
- github_statistics/config/models.py +156 -0
- github_statistics/config/schema.py +245 -0
- github_statistics/export/__init__.py +11 -0
- github_statistics/export/csv.py +93 -0
- github_statistics/export/documents.py +189 -0
- github_statistics/export/json.py +33 -0
- github_statistics/py.typed +2 -0
- github_statistics/render/__init__.py +44 -0
- github_statistics/render/bars3d.py +420 -0
- github_statistics/render/charts.py +214 -0
- github_statistics/render/demo.py +133 -0
- github_statistics/render/images.py +31 -0
- github_statistics/render/layout.py +341 -0
- github_statistics/render/model.py +260 -0
- github_statistics/render/palette.py +41 -0
- github_statistics/scope/__init__.py +17 -0
- github_statistics/scope/apply.py +95 -0
- github_statistics/scope/resolver.py +228 -0
- github_statistics/series/__init__.py +22 -0
- github_statistics/series/actors.py +128 -0
- github_statistics/series/coverage.py +86 -0
- github_statistics/series/daily.py +229 -0
- github_statistics/series/leaderboard.py +221 -0
- github_statistics/series/repositories.py +154 -0
- github_statistics/site/__init__.py +9 -0
- github_statistics/site/assets/site.css +281 -0
- github_statistics/site/build.py +392 -0
- github_statistics/site/templates/base.html.j2 +25 -0
- github_statistics/site/templates/index.html.j2 +30 -0
- github_statistics/site/templates/macros.html.j2 +5 -0
- github_statistics/site/templates/site.js.j2 +66 -0
- github_statistics/site/templates/target.html.j2 +95 -0
- github_statistics/store/__init__.py +40 -0
- github_statistics/store/activity.py +311 -0
- github_statistics/store/aggregates.py +294 -0
- github_statistics/store/base.py +163 -0
- github_statistics/store/codec.py +263 -0
- github_statistics/store/models.py +136 -0
- github_statistics/store/paths.py +36 -0
- github_statistics/store/schema.py +169 -0
- github_statistics/store/sqlite.py +299 -0
- github_statistics-0.1.0.dist-info/METADATA +308 -0
- github_statistics-0.1.0.dist-info/RECORD +86 -0
- github_statistics-0.1.0.dist-info/WHEEL +4 -0
- github_statistics-0.1.0.dist-info/entry_points.txt +2 -0
- github_statistics-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 The Linux Foundation
|
|
3
|
+
"""The pages of the site and the assets they load (design §8.5).
|
|
4
|
+
|
|
5
|
+
`build_site` writes HTML, ``.nojekyll`` and ``assets/`` and nothing
|
|
6
|
+
else. It reads no store and makes no request: each target's series and
|
|
7
|
+
tables come in built, and the charts and data files are the ones
|
|
8
|
+
`render` and `export` wrote under ``<out>/<owner>/``, linked where they
|
|
9
|
+
exist and named as missing where they do not. Downloads link the JSON
|
|
10
|
+
documents `export` writes, by name; nothing else in ``data/`` is
|
|
11
|
+
linked. Logins and repository names reach the pages only through
|
|
12
|
+
autoescaped templates.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from collections.abc import Iterable, Sequence
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from datetime import datetime
|
|
20
|
+
from importlib.resources import files
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any
|
|
23
|
+
|
|
24
|
+
from jinja2 import Environment, PackageLoader, select_autoescape
|
|
25
|
+
from PIL import Image
|
|
26
|
+
|
|
27
|
+
from github_statistics import __version__
|
|
28
|
+
|
|
29
|
+
from ..config import Config, ResolvedIdentities, Target, resolve_identities
|
|
30
|
+
from ..render.charts import VIEW_LABELS
|
|
31
|
+
from ..render.model import Coverage
|
|
32
|
+
from ..scope.resolver import is_exact
|
|
33
|
+
from ..series import Contributor, RepositoryRow, TargetSeries
|
|
34
|
+
from ..series.daily import SERIES
|
|
35
|
+
from ..series.leaderboard import leaderboard_columns
|
|
36
|
+
from ..series.repositories import COLUMNS as REPOSITORY_COLUMNS
|
|
37
|
+
from ..store import path_component
|
|
38
|
+
|
|
39
|
+
DATATABLES_VERSION = "9.0.3"
|
|
40
|
+
DATATABLES_CSS_URL = (
|
|
41
|
+
"https://cdn.jsdelivr.net/npm/simple-datatables@9.0.3/dist/style.css"
|
|
42
|
+
)
|
|
43
|
+
DATATABLES_CSS_SRI = (
|
|
44
|
+
"sha384-xnK68E/OAsSGcbvbeWEOyhjix2K7rBxt8Eytj/Ow9zuPG7WwFGGqMPQ8SbexlsL0"
|
|
45
|
+
)
|
|
46
|
+
DATATABLES_JS_URL = (
|
|
47
|
+
"https://cdn.jsdelivr.net/npm/simple-datatables@9.0.3/dist/umd/"
|
|
48
|
+
"simple-datatables.min.js"
|
|
49
|
+
)
|
|
50
|
+
DATATABLES_JS_SRI = (
|
|
51
|
+
"sha384-JYQd44jQWQbU+FdjWIUlbjzENGRHPdOQcj7dAgjJEvSyt2js5lE85kaPOdC53JVu"
|
|
52
|
+
)
|
|
53
|
+
CONTENT_SECURITY_POLICY = (
|
|
54
|
+
"default-src 'self'; script-src 'self' https://cdn.jsdelivr.net;"
|
|
55
|
+
" style-src 'self' https://cdn.jsdelivr.net; img-src 'self' data:;"
|
|
56
|
+
" base-uri 'none'; form-action 'none'"
|
|
57
|
+
)
|
|
58
|
+
TEMPLATES = (
|
|
59
|
+
"base.html.j2",
|
|
60
|
+
"macros.html.j2",
|
|
61
|
+
"index.html.j2",
|
|
62
|
+
"target.html.j2",
|
|
63
|
+
"site.js.j2",
|
|
64
|
+
)
|
|
65
|
+
ASSETS = ("site.css",)
|
|
66
|
+
# The stems of the JSON documents `export` writes (the keys of
|
|
67
|
+
# `github_statistics.export.build_documents`), in the order linked.
|
|
68
|
+
DATA_DOCUMENTS = (
|
|
69
|
+
"series",
|
|
70
|
+
"contributors",
|
|
71
|
+
"repositories",
|
|
72
|
+
"coverage",
|
|
73
|
+
"reviews",
|
|
74
|
+
"meta",
|
|
75
|
+
)
|
|
76
|
+
PER_PAGE = 50
|
|
77
|
+
PER_PAGE_SELECT = (25, 50, 100, 250)
|
|
78
|
+
INLINE_WIDTH = 1920
|
|
79
|
+
HEADINGS = {
|
|
80
|
+
"pull_requests": "Pull requests",
|
|
81
|
+
"issues": "Issues",
|
|
82
|
+
"workflows": "Workflow runs and jobs",
|
|
83
|
+
"workflow_outcomes": "Workflow outcomes",
|
|
84
|
+
}
|
|
85
|
+
CLASS_LABELS = {
|
|
86
|
+
"member": "member",
|
|
87
|
+
"external": "external contributor",
|
|
88
|
+
"org_bot": "our bot",
|
|
89
|
+
"external_bot": "external bot",
|
|
90
|
+
}
|
|
91
|
+
BOT_CLASSES = ("org_bot", "external_bot")
|
|
92
|
+
HORIZON_NOTE = (
|
|
93
|
+
"GitHub lists workflow runs for about a year; earlier days show as no data."
|
|
94
|
+
)
|
|
95
|
+
_RUN_METRICS = ("workflows", "workflow_outcomes")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass(frozen=True)
|
|
99
|
+
class SiteTarget:
|
|
100
|
+
"""What the pages of one target show, built from its store.
|
|
101
|
+
|
|
102
|
+
``merged`` counts the pull requests merged in the window under the
|
|
103
|
+
daily series' rules, deleted authors included, which the leaderboard
|
|
104
|
+
leaves out. ``identities`` are the lists the tables were classed
|
|
105
|
+
with; ``None`` means the configuration's, as `resolve_identities`
|
|
106
|
+
gives them.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
target: Target
|
|
110
|
+
series: TargetSeries
|
|
111
|
+
contributors: Sequence[Contributor]
|
|
112
|
+
repositories: Sequence[RepositoryRow]
|
|
113
|
+
merged: int
|
|
114
|
+
identities: ResolvedIdentities | None = None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _environment() -> Environment:
|
|
118
|
+
"""The template environment: autoescape on for HTML templates, off for the script."""
|
|
119
|
+
return Environment(
|
|
120
|
+
loader=PackageLoader("github_statistics", "site/templates"),
|
|
121
|
+
autoescape=select_autoescape(
|
|
122
|
+
enabled_extensions=("html.j2",), default_for_string=True, default=False
|
|
123
|
+
),
|
|
124
|
+
trim_blocks=True,
|
|
125
|
+
lstrip_blocks=True,
|
|
126
|
+
keep_trailing_newline=True,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _days(count: int) -> str:
|
|
131
|
+
"""``1 day`` or ``<count> days``."""
|
|
132
|
+
return f"{count} day" if count == 1 else f"{count} days"
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _window(series: TargetSeries) -> str:
|
|
136
|
+
"""The window in words: its length and its first and last days."""
|
|
137
|
+
days = series.days
|
|
138
|
+
return f"{_days(len(days))}, {days[0].isoformat()} to {days[-1].isoformat()} (UTC)"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _scope_rule(target: Target) -> str:
|
|
142
|
+
"""The rule that selects ``target``'s repositories, in words.
|
|
143
|
+
|
|
144
|
+
Where every ``include`` entry is an exact name the resolver reads
|
|
145
|
+
those repositories alone and keeps each whatever its archived, fork
|
|
146
|
+
or template state, so the rule says that rather than the toggles.
|
|
147
|
+
"""
|
|
148
|
+
if target.include and all(map(is_exact, target.include)):
|
|
149
|
+
return (
|
|
150
|
+
f"Public repositories of {target.owner} named"
|
|
151
|
+
f" {', '.join(target.include)}; a named repository counts"
|
|
152
|
+
" whether or not it is archived, a fork or a template."
|
|
153
|
+
)
|
|
154
|
+
chosen = f"public repositories of {target.owner}"
|
|
155
|
+
if target.include:
|
|
156
|
+
chosen += f" matching {', '.join(target.include)}"
|
|
157
|
+
if target.exclude:
|
|
158
|
+
chosen += f", except {', '.join(target.exclude)}"
|
|
159
|
+
if not (target.include or target.exclude):
|
|
160
|
+
chosen = f"all {chosen}"
|
|
161
|
+
kinds = (
|
|
162
|
+
("archived repositories", target.scan_archived),
|
|
163
|
+
("forks", target.scan_forks),
|
|
164
|
+
("templates", target.scan_templates),
|
|
165
|
+
)
|
|
166
|
+
flags = [f"{name} {'included' if on else 'left out'}" for name, on in kinds]
|
|
167
|
+
return f"{chosen[0].upper()}{chosen[1:]}; {', '.join(flags)}."
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _total(series: TargetSeries, metric: str, key: str, view: str = "all") -> int:
|
|
171
|
+
"""The sum over the window of one series of one view."""
|
|
172
|
+
return sum(series.values(metric, key, view))
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def _headline(site: SiteTarget) -> list[tuple[str, str]]:
|
|
176
|
+
"""The landing card's numbers for the window, for the metrics charted."""
|
|
177
|
+
series = site.series
|
|
178
|
+
charted = set(series.coverage)
|
|
179
|
+
numbers: list[tuple[str, int | str]] = []
|
|
180
|
+
if "pull_requests" in charted:
|
|
181
|
+
numbers.append(
|
|
182
|
+
("Pull requests opened", _total(series, "pull_requests", "opened"))
|
|
183
|
+
)
|
|
184
|
+
numbers.append(("Pull requests merged", site.merged))
|
|
185
|
+
if "issues" in charted:
|
|
186
|
+
numbers.append(("Issues opened", _total(series, "issues", "opened")))
|
|
187
|
+
numbers.append(("Issues closed", _total(series, "issues", "closed")))
|
|
188
|
+
if "workflows" in charted:
|
|
189
|
+
numbers.append(("Workflow runs", _total(series, "workflows", "runs")))
|
|
190
|
+
numbers.append(("Jobs", _total(series, "workflows", "jobs")))
|
|
191
|
+
numbers.append(("Repositories in scope", series.repositories[-1]))
|
|
192
|
+
complete = sum(
|
|
193
|
+
all(series.coverage[metric][index] is Coverage.COMPLETE for metric in charted)
|
|
194
|
+
for index in range(len(series.days))
|
|
195
|
+
)
|
|
196
|
+
numbers.append(("Days covered", f"{complete} of {len(series.days)}"))
|
|
197
|
+
return [(label, str(value)) for label, value in numbers]
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _coverage_note(metric: str, grades: Sequence[Coverage]) -> list[str]:
|
|
201
|
+
"""The coverage lines of one metric; none when every day is complete."""
|
|
202
|
+
missing = sum(grade is Coverage.NONE for grade in grades)
|
|
203
|
+
partial = sum(grade is Coverage.PARTIAL for grade in grades)
|
|
204
|
+
lines = []
|
|
205
|
+
if missing:
|
|
206
|
+
lines.append(f"{_days(missing)} of {len(grades)} without data.")
|
|
207
|
+
if partial:
|
|
208
|
+
lines.append(f"{_days(partial)} of {len(grades)} with partial data.")
|
|
209
|
+
if missing and metric in _RUN_METRICS:
|
|
210
|
+
lines.append(HORIZON_NOTE)
|
|
211
|
+
return lines
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _chart(
|
|
215
|
+
owner_dir: Path, site: SiteTarget, metric: str, view: str
|
|
216
|
+
) -> dict[str, Any] | None:
|
|
217
|
+
"""The image of one chart, its master and its text; ``None`` when not rendered.
|
|
218
|
+
|
|
219
|
+
The image is the `INLINE_WIDTH` derivative, or the master where
|
|
220
|
+
`render` wrote no derivative at that width. Paths are relative to
|
|
221
|
+
the target's directory.
|
|
222
|
+
"""
|
|
223
|
+
stem = f"{metric}-{view}".replace("_", "-")
|
|
224
|
+
master = owner_dir / "img" / f"{stem}.png"
|
|
225
|
+
inline = owner_dir / "img" / f"{stem}-{INLINE_WIDTH}.png"
|
|
226
|
+
shown = inline if inline.is_file() else master
|
|
227
|
+
if not shown.is_file():
|
|
228
|
+
return None
|
|
229
|
+
with Image.open(shown) as image:
|
|
230
|
+
width, height = image.size
|
|
231
|
+
first, second = SERIES[metric]
|
|
232
|
+
series = site.series
|
|
233
|
+
alt = (
|
|
234
|
+
f"{site.target.owner} — {HEADINGS[metric].lower()} per day,"
|
|
235
|
+
f" {VIEW_LABELS[view]}, {_window(series)}:"
|
|
236
|
+
f" {_total(series, metric, first, view)} {first},"
|
|
237
|
+
f" {_total(series, metric, second, view)} {second}"
|
|
238
|
+
)
|
|
239
|
+
return {
|
|
240
|
+
"src": f"img/{shown.name}",
|
|
241
|
+
"href": f"img/{master.name}" if master.is_file() else f"img/{shown.name}",
|
|
242
|
+
"width": width,
|
|
243
|
+
"height": height,
|
|
244
|
+
"alt": alt,
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _lazy_after_first(charts: Iterable[dict[str, Any] | None]) -> None:
|
|
249
|
+
"""Mark every chart of a page but the first to load lazily."""
|
|
250
|
+
present = [chart for chart in charts if chart is not None]
|
|
251
|
+
for index, chart in enumerate(present):
|
|
252
|
+
chart["lazy"] = index > 0
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def _target_page(site: SiteTarget, config: Config, owner_dir: Path) -> dict[str, Any]:
|
|
256
|
+
"""The context of one target's page."""
|
|
257
|
+
metrics: list[dict[str, Any]] = []
|
|
258
|
+
for metric, grades in site.series.coverage.items():
|
|
259
|
+
views = [
|
|
260
|
+
{
|
|
261
|
+
"id": f"{metric}-{view}".replace("_", "-"),
|
|
262
|
+
"label": VIEW_LABELS[view],
|
|
263
|
+
"chart": _chart(owner_dir, site, metric, view),
|
|
264
|
+
}
|
|
265
|
+
for view in config.classes
|
|
266
|
+
]
|
|
267
|
+
metrics.append(
|
|
268
|
+
{
|
|
269
|
+
"name": metric.replace("_", "-"),
|
|
270
|
+
"heading": HEADINGS[metric],
|
|
271
|
+
"views": views,
|
|
272
|
+
"notes": _coverage_note(metric, grades),
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
_lazy_after_first(view["chart"] for m in metrics for view in m["views"])
|
|
276
|
+
columns = leaderboard_columns(config)
|
|
277
|
+
identities = site.identities or resolve_identities(site.target, config)
|
|
278
|
+
data_dir = owner_dir / "data"
|
|
279
|
+
downloads = [
|
|
280
|
+
f"{stem}.json"
|
|
281
|
+
for stem in DATA_DOCUMENTS
|
|
282
|
+
if (data_dir / f"{stem}.json").is_file()
|
|
283
|
+
]
|
|
284
|
+
return {
|
|
285
|
+
"owner": site.target.owner,
|
|
286
|
+
"member_orgs": identities.member_orgs.values,
|
|
287
|
+
"named_members": bool(identities.members.values),
|
|
288
|
+
"metrics": metrics,
|
|
289
|
+
"columns": columns,
|
|
290
|
+
"contributors": [
|
|
291
|
+
{"login": row.login, "class": row.actor_class.value, "counts": row.counts}
|
|
292
|
+
for row in site.contributors
|
|
293
|
+
],
|
|
294
|
+
"repository_columns": REPOSITORY_COLUMNS,
|
|
295
|
+
"coverage_metrics": list(site.series.coverage),
|
|
296
|
+
"repositories": site.repositories,
|
|
297
|
+
"downloads": downloads,
|
|
298
|
+
"window": _window(site.series),
|
|
299
|
+
"scope_rule": _scope_rule(site.target),
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _card(
|
|
304
|
+
site: SiteTarget, config: Config, owner_dir: Path, directory: str
|
|
305
|
+
) -> dict[str, Any]:
|
|
306
|
+
"""The context of one target's card on the landing page.
|
|
307
|
+
|
|
308
|
+
``charts`` holds an entry per charted metric, its chart ``None``
|
|
309
|
+
where `render` wrote none, so the card names each missing chart.
|
|
310
|
+
The previews are the ``all`` view: when ``classes`` leaves it out,
|
|
311
|
+
`render` writes none, so ``charts`` is empty and ``previews`` false.
|
|
312
|
+
"""
|
|
313
|
+
previews = "all" in config.classes
|
|
314
|
+
charts = []
|
|
315
|
+
for metric in site.series.coverage if previews else ():
|
|
316
|
+
chart = _chart(owner_dir, site, metric, "all")
|
|
317
|
+
if chart is not None:
|
|
318
|
+
chart = {
|
|
319
|
+
**chart,
|
|
320
|
+
"src": f"{directory}/{chart['src']}",
|
|
321
|
+
"href": f"{directory}/{chart['href']}",
|
|
322
|
+
}
|
|
323
|
+
charts.append({"heading": HEADINGS[metric], "chart": chart})
|
|
324
|
+
return {
|
|
325
|
+
"owner": site.target.owner,
|
|
326
|
+
"href": f"{directory}/index.html",
|
|
327
|
+
"headline": _headline(site),
|
|
328
|
+
"charts": charts,
|
|
329
|
+
"previews": previews,
|
|
330
|
+
"scope_rule": _scope_rule(site.target),
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def _write(path: Path, text: str, written: list[Path]) -> None:
|
|
335
|
+
"""Write ``text`` to ``path`` as UTF-8 and record the path."""
|
|
336
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
337
|
+
path.write_text(text, encoding="utf-8")
|
|
338
|
+
written.append(path)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def build_site(
|
|
342
|
+
targets: Sequence[SiteTarget], config: Config, out_dir: Path, *, now: datetime
|
|
343
|
+
) -> list[Path]:
|
|
344
|
+
"""Write the site for ``targets`` under ``out_dir``; the files written, in order.
|
|
345
|
+
|
|
346
|
+
``now`` gives the generation date shown in each footer, the date
|
|
347
|
+
alone, so two builds on one day write identical pages. ``out_dir``
|
|
348
|
+
must hold the charts and data of the same run: this function links
|
|
349
|
+
what `render` and `export` wrote and does not check their freshness.
|
|
350
|
+
"""
|
|
351
|
+
out = Path(out_dir)
|
|
352
|
+
environment = _environment()
|
|
353
|
+
common = {
|
|
354
|
+
"csp": CONTENT_SECURITY_POLICY,
|
|
355
|
+
"version": __version__,
|
|
356
|
+
"generated": now.date().isoformat(),
|
|
357
|
+
"class_labels": CLASS_LABELS,
|
|
358
|
+
"bot_classes": BOT_CLASSES,
|
|
359
|
+
}
|
|
360
|
+
written: list[Path] = []
|
|
361
|
+
_write(out / ".nojekyll", "", written)
|
|
362
|
+
assets = files("github_statistics.site") / "assets"
|
|
363
|
+
for name in ASSETS:
|
|
364
|
+
_write(out / "assets" / name, (assets / name).read_text("utf-8"), written)
|
|
365
|
+
script = environment.get_template("site.js.j2").render(
|
|
366
|
+
per_page=PER_PAGE, per_page_select=list(PER_PAGE_SELECT)
|
|
367
|
+
)
|
|
368
|
+
_write(out / "assets" / "site.js", script, written)
|
|
369
|
+
target_page = environment.get_template("target.html.j2")
|
|
370
|
+
cards = []
|
|
371
|
+
for site in targets:
|
|
372
|
+
directory = path_component(site.target.owner, "owner")
|
|
373
|
+
owner_dir = out / directory
|
|
374
|
+
context = _target_page(site, config, owner_dir)
|
|
375
|
+
page = target_page.render(
|
|
376
|
+
**common,
|
|
377
|
+
**context,
|
|
378
|
+
root="../",
|
|
379
|
+
datatables_css_url=DATATABLES_CSS_URL,
|
|
380
|
+
datatables_css_sri=DATATABLES_CSS_SRI,
|
|
381
|
+
datatables_js_url=DATATABLES_JS_URL,
|
|
382
|
+
datatables_js_sri=DATATABLES_JS_SRI,
|
|
383
|
+
)
|
|
384
|
+
_write(owner_dir / "index.html", page, written)
|
|
385
|
+
cards.append(_card(site, config, owner_dir, directory))
|
|
386
|
+
_lazy_after_first(entry["chart"] for card in cards for entry in card["charts"])
|
|
387
|
+
window = _window(targets[0].series) if targets else ""
|
|
388
|
+
landing = environment.get_template("index.html.j2").render(
|
|
389
|
+
**common, root="", cards=cards, window=window
|
|
390
|
+
)
|
|
391
|
+
_write(out / "index.html", landing, written)
|
|
392
|
+
return written
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{# SPDX-License-Identifier: Apache-2.0 #}
|
|
2
|
+
{# SPDX-FileCopyrightText: 2026 The Linux Foundation #}
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<meta charset="utf-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
<meta http-equiv="Content-Security-Policy" content="{{ csp }}">
|
|
9
|
+
<title>{% block title %}GitHub statistics{% endblock %}</title>
|
|
10
|
+
{% block head %}{% endblock %}
|
|
11
|
+
<link rel="stylesheet" href="{{ root }}assets/site.css">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<header>
|
|
15
|
+
<div class="wrap"><a href="{{ root }}index.html">GitHub statistics</a></div>
|
|
16
|
+
</header>
|
|
17
|
+
<main class="wrap">
|
|
18
|
+
{% block main %}{% endblock %}
|
|
19
|
+
</main>
|
|
20
|
+
<footer class="wrap">
|
|
21
|
+
<p>Generated {{ generated }} by github-statistics {{ version }}.
|
|
22
|
+
{% block footer %}{% endblock %}</p>
|
|
23
|
+
</footer>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{# SPDX-License-Identifier: Apache-2.0 #}
|
|
2
|
+
{# SPDX-FileCopyrightText: 2026 The Linux Foundation #}
|
|
3
|
+
{% extends "base.html.j2" %}
|
|
4
|
+
{% from "macros.html.j2" import chart_image %}
|
|
5
|
+
{% block main %}
|
|
6
|
+
<h1>GitHub statistics</h1>
|
|
7
|
+
<p class="note">Daily activity over {{ window }}.</p>
|
|
8
|
+
{% for card in cards %}
|
|
9
|
+
<section class="card">
|
|
10
|
+
<h2><a href="{{ card.href }}">{{ card.owner }}</a></h2>
|
|
11
|
+
<dl class="headline">
|
|
12
|
+
{% for label, value in card.headline %}
|
|
13
|
+
<div><dt>{{ label }}</dt><dd>{{ value }}</dd></div>
|
|
14
|
+
{% endfor %}
|
|
15
|
+
</dl>
|
|
16
|
+
{% for entry in card.charts %}
|
|
17
|
+
{% if entry.chart %}
|
|
18
|
+
{{ chart_image(entry.chart) }}
|
|
19
|
+
{% else %}
|
|
20
|
+
<p class="missing">No {{ entry.heading|lower }} chart yet: run <code>github-statistics render</code>.</p>
|
|
21
|
+
{% endif %}
|
|
22
|
+
{% endfor %}
|
|
23
|
+
{% if not card.previews %}
|
|
24
|
+
<p class="missing">Chart previews show the everyone view: add <code>all</code> to <code>classes</code> to show them.</p>
|
|
25
|
+
{% endif %}
|
|
26
|
+
<p class="scope">{{ card.scope_rule }}</p>
|
|
27
|
+
</section>
|
|
28
|
+
{% endfor %}
|
|
29
|
+
{% endblock %}
|
|
30
|
+
{% block footer %}Window: {{ window }}.{% endblock %}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{# SPDX-License-Identifier: Apache-2.0 #}
|
|
2
|
+
{# SPDX-FileCopyrightText: 2026 The Linux Foundation #}
|
|
3
|
+
{% macro chart_image(chart) %}
|
|
4
|
+
<a class="chart" href="{{ chart.href }}"><img src="{{ chart.src }}" width="{{ chart.width }}" height="{{ chart.height }}" alt="{{ chart.alt }}"{% if chart.lazy %} loading="lazy"{% endif %}></a>
|
|
5
|
+
{% endmacro %}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{# SPDX-License-Identifier: Apache-2.0 #}
|
|
2
|
+
{# SPDX-FileCopyrightText: 2026 The Linux Foundation #}
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
// Table set-up: bot-class filters, then sorting and search where the
|
|
6
|
+
// simple-datatables script loaded. Without it the tables stay plain.
|
|
7
|
+
(function () {
|
|
8
|
+
var options = {
|
|
9
|
+
perPage: {{ per_page | tojson }},
|
|
10
|
+
perPageSelect: {{ per_page_select | tojson }}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function numberColumns(table) {
|
|
14
|
+
var select = [];
|
|
15
|
+
Array.prototype.forEach.call(table.tHead.rows[0].cells, function (cell, index) {
|
|
16
|
+
if (cell.dataset.type === "number") {
|
|
17
|
+
select.push(index);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return select.length ? [{ select: select, type: "number" }] : [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function setUp(table) {
|
|
24
|
+
var rows = Array.prototype.slice.call(table.tBodies[0].rows);
|
|
25
|
+
var filters = document.querySelector(
|
|
26
|
+
'fieldset[data-filter-for="' + table.id + '"]'
|
|
27
|
+
);
|
|
28
|
+
var boxes = filters
|
|
29
|
+
? Array.prototype.slice.call(filters.querySelectorAll("input[type=checkbox]"))
|
|
30
|
+
: [];
|
|
31
|
+
var settings = Object.assign({ columns: numberColumns(table) }, options);
|
|
32
|
+
var dataTable = null;
|
|
33
|
+
|
|
34
|
+
function build() {
|
|
35
|
+
var shown = {};
|
|
36
|
+
boxes.forEach(function (box) {
|
|
37
|
+
shown[box.value] = box.checked;
|
|
38
|
+
});
|
|
39
|
+
if (dataTable) {
|
|
40
|
+
// destroy() swaps in a new table built from the initial HTML.
|
|
41
|
+
dataTable.destroy();
|
|
42
|
+
table = document.getElementById(table.id);
|
|
43
|
+
}
|
|
44
|
+
var body = table.tBodies[0];
|
|
45
|
+
body.replaceChildren.apply(
|
|
46
|
+
body,
|
|
47
|
+
rows.filter(function (row) {
|
|
48
|
+
return !(row.dataset.class in shown) || shown[row.dataset.class];
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
if (window.simpleDatatables) {
|
|
52
|
+
dataTable = new window.simpleDatatables.DataTable(table, settings);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
boxes.forEach(function (box) {
|
|
57
|
+
box.addEventListener("change", build);
|
|
58
|
+
});
|
|
59
|
+
if (filters) {
|
|
60
|
+
filters.hidden = false;
|
|
61
|
+
}
|
|
62
|
+
build();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
document.querySelectorAll("table[data-table]").forEach(setUp);
|
|
66
|
+
})();
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{# SPDX-License-Identifier: Apache-2.0 #}
|
|
2
|
+
{# SPDX-FileCopyrightText: 2026 The Linux Foundation #}
|
|
3
|
+
{% extends "base.html.j2" %}
|
|
4
|
+
{% from "macros.html.j2" import chart_image %}
|
|
5
|
+
{% block title %}{{ owner }} · GitHub statistics{% endblock %}
|
|
6
|
+
{% block head %}
|
|
7
|
+
<link rel="stylesheet" href="{{ datatables_css_url }}" integrity="{{ datatables_css_sri }}" crossorigin="anonymous">
|
|
8
|
+
<script src="{{ datatables_js_url }}" integrity="{{ datatables_js_sri }}" crossorigin="anonymous" defer></script>
|
|
9
|
+
<script src="{{ root }}assets/site.js" defer></script>
|
|
10
|
+
{% endblock %}
|
|
11
|
+
{% block main %}
|
|
12
|
+
<h1>{{ owner }}</h1>
|
|
13
|
+
<p class="note">Daily activity over {{ window }}.</p>
|
|
14
|
+
<nav aria-label="Sections">
|
|
15
|
+
{% for metric in metrics %}<a href="#{{ metric.name }}">{{ metric.heading }}</a>
|
|
16
|
+
{% endfor %}<a href="#contributors">Contributors</a>
|
|
17
|
+
<a href="#repositories">Repositories</a>
|
|
18
|
+
<a href="#downloads">Downloads</a>
|
|
19
|
+
</nav>
|
|
20
|
+
{% for metric in metrics %}
|
|
21
|
+
<section class="metric" id="{{ metric.name }}">
|
|
22
|
+
<h2>{{ metric.heading }}</h2>
|
|
23
|
+
{% for line in metric.notes %}
|
|
24
|
+
<p class="note">{{ line }}</p>
|
|
25
|
+
{% endfor %}
|
|
26
|
+
<div class="tabs">
|
|
27
|
+
{% for view in metric.views %}
|
|
28
|
+
<input type="radio" name="view-{{ metric.name }}" id="tab-{{ view.id }}"{% if loop.first %} checked{% endif %}>
|
|
29
|
+
<label for="tab-{{ view.id }}">{{ view.label }}</label>
|
|
30
|
+
{% endfor %}
|
|
31
|
+
<div>
|
|
32
|
+
{% for view in metric.views %}
|
|
33
|
+
<div>
|
|
34
|
+
{% if view.chart %}
|
|
35
|
+
{{ chart_image(view.chart) }}
|
|
36
|
+
{% else %}
|
|
37
|
+
<p class="missing">No chart for {{ view.label }}: run <code>github-statistics render</code>.</p>
|
|
38
|
+
{% endif %}
|
|
39
|
+
</div>
|
|
40
|
+
{% endfor %}
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</section>
|
|
44
|
+
{% endfor %}
|
|
45
|
+
<section id="contributors">
|
|
46
|
+
<h2>Contributors</h2>
|
|
47
|
+
<fieldset class="filters" data-filter-for="contributors-table" hidden>
|
|
48
|
+
<legend>Show</legend>
|
|
49
|
+
{% for actor_class in bot_classes %}
|
|
50
|
+
<label><input type="checkbox" value="{{ actor_class }}"> {{ class_labels[actor_class] }}s</label>
|
|
51
|
+
{% endfor %}
|
|
52
|
+
</fieldset>
|
|
53
|
+
<div>
|
|
54
|
+
<table id="contributors-table" class="data" data-table>
|
|
55
|
+
<thead>
|
|
56
|
+
<tr><th>Login</th><th>Class</th>{% for column in columns %}<th data-type="number">{{ column | replace("_", " ") }}</th>{% endfor %}</tr>
|
|
57
|
+
</thead>
|
|
58
|
+
<tbody>
|
|
59
|
+
{% for row in contributors %}
|
|
60
|
+
<tr data-class="{{ row.class }}"><td>{{ row.login }}</td><td><span class="badge">{{ class_labels[row.class] }}</span></td>{% for column in columns %}<td>{{ row.counts[column] }}</td>{% endfor %}</tr>
|
|
61
|
+
{% endfor %}
|
|
62
|
+
</tbody>
|
|
63
|
+
</table>
|
|
64
|
+
</div>
|
|
65
|
+
<p class="note">Members are people whose membership of {{ member_orgs | join(" or ") }} is public on GitHub{% if named_members %}, and the people this site's configuration names as members{% endif %}; everyone else, including members who keep their membership private, appears as an external contributor. If {{ owner }} is a user rather than an organisation, {{ owner }} counts as a member too.</p>
|
|
66
|
+
</section>
|
|
67
|
+
<section id="repositories">
|
|
68
|
+
<h2>Repositories</h2>
|
|
69
|
+
<div>
|
|
70
|
+
<table id="repositories-table" class="data" data-table>
|
|
71
|
+
<thead>
|
|
72
|
+
<tr><th>Repository</th>{% for column in repository_columns %}<th data-type="number">{{ column | replace("_", " ") }}</th>{% endfor %}{% for metric in coverage_metrics %}<th data-type="number">coverage {{ metric | replace("_", " ") }} (%)</th>{% endfor %}</tr>
|
|
73
|
+
</thead>
|
|
74
|
+
<tbody>
|
|
75
|
+
{% for row in repositories %}
|
|
76
|
+
<tr><td>{{ row.repo }}</td>{% for column in repository_columns %}<td>{{ row.counts[column] }}</td>{% endfor %}{% for metric in coverage_metrics %}<td>{{ "%.1f" | format(row.coverage[metric] * 100) }}</td>{% endfor %}</tr>
|
|
77
|
+
{% endfor %}
|
|
78
|
+
</tbody>
|
|
79
|
+
</table>
|
|
80
|
+
</div>
|
|
81
|
+
</section>
|
|
82
|
+
<section id="downloads">
|
|
83
|
+
<h2>Downloads</h2>
|
|
84
|
+
{% if downloads %}
|
|
85
|
+
<ul class="downloads">
|
|
86
|
+
{% for name in downloads %}
|
|
87
|
+
<li><a href="data/{{ name | urlencode }}">{{ name }}</a></li>
|
|
88
|
+
{% endfor %}
|
|
89
|
+
</ul>
|
|
90
|
+
{% else %}
|
|
91
|
+
<p class="missing">No data files yet: run <code>github-statistics export</code>.</p>
|
|
92
|
+
{% endif %}
|
|
93
|
+
</section>
|
|
94
|
+
{% endblock %}
|
|
95
|
+
{% block footer %}Window: {{ window }}. Scope: {{ scope_rule }}{% endblock %}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 The Linux Foundation
|
|
3
|
+
"""The SQLite store, the one place state lives between runs (design §6.1)."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from .models import (
|
|
8
|
+
ActorDayCount,
|
|
9
|
+
DayRange,
|
|
10
|
+
Enrichment,
|
|
11
|
+
Item,
|
|
12
|
+
Member,
|
|
13
|
+
Review,
|
|
14
|
+
Run,
|
|
15
|
+
RunDayCount,
|
|
16
|
+
SyncState,
|
|
17
|
+
)
|
|
18
|
+
from .paths import STORE_FILE, path_component, store_path
|
|
19
|
+
from .schema import SCHEMA_VERSION, TABLES, StoreInfo, describe
|
|
20
|
+
from .sqlite import Store
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"SCHEMA_VERSION",
|
|
24
|
+
"STORE_FILE",
|
|
25
|
+
"TABLES",
|
|
26
|
+
"ActorDayCount",
|
|
27
|
+
"DayRange",
|
|
28
|
+
"Enrichment",
|
|
29
|
+
"Item",
|
|
30
|
+
"Member",
|
|
31
|
+
"Review",
|
|
32
|
+
"Run",
|
|
33
|
+
"RunDayCount",
|
|
34
|
+
"Store",
|
|
35
|
+
"StoreInfo",
|
|
36
|
+
"SyncState",
|
|
37
|
+
"describe",
|
|
38
|
+
"path_component",
|
|
39
|
+
"store_path",
|
|
40
|
+
]
|