git-year-wrapped 0.0.0-stage → 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +78 -2
- package/bin/git-year-wrapped.mjs +182 -0
- package/lib/card.mjs +74 -0
- package/lib/clone.mjs +55 -0
- package/lib/languages.mjs +69 -0
- package/lib/log.mjs +69 -0
- package/lib/repo-label.mjs +31 -0
- package/lib/stats.mjs +112 -0
- package/package.json +37 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 caelum0x
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
|
-
#
|
|
1
|
+
# git-year-wrapped
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate a shareable year-in-review card from any public git repo's commit
|
|
4
|
+
history. Works with GitHub, GitLab, Rithub, or any other host that speaks
|
|
5
|
+
plain git — the tool just clones the repo and reads its real commit log, no
|
|
6
|
+
host-specific API, no login.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npx git-year-wrapped https://github.com/facebook/react
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
That's it. One argument, no signup, no API key, no config file. It writes an
|
|
13
|
+
SVG card you can open in any browser, drop in a README, or convert to PNG with
|
|
14
|
+
any image tool, and prints the same stats to your terminal.
|
|
15
|
+
|
|
16
|
+
## What it computes
|
|
17
|
+
|
|
18
|
+
From the real commit log of the repo you point it at:
|
|
19
|
+
|
|
20
|
+
- total commits in the window
|
|
21
|
+
- active days and longest daily streak
|
|
22
|
+
- busiest weekday and hour (UTC)
|
|
23
|
+
- top languages touched, by file extension
|
|
24
|
+
- top contributors by commit count
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
git-year-wrapped <repo-url> [options]
|
|
30
|
+
|
|
31
|
+
--year <YYYY> Only count commits from this calendar year (UTC).
|
|
32
|
+
Default: the current year, falling back to all-time
|
|
33
|
+
history if that year has no commits in this repo.
|
|
34
|
+
--since-days <N> Only count commits from the last N days instead of a
|
|
35
|
+
calendar year.
|
|
36
|
+
--all-time Count the repo's entire history.
|
|
37
|
+
--out <path> Where to write the SVG card. Default: ./<repo>-wrapped.svg
|
|
38
|
+
--accent <#hex> Accent color for the card. Default: #4f8cff
|
|
39
|
+
--json Also print the computed stats as JSON.
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Examples:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
npx git-year-wrapped https://github.com/facebook/react
|
|
46
|
+
npx git-year-wrapped https://rithub.dev/caelum0x/git-year-wrapped --year 2026
|
|
47
|
+
npx git-year-wrapped git@gitlab.com:group/project.git --all-time --json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## How it works
|
|
51
|
+
|
|
52
|
+
1. A `git clone --bare --filter=blob:none` of the URL you pass in, into a
|
|
53
|
+
temp directory. The partial-clone filter means file *contents* are not
|
|
54
|
+
downloaded, only commit and tree metadata, so even large repos are quick.
|
|
55
|
+
Hosts that don't support the filter just ignore it; nothing breaks.
|
|
56
|
+
2. `git log --name-only` over that clone to read every commit's author, date,
|
|
57
|
+
and changed file paths.
|
|
58
|
+
3. Plain arithmetic over that log — no network calls beyond the clone itself,
|
|
59
|
+
no AI, nothing sent anywhere.
|
|
60
|
+
4. An SVG card rendered from the result, written to disk.
|
|
61
|
+
|
|
62
|
+
## Requirements
|
|
63
|
+
|
|
64
|
+
- Node.js 18+
|
|
65
|
+
- `git` on your `PATH`
|
|
66
|
+
|
|
67
|
+
No other dependencies. Nothing is installed beyond this package itself.
|
|
68
|
+
|
|
69
|
+
## Why this is free
|
|
70
|
+
|
|
71
|
+
This is published by the team behind [Ritgram](https://ritgram.rithub.dev), a
|
|
72
|
+
social feed for developers who want their work seen, next to
|
|
73
|
+
[Rithub](https://rithub.dev). It works on any repo on any host, including
|
|
74
|
+
your competitors' — if it's useful to you, that's the whole point. If you want
|
|
75
|
+
to post what it finds, Ritgram is one place to put it.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { writeFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
import { cloneBare, cleanup } from "../lib/clone.mjs";
|
|
6
|
+
import { readCommits } from "../lib/log.mjs";
|
|
7
|
+
import { filterByWindow, computeStats } from "../lib/stats.mjs";
|
|
8
|
+
import { renderCard } from "../lib/card.mjs";
|
|
9
|
+
import { repoLabelFromUrl } from "../lib/repo-label.mjs";
|
|
10
|
+
|
|
11
|
+
const HELP = `git-year-wrapped <repo-url> [options]
|
|
12
|
+
|
|
13
|
+
Generate a shareable year-in-review card from any public git repo's commit
|
|
14
|
+
history - GitHub, GitLab, Rithub, or any other host that speaks plain git.
|
|
15
|
+
No signup, no API keys, no telemetry; runs entirely on your machine.
|
|
16
|
+
|
|
17
|
+
Options:
|
|
18
|
+
--year <YYYY> Only count commits from this calendar year (UTC).
|
|
19
|
+
Default: the current year, falling back to all-time
|
|
20
|
+
history if that year has no commits in this repo.
|
|
21
|
+
--since-days <N> Only count commits from the last N days instead of a
|
|
22
|
+
calendar year.
|
|
23
|
+
--all-time Count the repo's entire history.
|
|
24
|
+
--out <path> Where to write the SVG card. Default:
|
|
25
|
+
./<repo>-wrapped.svg
|
|
26
|
+
--accent <#hex> Accent color for the card. Default: #4f8cff
|
|
27
|
+
--json Also print the computed stats as JSON.
|
|
28
|
+
-h, --help Show this help.
|
|
29
|
+
-v, --version Show the version.
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
npx git-year-wrapped https://github.com/facebook/react
|
|
33
|
+
npx git-year-wrapped https://rithub.dev/caelum0x/git-year-wrapped --year 2026
|
|
34
|
+
npx git-year-wrapped git@gitlab.com:group/project.git --all-time --json
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
function parseArgs(argv) {
|
|
38
|
+
const args = { repoUrl: null, year: null, sinceDays: null, allTime: false, out: null, accent: null, json: false };
|
|
39
|
+
const rest = [...argv];
|
|
40
|
+
|
|
41
|
+
while (rest.length > 0) {
|
|
42
|
+
const token = rest.shift();
|
|
43
|
+
switch (token) {
|
|
44
|
+
case "-h":
|
|
45
|
+
case "--help":
|
|
46
|
+
process.stdout.write(HELP);
|
|
47
|
+
process.exit(0);
|
|
48
|
+
break;
|
|
49
|
+
case "-v":
|
|
50
|
+
case "--version": {
|
|
51
|
+
process.stdout.write("1.0.0\n");
|
|
52
|
+
process.exit(0);
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "--year":
|
|
56
|
+
args.year = Number(rest.shift());
|
|
57
|
+
break;
|
|
58
|
+
case "--since-days":
|
|
59
|
+
args.sinceDays = Number(rest.shift());
|
|
60
|
+
break;
|
|
61
|
+
case "--all-time":
|
|
62
|
+
args.allTime = true;
|
|
63
|
+
break;
|
|
64
|
+
case "--out":
|
|
65
|
+
args.out = rest.shift();
|
|
66
|
+
break;
|
|
67
|
+
case "--accent":
|
|
68
|
+
args.accent = rest.shift();
|
|
69
|
+
break;
|
|
70
|
+
case "--json":
|
|
71
|
+
args.json = true;
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
if (!args.repoUrl && !token.startsWith("-")) {
|
|
75
|
+
args.repoUrl = token;
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error(`Unknown argument: ${token}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return args;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function fail(message) {
|
|
86
|
+
process.stderr.write(`git-year-wrapped: ${message}\n`);
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function main() {
|
|
91
|
+
let args;
|
|
92
|
+
try {
|
|
93
|
+
args = parseArgs(process.argv.slice(2));
|
|
94
|
+
} catch (err) {
|
|
95
|
+
fail(err.message);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!args.repoUrl) {
|
|
100
|
+
process.stdout.write(HELP);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const repoLabel = repoLabelFromUrl(args.repoUrl);
|
|
106
|
+
let gitDir;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
gitDir = cloneBare(args.repoUrl);
|
|
110
|
+
const commits = readCommits(gitDir);
|
|
111
|
+
|
|
112
|
+
let window;
|
|
113
|
+
let windowLabel;
|
|
114
|
+
if (args.allTime) {
|
|
115
|
+
window = {};
|
|
116
|
+
windowLabel = "All-time";
|
|
117
|
+
} else if (args.sinceDays) {
|
|
118
|
+
window = { sinceDays: args.sinceDays };
|
|
119
|
+
windowLabel = `Last ${args.sinceDays} days`;
|
|
120
|
+
} else {
|
|
121
|
+
const year = args.year || new Date().getUTCFullYear();
|
|
122
|
+
const inYear = filterByWindow(commits, { year });
|
|
123
|
+
if (inYear.length === 0 && !args.year) {
|
|
124
|
+
// No activity in the current calendar year yet (or a repo whose
|
|
125
|
+
// history predates it) - fall back to all-time rather than
|
|
126
|
+
// handing a stranger an empty card.
|
|
127
|
+
window = {};
|
|
128
|
+
windowLabel = "All-time";
|
|
129
|
+
} else {
|
|
130
|
+
window = { year };
|
|
131
|
+
windowLabel = `${year} Wrapped`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const windowed = filterByWindow(commits, window);
|
|
136
|
+
const stats = computeStats(windowed);
|
|
137
|
+
|
|
138
|
+
if (stats.totalCommits === 0) {
|
|
139
|
+
fail(`No commits found for "${repoLabel}" in that window.`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const svg = renderCard({
|
|
144
|
+
repoLabel,
|
|
145
|
+
windowLabel,
|
|
146
|
+
stats,
|
|
147
|
+
accent: args.accent || undefined,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const outPath = resolve(args.out || `${repoLabel.replace(/[\\/]/g, "-")}-wrapped.svg`);
|
|
151
|
+
writeFileSync(outPath, svg, "utf8");
|
|
152
|
+
|
|
153
|
+
console.log(`${repoLabel} — ${windowLabel}`);
|
|
154
|
+
console.log(` commits: ${stats.totalCommits}`);
|
|
155
|
+
console.log(` active days: ${stats.activeDays}`);
|
|
156
|
+
console.log(` longest streak: ${stats.longestStreak} day(s)`);
|
|
157
|
+
console.log(` busiest day: ${stats.busiestWeekday ?? "—"}`);
|
|
158
|
+
console.log(` busiest hour UTC: ${stats.busiestHour ?? "—"}:00`);
|
|
159
|
+
console.log(
|
|
160
|
+
` top languages: ${stats.topLanguages.map((l) => l.language).join(", ") || "—"}`
|
|
161
|
+
);
|
|
162
|
+
console.log(
|
|
163
|
+
` top contributor: ${
|
|
164
|
+
stats.topContributors[0]
|
|
165
|
+
? `${stats.topContributors[0].name} (${stats.topContributors[0].count} commits)`
|
|
166
|
+
: "—"
|
|
167
|
+
}`
|
|
168
|
+
);
|
|
169
|
+
console.log("");
|
|
170
|
+
console.log(`Card written to ${outPath}`);
|
|
171
|
+
|
|
172
|
+
if (args.json) {
|
|
173
|
+
console.log(JSON.stringify({ repoLabel, windowLabel, stats }, null, 2));
|
|
174
|
+
}
|
|
175
|
+
} catch (err) {
|
|
176
|
+
fail(err.message || String(err));
|
|
177
|
+
} finally {
|
|
178
|
+
if (gitDir) cleanup(gitDir);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
main();
|
package/lib/card.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const WIDTH = 1200;
|
|
2
|
+
const HEIGHT = 630;
|
|
3
|
+
const FONT_STACK =
|
|
4
|
+
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} value
|
|
8
|
+
*/
|
|
9
|
+
function escapeXml(value) {
|
|
10
|
+
return String(value)
|
|
11
|
+
.replace(/&/g, "&")
|
|
12
|
+
.replace(/</g, "<")
|
|
13
|
+
.replace(/>/g, ">")
|
|
14
|
+
.replace(/"/g, """)
|
|
15
|
+
.replace(/'/g, "'");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Plain, flat, no-gradient stat tile: a big number over a small label.
|
|
20
|
+
*/
|
|
21
|
+
function statTile(x, y, w, h, value, label, accent) {
|
|
22
|
+
return `
|
|
23
|
+
<g>
|
|
24
|
+
<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="14" fill="#15161a" stroke="#2a2b30" stroke-width="1"/>
|
|
25
|
+
<text x="${x + 28}" y="${y + h / 2 - 4}" font-family="${FONT_STACK}" font-size="52" font-weight="700" fill="${accent}">${escapeXml(value)}</text>
|
|
26
|
+
<text x="${x + 28}" y="${y + h - 22}" font-family="${FONT_STACK}" font-size="18" fill="#9a9ba3" letter-spacing="0.5">${escapeXml(label)}</text>
|
|
27
|
+
</g>`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {object} params
|
|
32
|
+
* @param {string} params.repoLabel e.g. "owner/repo"
|
|
33
|
+
* @param {string} params.windowLabel e.g. "2026 Wrapped" or "Last 365 days"
|
|
34
|
+
* @param {ReturnType<typeof import("./stats.mjs").computeStats>} params.stats
|
|
35
|
+
* @param {string} [params.accent] hex color, default a single muted accent
|
|
36
|
+
* @returns {string} SVG markup
|
|
37
|
+
*/
|
|
38
|
+
export function renderCard({ repoLabel, windowLabel, stats, accent = "#4f8cff" }) {
|
|
39
|
+
const topContributor = stats.topContributors[0];
|
|
40
|
+
|
|
41
|
+
const languageLine = stats.topLanguages.length
|
|
42
|
+
? stats.topLanguages.map((l) => l.language).join(" · ")
|
|
43
|
+
: "no file data";
|
|
44
|
+
|
|
45
|
+
const tiles = [
|
|
46
|
+
statTile(60, 240, 260, 150, String(stats.totalCommits), "COMMITS", accent),
|
|
47
|
+
statTile(340, 240, 260, 150, String(stats.activeDays), "ACTIVE DAYS", accent),
|
|
48
|
+
statTile(620, 240, 260, 150, String(stats.longestStreak), "LONGEST STREAK (DAYS)", accent),
|
|
49
|
+
statTile(
|
|
50
|
+
900,
|
|
51
|
+
240,
|
|
52
|
+
240,
|
|
53
|
+
150,
|
|
54
|
+
stats.busiestWeekday ? stats.busiestWeekday.slice(0, 3).toUpperCase() : "—",
|
|
55
|
+
"BUSIEST DAY",
|
|
56
|
+
accent
|
|
57
|
+
),
|
|
58
|
+
].join("\n");
|
|
59
|
+
|
|
60
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${WIDTH}" height="${HEIGHT}" viewBox="0 0 ${WIDTH} ${HEIGHT}">
|
|
61
|
+
<rect width="${WIDTH}" height="${HEIGHT}" fill="#0a0a0c"/>
|
|
62
|
+
<text x="60" y="90" font-family="${FONT_STACK}" font-size="22" font-weight="600" fill="${accent}" letter-spacing="2">GIT WRAPPED</text>
|
|
63
|
+
<text x="60" y="160" font-family="${FONT_STACK}" font-size="54" font-weight="700" fill="#f4f4f5">${escapeXml(repoLabel)}</text>
|
|
64
|
+
<text x="60" y="200" font-family="${FONT_STACK}" font-size="22" fill="#9a9ba3">${escapeXml(windowLabel)}</text>
|
|
65
|
+
${tiles}
|
|
66
|
+
<text x="60" y="450" font-family="${FONT_STACK}" font-size="18" fill="#9a9ba3" letter-spacing="0.5">TOP LANGUAGES</text>
|
|
67
|
+
<text x="60" y="482" font-family="${FONT_STACK}" font-size="26" fill="#f4f4f5">${escapeXml(languageLine)}</text>
|
|
68
|
+
<text x="60" y="540" font-family="${FONT_STACK}" font-size="18" fill="#9a9ba3" letter-spacing="0.5">TOP CONTRIBUTOR</text>
|
|
69
|
+
<text x="60" y="572" font-family="${FONT_STACK}" font-size="26" fill="#f4f4f5">${escapeXml(
|
|
70
|
+
topContributor ? `${topContributor.name} (${topContributor.count} commits)` : "—"
|
|
71
|
+
)}</text>
|
|
72
|
+
<text x="${WIDTH - 60}" y="${HEIGHT - 30}" font-family="${FONT_STACK}" font-size="16" fill="#5a5b63" text-anchor="end">git-year-wrapped</text>
|
|
73
|
+
</svg>`;
|
|
74
|
+
}
|
package/lib/clone.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bare-clone any public git repo (GitHub, GitLab, Rithub, or any other host
|
|
8
|
+
* that speaks the plain git protocol over http(s)/ssh) into a temp dir.
|
|
9
|
+
*
|
|
10
|
+
* Uses --filter=blob:none where the server supports it (git protocol v2) so
|
|
11
|
+
* file *contents* are not downloaded, only commit/tree metadata - this keeps
|
|
12
|
+
* the clone fast even for large repos. Hosts that don't support the filter
|
|
13
|
+
* just ignore it and git falls back to a normal clone; nothing breaks.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} repoUrl
|
|
16
|
+
* @returns {string} path to the temporary bare repo
|
|
17
|
+
*/
|
|
18
|
+
export function cloneBare(repoUrl) {
|
|
19
|
+
const dir = mkdtempSync(join(tmpdir(), "git-year-wrapped-"));
|
|
20
|
+
|
|
21
|
+
const result = spawnSync(
|
|
22
|
+
"git",
|
|
23
|
+
["clone", "--bare", "--filter=blob:none", "--no-tags", "--quiet", repoUrl, dir],
|
|
24
|
+
{ stdio: ["ignore", "pipe", "pipe"], encoding: "utf8" }
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (result.error) {
|
|
28
|
+
cleanup(dir);
|
|
29
|
+
if (result.error.code === "ENOENT") {
|
|
30
|
+
throw new Error("git-year-wrapped needs the git CLI installed and on your PATH.");
|
|
31
|
+
}
|
|
32
|
+
throw result.error;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (result.status !== 0) {
|
|
36
|
+
cleanup(dir);
|
|
37
|
+
const stderr = (result.stderr || "").trim();
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Could not clone "${repoUrl}". Is the repo public and the URL correct?${stderr ? `\n${stderr}` : ""}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return dir;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} dir
|
|
48
|
+
*/
|
|
49
|
+
export function cleanup(dir) {
|
|
50
|
+
try {
|
|
51
|
+
rmSync(dir, { recursive: true, force: true });
|
|
52
|
+
} catch {
|
|
53
|
+
// best effort; a leftover temp dir is not worth failing the run over
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// Small, intentionally non-exhaustive extension -> language map, enough to
|
|
2
|
+
// label the "top languages" stat tile. Unknown extensions fall back to the
|
|
3
|
+
// raw extension string so nothing is silently dropped.
|
|
4
|
+
export const EXTENSION_TO_LANGUAGE = {
|
|
5
|
+
js: "JavaScript",
|
|
6
|
+
mjs: "JavaScript",
|
|
7
|
+
cjs: "JavaScript",
|
|
8
|
+
jsx: "JavaScript",
|
|
9
|
+
ts: "TypeScript",
|
|
10
|
+
tsx: "TypeScript",
|
|
11
|
+
py: "Python",
|
|
12
|
+
rb: "Ruby",
|
|
13
|
+
go: "Go",
|
|
14
|
+
rs: "Rust",
|
|
15
|
+
java: "Java",
|
|
16
|
+
kt: "Kotlin",
|
|
17
|
+
kts: "Kotlin",
|
|
18
|
+
swift: "Swift",
|
|
19
|
+
c: "C",
|
|
20
|
+
h: "C",
|
|
21
|
+
cpp: "C++",
|
|
22
|
+
cc: "C++",
|
|
23
|
+
hpp: "C++",
|
|
24
|
+
cs: "C#",
|
|
25
|
+
php: "PHP",
|
|
26
|
+
sh: "Shell",
|
|
27
|
+
bash: "Shell",
|
|
28
|
+
zsh: "Shell",
|
|
29
|
+
sql: "SQL",
|
|
30
|
+
html: "HTML",
|
|
31
|
+
css: "CSS",
|
|
32
|
+
scss: "CSS",
|
|
33
|
+
less: "CSS",
|
|
34
|
+
json: "JSON",
|
|
35
|
+
yml: "YAML",
|
|
36
|
+
yaml: "YAML",
|
|
37
|
+
toml: "TOML",
|
|
38
|
+
md: "Markdown",
|
|
39
|
+
mdx: "Markdown",
|
|
40
|
+
vue: "Vue",
|
|
41
|
+
svelte: "Svelte",
|
|
42
|
+
dart: "Dart",
|
|
43
|
+
ex: "Elixir",
|
|
44
|
+
exs: "Elixir",
|
|
45
|
+
erl: "Erlang",
|
|
46
|
+
scala: "Scala",
|
|
47
|
+
lua: "Lua",
|
|
48
|
+
r: "R",
|
|
49
|
+
jl: "Julia",
|
|
50
|
+
proto: "Protocol Buffers",
|
|
51
|
+
graphql: "GraphQL",
|
|
52
|
+
gql: "GraphQL",
|
|
53
|
+
dockerfile: "Dockerfile",
|
|
54
|
+
tf: "Terraform",
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {string} filePath
|
|
59
|
+
* @returns {string | null} a display language name, or null for extensionless/dotfiles
|
|
60
|
+
*/
|
|
61
|
+
export function languageForFile(filePath) {
|
|
62
|
+
const base = filePath.split("/").pop() || filePath;
|
|
63
|
+
if (base.toLowerCase() === "dockerfile") return "Dockerfile";
|
|
64
|
+
const dot = base.lastIndexOf(".");
|
|
65
|
+
if (dot <= 0) return null; // no extension, or a dotfile like .gitignore
|
|
66
|
+
const ext = base.slice(dot + 1).toLowerCase();
|
|
67
|
+
if (!ext) return null;
|
|
68
|
+
return EXTENSION_TO_LANGUAGE[ext] || null;
|
|
69
|
+
}
|
package/lib/log.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
const RECORD_START = "\x01";
|
|
4
|
+
const FIELD_SEP = "\x1f";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {object} Commit
|
|
8
|
+
* @property {string} hash
|
|
9
|
+
* @property {string} authorName
|
|
10
|
+
* @property {string} authorEmail
|
|
11
|
+
* @property {Date} date
|
|
12
|
+
* @property {string[]} files
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Read the full commit history of a bare repo cloned by clone.mjs.
|
|
17
|
+
* Uses --name-only, which only needs tree metadata (which paths changed),
|
|
18
|
+
* not blob content - so it stays fast even on a --filter=blob:none clone.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} gitDir path to the bare repo
|
|
21
|
+
* @returns {Commit[]}
|
|
22
|
+
*/
|
|
23
|
+
export function readCommits(gitDir) {
|
|
24
|
+
const result = spawnSync(
|
|
25
|
+
"git",
|
|
26
|
+
[
|
|
27
|
+
"--git-dir",
|
|
28
|
+
gitDir,
|
|
29
|
+
"log",
|
|
30
|
+
"--all",
|
|
31
|
+
"--no-merges",
|
|
32
|
+
`--pretty=format:${RECORD_START}%H${FIELD_SEP}%an${FIELD_SEP}%ae${FIELD_SEP}%aI`,
|
|
33
|
+
"--name-only",
|
|
34
|
+
],
|
|
35
|
+
{ encoding: "utf8", maxBuffer: 1024 * 1024 * 256 }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (result.status !== 0) {
|
|
39
|
+
const stderr = (result.stderr || "").trim();
|
|
40
|
+
throw new Error(`git log failed${stderr ? `: ${stderr}` : ""}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const records = (result.stdout || "").split(RECORD_START).filter(Boolean);
|
|
44
|
+
const commits = [];
|
|
45
|
+
|
|
46
|
+
for (const record of records) {
|
|
47
|
+
const newlineIndex = record.indexOf("\n");
|
|
48
|
+
const header = newlineIndex === -1 ? record : record.slice(0, newlineIndex);
|
|
49
|
+
const body = newlineIndex === -1 ? "" : record.slice(newlineIndex + 1);
|
|
50
|
+
|
|
51
|
+
const [hash, authorName, authorEmail, isoDate] = header.split(FIELD_SEP);
|
|
52
|
+
if (!hash || !isoDate) continue;
|
|
53
|
+
|
|
54
|
+
const files = body
|
|
55
|
+
.split("\n")
|
|
56
|
+
.map((line) => line.trim())
|
|
57
|
+
.filter(Boolean);
|
|
58
|
+
|
|
59
|
+
commits.push({
|
|
60
|
+
hash,
|
|
61
|
+
authorName: authorName || "unknown",
|
|
62
|
+
authorEmail: authorEmail || "",
|
|
63
|
+
date: new Date(isoDate),
|
|
64
|
+
files,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return commits;
|
|
69
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn any git remote URL into a short "owner/repo" style label for the
|
|
3
|
+
* card title. Falls back to the raw URL if the shape is unrecognized.
|
|
4
|
+
*
|
|
5
|
+
* Handles https://host/owner/repo(.git), git@host:owner/repo.git, and
|
|
6
|
+
* ssh://git@host/owner/repo.git - the same three shapes GitHub, GitLab and
|
|
7
|
+
* Rithub all use.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} repoUrl
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function repoLabelFromUrl(repoUrl) {
|
|
13
|
+
const stripped = repoUrl.replace(/\.git$/, "");
|
|
14
|
+
|
|
15
|
+
const scpMatch = stripped.match(/^[^@]+@[^:]+:(.+)$/);
|
|
16
|
+
if (scpMatch) {
|
|
17
|
+
const parts = scpMatch[1].split("/").filter(Boolean);
|
|
18
|
+
if (parts.length >= 2) return parts.slice(-2).join("/");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(stripped);
|
|
23
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
24
|
+
if (parts.length >= 2) return parts.slice(-2).join("/");
|
|
25
|
+
if (parts.length === 1) return parts[0];
|
|
26
|
+
} catch {
|
|
27
|
+
// not a parseable URL - fall through to the raw string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return stripped;
|
|
31
|
+
}
|
package/lib/stats.mjs
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { languageForFile } from "./languages.mjs";
|
|
2
|
+
|
|
3
|
+
const WEEKDAY_NAMES = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
4
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {import("./log.mjs").Commit[]} commits
|
|
8
|
+
* @param {{ year?: number, sinceDays?: number }} window
|
|
9
|
+
* @returns {import("./log.mjs").Commit[]}
|
|
10
|
+
*/
|
|
11
|
+
export function filterByWindow(commits, window) {
|
|
12
|
+
if (window.year) {
|
|
13
|
+
const start = new Date(Date.UTC(window.year, 0, 1));
|
|
14
|
+
const end = new Date(Date.UTC(window.year + 1, 0, 1));
|
|
15
|
+
return commits.filter((c) => c.date >= start && c.date < end);
|
|
16
|
+
}
|
|
17
|
+
if (window.sinceDays) {
|
|
18
|
+
const cutoff = new Date(Date.now() - window.sinceDays * DAY_MS);
|
|
19
|
+
return commits.filter((c) => c.date >= cutoff);
|
|
20
|
+
}
|
|
21
|
+
return commits;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function dateKey(date) {
|
|
25
|
+
return date.toISOString().slice(0, 10); // YYYY-MM-DD, UTC
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {import("./log.mjs").Commit[]} commits
|
|
30
|
+
*/
|
|
31
|
+
export function computeStats(commits) {
|
|
32
|
+
if (commits.length === 0) {
|
|
33
|
+
return {
|
|
34
|
+
totalCommits: 0,
|
|
35
|
+
activeDays: 0,
|
|
36
|
+
longestStreak: 0,
|
|
37
|
+
busiestWeekday: null,
|
|
38
|
+
busiestHour: null,
|
|
39
|
+
topContributors: [],
|
|
40
|
+
topLanguages: [],
|
|
41
|
+
firstDate: null,
|
|
42
|
+
lastDate: null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const sorted = [...commits].sort((a, b) => a.date - b.date);
|
|
47
|
+
|
|
48
|
+
const dayCounts = new Map();
|
|
49
|
+
const weekdayCounts = new Array(7).fill(0);
|
|
50
|
+
const hourCounts = new Array(24).fill(0);
|
|
51
|
+
const contributorCounts = new Map();
|
|
52
|
+
const languageCounts = new Map();
|
|
53
|
+
|
|
54
|
+
for (const commit of sorted) {
|
|
55
|
+
const key = dateKey(commit.date);
|
|
56
|
+
dayCounts.set(key, (dayCounts.get(key) || 0) + 1);
|
|
57
|
+
weekdayCounts[commit.date.getUTCDay()] += 1;
|
|
58
|
+
hourCounts[commit.date.getUTCHours()] += 1;
|
|
59
|
+
|
|
60
|
+
const who = commit.authorName || commit.authorEmail || "unknown";
|
|
61
|
+
contributorCounts.set(who, (contributorCounts.get(who) || 0) + 1);
|
|
62
|
+
|
|
63
|
+
const seenLanguages = new Set();
|
|
64
|
+
for (const file of commit.files) {
|
|
65
|
+
const lang = languageForFile(file);
|
|
66
|
+
if (lang && !seenLanguages.has(lang)) {
|
|
67
|
+
seenLanguages.add(lang);
|
|
68
|
+
languageCounts.set(lang, (languageCounts.get(lang) || 0) + 1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const activeDayKeys = [...dayCounts.keys()].sort();
|
|
74
|
+
let longestStreak = 0;
|
|
75
|
+
let currentRun = 0;
|
|
76
|
+
let previousKey = null;
|
|
77
|
+
for (const key of activeDayKeys) {
|
|
78
|
+
if (previousKey !== null) {
|
|
79
|
+
const gapDays = Math.round((Date.parse(key) - Date.parse(previousKey)) / DAY_MS);
|
|
80
|
+
currentRun = gapDays === 1 ? currentRun + 1 : 1;
|
|
81
|
+
} else {
|
|
82
|
+
currentRun = 1;
|
|
83
|
+
}
|
|
84
|
+
longestStreak = Math.max(longestStreak, currentRun);
|
|
85
|
+
previousKey = key;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const busiestWeekdayIndex = weekdayCounts.indexOf(Math.max(...weekdayCounts));
|
|
89
|
+
const busiestHour = hourCounts.indexOf(Math.max(...hourCounts));
|
|
90
|
+
|
|
91
|
+
const topContributors = [...contributorCounts.entries()]
|
|
92
|
+
.sort((a, b) => b[1] - a[1])
|
|
93
|
+
.slice(0, 3)
|
|
94
|
+
.map(([name, count]) => ({ name, count }));
|
|
95
|
+
|
|
96
|
+
const topLanguages = [...languageCounts.entries()]
|
|
97
|
+
.sort((a, b) => b[1] - a[1])
|
|
98
|
+
.slice(0, 5)
|
|
99
|
+
.map(([language, commitsTouched]) => ({ language, commitsTouched }));
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
totalCommits: sorted.length,
|
|
103
|
+
activeDays: dayCounts.size,
|
|
104
|
+
longestStreak,
|
|
105
|
+
busiestWeekday: WEEKDAY_NAMES[busiestWeekdayIndex],
|
|
106
|
+
busiestHour,
|
|
107
|
+
topContributors,
|
|
108
|
+
topLanguages,
|
|
109
|
+
firstDate: sorted[0].date,
|
|
110
|
+
lastDate: sorted[sorted.length - 1].date,
|
|
111
|
+
};
|
|
112
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-year-wrapped",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate a shareable year-in-review card from any public git repo's commit history (GitHub, GitLab, Rithub, or any other git host). No signup, no API keys, no telemetry.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"git-year-wrapped": "bin/git-year-wrapped.mjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"lib",
|
|
13
|
+
"README.md",
|
|
14
|
+
"LICENSE"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://rithub.dev/caelum0x/git-year-wrapped.git"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://rithub.dev/caelum0x/git-year-wrapped",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://rithub.dev/caelum0x/git-year-wrapped/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"git",
|
|
29
|
+
"github",
|
|
30
|
+
"gitlab",
|
|
31
|
+
"year-in-review",
|
|
32
|
+
"wrapped",
|
|
33
|
+
"commit-history",
|
|
34
|
+
"cli",
|
|
35
|
+
"svg",
|
|
36
|
+
"developer-tools"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {}
|
|
39
|
+
}
|