📦 3.0.0
This commit is contained in:
@@ -4,7 +4,7 @@ author: "platane"
|
|||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: docker
|
using: docker
|
||||||
image: docker://platane/snk@sha256:2115ffeb538e355aa155630e6e32b6d77ea2345fa8584645c41ace7f5ad667fc
|
image: docker://platane/snk@sha256:753878055e52fbbaf3148fdac4590e396f97581f1dc4c1f861701add7a1dc1b5
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
github_user_name:
|
github_user_name:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "snk",
|
"name": "snk",
|
||||||
"description": "Generates a snake game from a github user contributions grid",
|
"description": "Generates a snake game from a github user contributions grid",
|
||||||
"version": "2.3.0",
|
"version": "3.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"repository": "github:platane/snk",
|
"repository": "github:platane/snk",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
exports.id = 317;
|
exports.id = 407;
|
||||||
exports.ids = [317];
|
exports.ids = [407];
|
||||||
exports.modules = {
|
exports.modules = {
|
||||||
|
|
||||||
/***/ 5317:
|
/***/ 407:
|
||||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||||
|
|
||||||
// ESM COMPAT FLAG
|
// ESM COMPAT FLAG
|
||||||
@@ -17,37 +17,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|||||||
// EXTERNAL MODULE: ../../node_modules/node-fetch/lib/index.js
|
// EXTERNAL MODULE: ../../node_modules/node-fetch/lib/index.js
|
||||||
var lib = __webpack_require__(2197);
|
var lib = __webpack_require__(2197);
|
||||||
var lib_default = /*#__PURE__*/__webpack_require__.n(lib);
|
var lib_default = /*#__PURE__*/__webpack_require__.n(lib);
|
||||||
;// CONCATENATED MODULE: ../github-user-contribution/formatParams.ts
|
|
||||||
const formatParams = (options = {}) => {
|
|
||||||
const sp = new URLSearchParams();
|
|
||||||
const o = { ...options };
|
|
||||||
if ("year" in options) {
|
|
||||||
o.from = `${options.year}-01-01`;
|
|
||||||
o.to = `${options.year}-12-31`;
|
|
||||||
}
|
|
||||||
for (const s of ["from", "to"])
|
|
||||||
if (o[s]) {
|
|
||||||
const value = o[s];
|
|
||||||
if (value >= formatDate(new Date()))
|
|
||||||
throw new Error("Cannot get contribution for a date in the future.\nPlease limit your range to the current UTC day.");
|
|
||||||
sp.set(s, value);
|
|
||||||
}
|
|
||||||
return sp.toString();
|
|
||||||
};
|
|
||||||
const formatDate = (d) => {
|
|
||||||
const year = d.getUTCFullYear();
|
|
||||||
const month = d.getUTCMonth() + 1;
|
|
||||||
const date = d.getUTCDate();
|
|
||||||
return [
|
|
||||||
year,
|
|
||||||
month.toString().padStart(2, "0"),
|
|
||||||
date.toString().padStart(2, "0"),
|
|
||||||
].join("-");
|
|
||||||
};
|
|
||||||
|
|
||||||
;// CONCATENATED MODULE: ../github-user-contribution/index.ts
|
;// CONCATENATED MODULE: ../github-user-contribution/index.ts
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the contribution grid from a github user page
|
* get the contribution grid from a github user page
|
||||||
*
|
*
|
||||||
@@ -64,43 +35,50 @@ const formatDate = (d) => {
|
|||||||
* getGithubUserContribution("platane", { year: 2019 })
|
* getGithubUserContribution("platane", { year: 2019 })
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
const getGithubUserContribution = async (userName, options = {}) => {
|
const getGithubUserContribution = async (userName, o) => {
|
||||||
// either use github.com/users/xxxx/contributions for previous years
|
const query = /* GraphQL */ `
|
||||||
// or github.com/xxxx ( which gives the latest update to today result )
|
query ($login: String!) {
|
||||||
const url = "year" in options || "from" in options || "to" in options
|
user(login: $login) {
|
||||||
? `https://github.com/users/${userName}/contributions?` +
|
contributionsCollection {
|
||||||
formatParams(options)
|
contributionCalendar {
|
||||||
: `https://github.com/${userName}`;
|
weeks {
|
||||||
const res = await lib_default()(url);
|
contributionDays {
|
||||||
|
contributionCount
|
||||||
|
contributionLevel
|
||||||
|
weekday
|
||||||
|
date
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const variables = { login: userName };
|
||||||
|
const res = await lib_default()("https://api.github.com/graphql", {
|
||||||
|
headers: {
|
||||||
|
Authorization: `bearer ${o.githubToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ variables, query }),
|
||||||
|
});
|
||||||
if (!res.ok)
|
if (!res.ok)
|
||||||
throw new Error(res.statusText);
|
throw new Error(res.statusText);
|
||||||
const resText = await res.text();
|
const { data, errors } = (await res.json());
|
||||||
return parseUserPage(resText);
|
if (errors?.[0])
|
||||||
};
|
throw errors[0];
|
||||||
const parseUserPage = (content) => {
|
return data.user.contributionsCollection.contributionCalendar.weeks.flatMap(({ contributionDays }, x) => contributionDays.map((d) => ({
|
||||||
// take roughly the table block
|
x,
|
||||||
const block = content
|
y: d.weekday,
|
||||||
.split(`aria-describedby="contribution-graph-description"`)[1]
|
date: d.date,
|
||||||
.split("<tbody>")[1]
|
count: d.contributionCount,
|
||||||
.split("</tbody>")[0];
|
level: (d.contributionLevel === "FOURTH_QUARTILE" && 4) ||
|
||||||
const cells = block.split("</tr>").flatMap((inside, y) => inside.split("</td>").flatMap((m) => {
|
(d.contributionLevel === "THIRD_QUARTILE" && 3) ||
|
||||||
const date = m.match(/data-date="([^"]+)"/)?.[1];
|
(d.contributionLevel === "SECOND_QUARTILE" && 2) ||
|
||||||
const literalLevel = m.match(/data-level="([^"]+)"/)?.[1];
|
(d.contributionLevel === "FIRST_QUARTILE" && 1) ||
|
||||||
const literalX = m.match(/data-ix="([^"]+)"/)?.[1];
|
0,
|
||||||
const literalCount = m.match(/(No|\d+) contributions? on/)?.[1];
|
})));
|
||||||
if (date && literalLevel && literalX && literalCount)
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
x: +literalX,
|
|
||||||
y,
|
|
||||||
date,
|
|
||||||
count: +literalCount,
|
|
||||||
level: +literalLevel,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
return [];
|
|
||||||
}));
|
|
||||||
return cells;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// EXTERNAL MODULE: ../types/grid.ts
|
// EXTERNAL MODULE: ../types/grid.ts
|
||||||
@@ -655,9 +633,9 @@ const getPathToPose = (snake0, target, grid) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const generateContributionSnake = async (userName, outputs) => {
|
const generateContributionSnake = async (userName, outputs, options) => {
|
||||||
console.log("🎣 fetching github user contribution");
|
console.log("🎣 fetching github user contribution");
|
||||||
const cells = await getGithubUserContribution(userName);
|
const cells = await getGithubUserContribution(userName, options);
|
||||||
const grid = userContributionToGrid(cells);
|
const grid = userContributionToGrid(cells);
|
||||||
const snake = snake4;
|
const snake = snake4;
|
||||||
console.log("📡 computing best route");
|
console.log("📡 computing best route");
|
||||||
7
svg-only/dist/index.js
vendored
7
svg-only/dist/index.js
vendored
@@ -3098,8 +3098,11 @@ const parseEntry = (entry) => {
|
|||||||
core.getInput("gif_out_path"),
|
core.getInput("gif_out_path"),
|
||||||
core.getInput("svg_out_path"),
|
core.getInput("svg_out_path"),
|
||||||
]);
|
]);
|
||||||
const { generateContributionSnake } = await Promise.all(/* import() */[__nccwpck_require__.e(197), __nccwpck_require__.e(317)]).then(__nccwpck_require__.bind(__nccwpck_require__, 5317));
|
const githubToken = process.env.GITHUB_TOKEN;
|
||||||
const results = await generateContributionSnake(userName, outputs);
|
const { generateContributionSnake } = await Promise.all(/* import() */[__nccwpck_require__.e(197), __nccwpck_require__.e(407)]).then(__nccwpck_require__.bind(__nccwpck_require__, 407));
|
||||||
|
const results = await generateContributionSnake(userName, outputs, {
|
||||||
|
githubToken,
|
||||||
|
});
|
||||||
outputs.forEach((out, i) => {
|
outputs.forEach((out, i) => {
|
||||||
const result = results[i];
|
const result = results[i];
|
||||||
if (out?.filename && result) {
|
if (out?.filename && result) {
|
||||||
|
|||||||
Reference in New Issue
Block a user