From aebc3a92857730857d5a96010a3538f16bbec662 Mon Sep 17 00:00:00 2001 From: release bot Date: Mon, 17 Jul 2023 20:57:38 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=203.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 2 +- package.json | 2 +- svg-only/dist/{317.index.js => 407.index.js} | 116 ++++++++----------- svg-only/dist/index.js | 7 +- 4 files changed, 54 insertions(+), 73 deletions(-) rename svg-only/dist/{317.index.js => 407.index.js} (91%) diff --git a/action.yml b/action.yml index dc032b7..b1e81b4 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ author: "platane" runs: using: docker - image: docker://platane/snk@sha256:2115ffeb538e355aa155630e6e32b6d77ea2345fa8584645c41ace7f5ad667fc + image: docker://platane/snk@sha256:753878055e52fbbaf3148fdac4590e396f97581f1dc4c1f861701add7a1dc1b5 inputs: github_user_name: diff --git a/package.json b/package.json index 649c9e6..58794f4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "snk", "description": "Generates a snake game from a github user contributions grid", - "version": "2.3.0", + "version": "3.0.0", "private": true, "repository": "github:platane/snk", "devDependencies": { diff --git a/svg-only/dist/317.index.js b/svg-only/dist/407.index.js similarity index 91% rename from svg-only/dist/317.index.js rename to svg-only/dist/407.index.js index a095f5e..5918726 100644 --- a/svg-only/dist/317.index.js +++ b/svg-only/dist/407.index.js @@ -1,9 +1,9 @@ "use strict"; -exports.id = 317; -exports.ids = [317]; +exports.id = 407; +exports.ids = [407]; exports.modules = { -/***/ 5317: +/***/ 407: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { // ESM COMPAT FLAG @@ -17,37 +17,8 @@ __webpack_require__.d(__webpack_exports__, { // EXTERNAL MODULE: ../../node_modules/node-fetch/lib/index.js var lib = __webpack_require__(2197); 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 - /** * get the contribution grid from a github user page * @@ -64,43 +35,50 @@ const formatDate = (d) => { * getGithubUserContribution("platane", { year: 2019 }) * */ -const getGithubUserContribution = async (userName, options = {}) => { - // either use github.com/users/xxxx/contributions for previous years - // or github.com/xxxx ( which gives the latest update to today result ) - const url = "year" in options || "from" in options || "to" in options - ? `https://github.com/users/${userName}/contributions?` + - formatParams(options) - : `https://github.com/${userName}`; - const res = await lib_default()(url); +const getGithubUserContribution = async (userName, o) => { + const query = /* GraphQL */ ` + query ($login: String!) { + user(login: $login) { + contributionsCollection { + contributionCalendar { + weeks { + 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) throw new Error(res.statusText); - const resText = await res.text(); - return parseUserPage(resText); -}; -const parseUserPage = (content) => { - // take roughly the table block - const block = content - .split(`aria-describedby="contribution-graph-description"`)[1] - .split("")[1] - .split("")[0]; - const cells = block.split("").flatMap((inside, y) => inside.split("").flatMap((m) => { - const date = m.match(/data-date="([^"]+)"/)?.[1]; - const literalLevel = m.match(/data-level="([^"]+)"/)?.[1]; - const literalX = m.match(/data-ix="([^"]+)"/)?.[1]; - 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; + const { data, errors } = (await res.json()); + if (errors?.[0]) + throw errors[0]; + return data.user.contributionsCollection.contributionCalendar.weeks.flatMap(({ contributionDays }, x) => contributionDays.map((d) => ({ + x, + y: d.weekday, + date: d.date, + count: d.contributionCount, + level: (d.contributionLevel === "FOURTH_QUARTILE" && 4) || + (d.contributionLevel === "THIRD_QUARTILE" && 3) || + (d.contributionLevel === "SECOND_QUARTILE" && 2) || + (d.contributionLevel === "FIRST_QUARTILE" && 1) || + 0, + }))); }; // 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"); - const cells = await getGithubUserContribution(userName); + const cells = await getGithubUserContribution(userName, options); const grid = userContributionToGrid(cells); const snake = snake4; console.log("📡 computing best route"); diff --git a/svg-only/dist/index.js b/svg-only/dist/index.js index 6dae8b5..25d40f7 100644 --- a/svg-only/dist/index.js +++ b/svg-only/dist/index.js @@ -3098,8 +3098,11 @@ const parseEntry = (entry) => { core.getInput("gif_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 results = await generateContributionSnake(userName, outputs); + const githubToken = process.env.GITHUB_TOKEN; + 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) => { const result = results[i]; if (out?.filename && result) {