Skip to content

Commit aebc3a9

Browse files
author
release bot
committed
📦 3.0.0
1 parent 1574f65 commit aebc3a9

File tree

4 files changed

+54
-73
lines changed

4 files changed

+54
-73
lines changed

‎action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: "platane"
44

55
runs:
66
using: docker
7-
image: docker://platane/snk@sha256:2115ffeb538e355aa155630e6e32b6d77ea2345fa8584645c41ace7f5ad667fc
7+
image: docker://platane/snk@sha256:753878055e52fbbaf3148fdac4590e396f97581f1dc4c1f861701add7a1dc1b5
88

99
inputs:
1010
github_user_name:

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "snk",
33
"description": "Generates a snake game from a github user contributions grid",
4-
"version": "2.3.0",
4+
"version": "3.0.0",
55
"private": true,
66
"repository": "github:platane/snk",
77
"devDependencies": {

‎svg-only/dist/317.index.js‎ renamed to ‎svg-only/dist/407.index.js‎

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"use strict";
2-
exports.id = 317;
3-
exports.ids = [317];
2+
exports.id = 407;
3+
exports.ids = [407];
44
exports.modules = {
55

6-
/***/ 5317:
6+
/***/ 407:
77
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
88

99
// ESM COMPAT FLAG
@@ -17,37 +17,8 @@ __webpack_require__.d(__webpack_exports__, {
1717
// EXTERNAL MODULE: ../../node_modules/node-fetch/lib/index.js
1818
var lib = __webpack_require__(2197);
1919
var lib_default = /*#__PURE__*/__webpack_require__.n(lib);
20-
;// CONCATENATED MODULE: ../github-user-contribution/formatParams.ts
21-
const formatParams = (options = {}) => {
22-
const sp = new URLSearchParams();
23-
const o = { ...options };
24-
if ("year" in options) {
25-
o.from = `${options.year}-01-01`;
26-
o.to = `${options.year}-12-31`;
27-
}
28-
for (const s of ["from", "to"])
29-
if (o[s]) {
30-
const value = o[s];
31-
if (value >= formatDate(new Date()))
32-
throw new Error("Cannot get contribution for a date in the future.\nPlease limit your range to the current UTC day.");
33-
sp.set(s, value);
34-
}
35-
return sp.toString();
36-
};
37-
const formatDate = (d) => {
38-
const year = d.getUTCFullYear();
39-
const month = d.getUTCMonth() + 1;
40-
const date = d.getUTCDate();
41-
return [
42-
year,
43-
month.toString().padStart(2, "0"),
44-
date.toString().padStart(2, "0"),
45-
].join("-");
46-
};
47-
4820
;// CONCATENATED MODULE: ../github-user-contribution/index.ts
4921

50-
5122
/**
5223
* get the contribution grid from a github user page
5324
*
@@ -64,43 +35,50 @@ const formatDate = (d) => {
6435
* getGithubUserContribution("platane", { year: 2019 })
6536
*
6637
*/
67-
const getGithubUserContribution = async (userName, options = {}) => {
68-
// either use github.com/users/xxxx/contributions for previous years
69-
// or github.com/xxxx ( which gives the latest update to today result )
70-
const url = "year" in options || "from" in options || "to" in options
71-
? `https://github.com/users/${userName}/contributions?` +
72-
formatParams(options)
73-
: `https://github.com/${userName}`;
74-
const res = await lib_default()(url);
38+
const getGithubUserContribution = async (userName, o) => {
39+
const query = /* GraphQL */ `
40+
query ($login: String!) {
41+
user(login: $login) {
42+
contributionsCollection {
43+
contributionCalendar {
44+
weeks {
45+
contributionDays {
46+
contributionCount
47+
contributionLevel
48+
weekday
49+
date
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
`;
57+
const variables = { login: userName };
58+
const res = await lib_default()("https://api.github.com/graphql", {
59+
headers: {
60+
Authorization: `bearer ${o.githubToken}`,
61+
"Content-Type": "application/json",
62+
},
63+
method: "POST",
64+
body: JSON.stringify({ variables, query }),
65+
});
7566
if (!res.ok)
7667
throw new Error(res.statusText);
77-
const resText = await res.text();
78-
return parseUserPage(resText);
79-
};
80-
const parseUserPage = (content) => {
81-
// take roughly the table block
82-
const block = content
83-
.split(`aria-describedby="contribution-graph-description"`)[1]
84-
.split("<tbody>")[1]
85-
.split("</tbody>")[0];
86-
const cells = block.split("</tr>").flatMap((inside, y) => inside.split("</td>").flatMap((m) => {
87-
const date = m.match(/data-date="([^"]+)"/)?.[1];
88-
const literalLevel = m.match(/data-level="([^"]+)"/)?.[1];
89-
const literalX = m.match(/data-ix="([^"]+)"/)?.[1];
90-
const literalCount = m.match(/(No|\d+) contributions? on/)?.[1];
91-
if (date && literalLevel && literalX && literalCount)
92-
return [
93-
{
94-
x: +literalX,
95-
y,
96-
date,
97-
count: +literalCount,
98-
level: +literalLevel,
99-
},
100-
];
101-
return [];
102-
}));
103-
return cells;
68+
const { data, errors } = (await res.json());
69+
if (errors?.[0])
70+
throw errors[0];
71+
return data.user.contributionsCollection.contributionCalendar.weeks.flatMap(({ contributionDays }, x) => contributionDays.map((d) => ({
72+
x,
73+
y: d.weekday,
74+
date: d.date,
75+
count: d.contributionCount,
76+
level: (d.contributionLevel === "FOURTH_QUARTILE" && 4) ||
77+
(d.contributionLevel === "THIRD_QUARTILE" && 3) ||
78+
(d.contributionLevel === "SECOND_QUARTILE" && 2) ||
79+
(d.contributionLevel === "FIRST_QUARTILE" && 1) ||
80+
0,
81+
})));
10482
};
10583

10684
// EXTERNAL MODULE: ../types/grid.ts
@@ -655,9 +633,9 @@ const getPathToPose = (snake0, target, grid) => {
655633

656634

657635

658-
const generateContributionSnake = async (userName, outputs) => {
636+
const generateContributionSnake = async (userName, outputs, options) => {
659637
console.log("🎣 fetching github user contribution");
660-
const cells = await getGithubUserContribution(userName);
638+
const cells = await getGithubUserContribution(userName, options);
661639
const grid = userContributionToGrid(cells);
662640
const snake = snake4;
663641
console.log("📡 computing best route");

‎svg-only/dist/index.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,8 +3098,11 @@ const parseEntry = (entry) => {
30983098
core.getInput("gif_out_path"),
30993099
core.getInput("svg_out_path"),
31003100
]);
3101-
const { generateContributionSnake } = await Promise.all(/* import() */[__nccwpck_require__.e(197), __nccwpck_require__.e(317)]).then(__nccwpck_require__.bind(__nccwpck_require__, 5317));
3102-
const results = await generateContributionSnake(userName, outputs);
3101+
const githubToken = process.env.GITHUB_TOKEN;
3102+
const { generateContributionSnake } = await Promise.all(/* import() */[__nccwpck_require__.e(197), __nccwpck_require__.e(407)]).then(__nccwpck_require__.bind(__nccwpck_require__, 407));
3103+
const results = await generateContributionSnake(userName, outputs, {
3104+
githubToken,
3105+
});
31033106
outputs.forEach((out, i) => {
31043107
const result = results[i];
31053108
if (out?.filename && result) {

0 commit comments

Comments
 (0)