Skip to content

Commit d6ba38f

Browse files
committed
✨ support codeberg + gitlab . Add cli tool
1 parent bf17575 commit d6ba38f

31 files changed

Lines changed: 723 additions & 116 deletions

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ inputs:
2424
2525
- palette: A preset of color, one of [github, github-dark, github-light]
2626
- color_snake: Color of the snake
27-
- color_dots: Coma separated list of dots color.
27+
- color_dots: Coma separated list of dots color.
2828
The first one is 0 contribution, then it goes from the low contribution to the highest.
2929
Exactly 5 colors are expected.
3030
example:

bun.lock

Lines changed: 38 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"repository": "github:platane/snk",
77
"devDependencies": {
88
"@types/bun": "1.3.4",
9+
"@types/node": "24.12.2",
910
"prettier": "3.6.2",
1011
"typescript": "5.9.3"
1112
},
@@ -17,6 +18,7 @@
1718
"lint": "prettier -c '**/*.{ts,js,json,md,yml,yaml}' '!packages/*/dist/**' '!svg-only/dist/**'",
1819
"dev:demo": "( cd packages/demo ; npm run dev )",
1920
"build:demo": "( cd packages/demo ; npm run build )",
20-
"build:action": "( cd packages/action ; npm run build )"
21+
"build:action": "( cd packages/action ; npm run build )",
22+
"build:lib": "( cd packages/generate-snake-animation ; npm run build )"
2123
}
2224
}

packages/action/generateContributionSnake.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/action/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import * as fs from "node:fs";
22
import * as path from "node:path";
3-
import { parseOutputsOption } from "./outputsOptions";
3+
import { generateSnakeAnimation } from "generate-snake-animation/generateSnakeAnimation";
4+
import { parseOutputsOption } from "generate-snake-animation/outputsOptions";
45
import * as githubAction from "./github-action";
56

67
(async () => {
78
try {
89
const userName = githubAction.getInput("github_user_name");
10+
const githubToken =
11+
process.env.GITHUB_TOKEN ?? githubAction.getInput("github_token");
12+
913
const outputsRaw = [
1014
...githubAction.getInput("outputs").split("\n"),
1115
//
@@ -17,15 +21,11 @@ import * as githubAction from "./github-action";
1721
.filter(Boolean);
1822

1923
const outputs = parseOutputsOption(outputsRaw);
20-
const githubToken =
21-
process.env.GITHUB_TOKEN ?? githubAction.getInput("github_token");
2224

23-
const { generateContributionSnake } = await import(
24-
"./generateContributionSnake"
25+
const results = await generateSnakeAnimation(
26+
{ platform: "github", username: userName, githubToken },
27+
outputs,
2528
);
26-
const results = await generateContributionSnake(userName, outputs, {
27-
githubToken,
28-
});
2929

3030
outputs.forEach((out, i) => {
3131
const result = results[i];

packages/action/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
"version": "1.0.0",
44
"dependencies": {
55
"@actions/core": "1.11.1",
6-
"@snk/gif-creator": "1.0.0",
7-
"@snk/github-user-contribution": "1.0.0",
8-
"@snk/solver": "1.0.0",
9-
"@snk/svg-creator": "1.0.0",
10-
"@snk/types": "1.0.0"
6+
"generate-snake-animation": "1.0.0"
117
},
128
"devDependencies": {
139
"@vercel/ncc": "0.38.4"

packages/action/palettes.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/demo/interactive/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { parseEntry } from "@snk/action/outputsOptions";
2-
import { basePalettes } from "@snk/action/palettes";
3-
import { userContributionToGrid } from "@snk/action/userContributionToGrid";
41
import {
52
Options as DrawOptions,
63
drawLerpWorld,
74
getCanvasWorldSize,
85
} from "@snk/draw/drawWorld";
96
import type { Res } from "@snk/github-user-contribution";
7+
import { cellsToGrid } from "generate-snake-animation/cellsToGrid";
8+
import { parseEntry } from "generate-snake-animation/outputsOptions";
9+
import { basePalettes } from "generate-snake-animation/palettes";
1010
import { step } from "@snk/solver/step";
1111
import { createSvg } from "@snk/svg-creator";
1212
import { Color, copyGrid, Grid } from "@snk/types/grid";
@@ -312,7 +312,7 @@ const onSubmit = async (userName: string) => {
312312
);
313313
const cells = (await res.json()) as Res;
314314

315-
const grid = userContributionToGrid(cells);
315+
const grid = cellsToGrid(cells);
316316

317317
const chain = await getChain(grid);
318318

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, expect, it } from "bun:test";
2+
import { getForgejoUserContribution } from "..";
3+
4+
describe("getForgejoUserContribution", () => {
5+
const promise = getForgejoUserContribution("Codeberg");
6+
7+
it("should resolve", async () => {
8+
await promise;
9+
});
10+
11+
it("should get around 365 cells", async () => {
12+
const cells = await promise;
13+
14+
expect(cells.length).toBeGreaterThanOrEqual(365);
15+
expect(cells.length).toBeLessThanOrEqual(365 + 7);
16+
});
17+
18+
it("cells should cover a full 7-row grid with no gaps", async () => {
19+
const cells = await promise;
20+
21+
expect(cells.length).toBeGreaterThan(300);
22+
23+
const maxX = Math.max(...cells.map((c) => c.x));
24+
25+
// every (x, y) pair from (0,0) to (maxX-1, 6) must be present
26+
const missing = Array.from({ length: maxX }, (_, x) =>
27+
Array.from({ length: 7 }, (_, y) => ({ x, y })),
28+
)
29+
.flat()
30+
.filter(({ x, y }) => !cells.some((c) => c.x === x && c.y === y));
31+
32+
expect(missing).toEqual([]);
33+
});
34+
35+
it("cells should have level between 0 and 4", async () => {
36+
const cells = await promise;
37+
38+
for (const c of cells) {
39+
expect(c.level).toBeGreaterThanOrEqual(0);
40+
expect(c.level).toBeLessThanOrEqual(4);
41+
}
42+
});
43+
});

0 commit comments

Comments
 (0)