From ebeb59fcedcfb1c5d8ca74a0778da5e410796adb Mon Sep 17 00:00:00 2001 From: platane Date: Mon, 17 Jul 2023 19:59:59 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20read=20contribution=20calendar=20fr?= =?UTF-8?q?om=20github=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 6 + .gitignore | 3 +- .../generateContributionSnake.spec.ts | 6 +- packages/action/generateContributionSnake.ts | 5 +- packages/action/index.ts | 5 +- packages/action/package.json | 3 +- packages/demo/webpack.config.ts | 13 +- .../github-user-contribution/[userName].ts | 6 +- .../getGithubUserContribution.spec.ts.snap | 2561 ----------------- .../__tests__/formatParams.spec.ts | 19 - .../getGithubUserContribution.spec.ts | 17 +- .../github-user-contribution/formatParams.ts | 38 - packages/github-user-contribution/index.ts | 113 +- .../github-user-contribution/package.json | 3 +- yarn.lock | 21 +- 15 files changed, 130 insertions(+), 2689 deletions(-) delete mode 100644 packages/github-user-contribution/__tests__/__snapshots__/getGithubUserContribution.spec.ts.snap delete mode 100644 packages/github-user-contribution/__tests__/formatParams.spec.ts delete mode 100644 packages/github-user-contribution/formatParams.ts diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f52a150..6a14901 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,6 +17,8 @@ jobs: - run: npm run type - run: npm run lint - run: npm run test --ci + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} test-action: runs-on: ubuntu-latest @@ -36,6 +38,8 @@ jobs: dist/github-contribution-grid-snake.svg dist/github-contribution-grid-snake-dark.svg?palette=github-dark dist/github-contribution-grid-snake.gif?color_snake=orange&color_dots=#bfd6f6,#8dbdff,#64a1f4,#4b91f1,#3c7dd9 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: ensure the generated file exists run: | @@ -75,6 +79,8 @@ jobs: outputs: | dist/github-contribution-grid-snake.svg dist/github-contribution-grid-snake-dark.svg?palette=github-dark + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: ensure the generated file exists run: | diff --git a/.gitignore b/.gitignore index fe53d86..1f93e41 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ npm-debug.log* yarn-error.log* dist !svg-only/dist -build \ No newline at end of file +build +.env \ No newline at end of file diff --git a/packages/action/__tests__/generateContributionSnake.spec.ts b/packages/action/__tests__/generateContributionSnake.spec.ts index 5c56d54..630afe3 100644 --- a/packages/action/__tests__/generateContributionSnake.spec.ts +++ b/packages/action/__tests__/generateContributionSnake.spec.ts @@ -2,6 +2,8 @@ import * as fs from "fs"; import * as path from "path"; import { generateContributionSnake } from "../generateContributionSnake"; import { parseOutputsOption } from "../outputsOptions"; +import { config } from "dotenv"; +config({ path: __dirname + "/../../../.env" }); jest.setTimeout(2 * 60 * 1000); @@ -30,7 +32,9 @@ it( const outputs = parseOutputsOption(entries); - const results = await generateContributionSnake("platane", outputs); + const results = await generateContributionSnake("platane", outputs, { + githubToken: process.env.GITHUB_TOKEN!, + }); expect(results[0]).toBeDefined(); expect(results[1]).toBeDefined(); diff --git a/packages/action/generateContributionSnake.ts b/packages/action/generateContributionSnake.ts index ef0dd94..8f9df30 100644 --- a/packages/action/generateContributionSnake.ts +++ b/packages/action/generateContributionSnake.ts @@ -12,10 +12,11 @@ export const generateContributionSnake = async ( format: "svg" | "gif"; drawOptions: DrawOptions; animationOptions: AnimationOptions; - } | null)[] + } | null)[], + options: { githubToken: string } ) => { console.log("🎣 fetching github user contribution"); - const cells = await getGithubUserContribution(userName); + const cells = await getGithubUserContribution(userName, options); const grid = userContributionToGrid(cells); const snake = snake4; diff --git a/packages/action/index.ts b/packages/action/index.ts index e889887..5830446 100644 --- a/packages/action/index.ts +++ b/packages/action/index.ts @@ -12,11 +12,14 @@ import { parseOutputsOption } from "./outputsOptions"; core.getInput("svg_out_path"), ] ); + const githubToken = process.env.GITHUB_TOKEN!; const { generateContributionSnake } = await import( "./generateContributionSnake" ); - const results = await generateContributionSnake(userName, outputs); + const results = await generateContributionSnake(userName, outputs, { + githubToken, + }); outputs.forEach((out, i) => { const result = results[i]; diff --git a/packages/action/package.json b/packages/action/package.json index 922d3f0..a177213 100644 --- a/packages/action/package.json +++ b/packages/action/package.json @@ -10,7 +10,8 @@ "@snk/types": "1.0.0" }, "devDependencies": { - "@vercel/ncc": "0.36.1" + "@vercel/ncc": "0.36.1", + "dotenv": "16.3.1" }, "scripts": { "build": "ncc build --external canvas --external gifsicle --out dist ./index.ts", diff --git a/packages/demo/webpack.config.ts b/packages/demo/webpack.config.ts index e9177c3..4a20e8e 100644 --- a/packages/demo/webpack.config.ts +++ b/packages/demo/webpack.config.ts @@ -1,10 +1,11 @@ import path from "path"; import HtmlWebpackPlugin from "html-webpack-plugin"; - -import type { Configuration as WebpackConfiguration } from "webpack"; -import type { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server"; import webpack from "webpack"; import { getGithubUserContribution } from "@snk/github-user-contribution"; +import { config } from "dotenv"; +import type { Configuration as WebpackConfiguration } from "webpack"; +import type { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server"; +config({ path: __dirname + "/../../.env" }); const demos: string[] = require("./demo.json"); @@ -13,7 +14,11 @@ const webpackDevServerConfiguration: WebpackDevServerConfiguration = { onAfterSetupMiddleware: ({ app }) => { app!.get("/api/github-user-contribution/:userName", async (req, res) => { const userName: string = req.params.userName; - res.send(await getGithubUserContribution(userName)); + res.send( + await getGithubUserContribution(userName, { + githubToken: process.env.GITHUB_TOKEN!, + }) + ); }); }, }; diff --git a/packages/github-user-contribution-service/api/github-user-contribution/[userName].ts b/packages/github-user-contribution-service/api/github-user-contribution/[userName].ts index a0f3a4d..c18dc9b 100644 --- a/packages/github-user-contribution-service/api/github-user-contribution/[userName].ts +++ b/packages/github-user-contribution-service/api/github-user-contribution/[userName].ts @@ -7,7 +7,11 @@ export default async (req: VercelRequest, res: VercelResponse) => { try { res.setHeader("Access-Control-Allow-Origin", "https://platane.github.io"); res.statusCode = 200; - res.json(await getGithubUserContribution(userName as string)); + res.json( + await getGithubUserContribution(userName as string, { + githubToken: process.env.GITHUB!, + }) + ); } catch (err) { console.error(err); res.statusCode = 500; diff --git a/packages/github-user-contribution/__tests__/__snapshots__/getGithubUserContribution.spec.ts.snap b/packages/github-user-contribution/__tests__/__snapshots__/getGithubUserContribution.spec.ts.snap deleted file mode 100644 index 35ed782..0000000 --- a/packages/github-user-contribution/__tests__/__snapshots__/getGithubUserContribution.spec.ts.snap +++ /dev/null @@ -1,2561 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should match snapshot for year=2019 1`] = ` -[ - { - "count": 0, - "date": "2019-01-01", - "level": 0, - "x": 0, - "y": 2, - }, - { - "count": 0, - "date": "2019-01-02", - "level": 0, - "x": 0, - "y": 3, - }, - { - "count": 0, - "date": "2019-01-03", - "level": 0, - "x": 0, - "y": 4, - }, - { - "count": 0, - "date": "2019-01-04", - "level": 0, - "x": 0, - "y": 5, - }, - { - "count": 0, - "date": "2019-01-05", - "level": 0, - "x": 0, - "y": 6, - }, - { - "count": 0, - "date": "2019-01-06", - "level": 0, - "x": 1, - "y": 0, - }, - { - "count": 0, - "date": "2019-01-07", - "level": 0, - "x": 1, - "y": 1, - }, - { - "count": 0, - "date": "2019-01-08", - "level": 0, - "x": 1, - "y": 2, - }, - { - "count": 3, - "date": "2019-01-09", - "level": 1, - "x": 1, - "y": 3, - }, - { - "count": 2, - "date": "2019-01-10", - "level": 1, - "x": 1, - "y": 4, - }, - { - "count": 0, - "date": "2019-01-11", - "level": 0, - "x": 1, - "y": 5, - }, - { - "count": 0, - "date": "2019-01-12", - "level": 0, - "x": 1, - "y": 6, - }, - { - "count": 0, - "date": "2019-01-13", - "level": 0, - "x": 2, - "y": 0, - }, - { - "count": 0, - "date": "2019-01-14", - "level": 0, - "x": 2, - "y": 1, - }, - { - "count": 0, - "date": "2019-01-15", - "level": 0, - "x": 2, - "y": 2, - }, - { - "count": 5, - "date": "2019-01-16", - "level": 1, - "x": 2, - "y": 3, - }, - { - "count": 0, - "date": "2019-01-17", - "level": 0, - "x": 2, - "y": 4, - }, - { - "count": 0, - "date": "2019-01-18", - "level": 0, - "x": 2, - "y": 5, - }, - { - "count": 0, - "date": "2019-01-19", - "level": 0, - "x": 2, - "y": 6, - }, - { - "count": 0, - "date": "2019-01-20", - "level": 0, - "x": 3, - "y": 0, - }, - { - "count": 0, - "date": "2019-01-21", - "level": 0, - "x": 3, - "y": 1, - }, - { - "count": 0, - "date": "2019-01-22", - "level": 0, - "x": 3, - "y": 2, - }, - { - "count": 0, - "date": "2019-01-23", - "level": 0, - "x": 3, - "y": 3, - }, - { - "count": 0, - "date": "2019-01-24", - "level": 0, - "x": 3, - "y": 4, - }, - { - "count": 0, - "date": "2019-01-25", - "level": 0, - "x": 3, - "y": 5, - }, - { - "count": 0, - "date": "2019-01-26", - "level": 0, - "x": 3, - "y": 6, - }, - { - "count": 0, - "date": "2019-01-27", - "level": 0, - "x": 4, - "y": 0, - }, - { - "count": 0, - "date": "2019-01-28", - "level": 0, - "x": 4, - "y": 1, - }, - { - "count": 0, - "date": "2019-01-29", - "level": 0, - "x": 4, - "y": 2, - }, - { - "count": 0, - "date": "2019-01-30", - "level": 0, - "x": 4, - "y": 3, - }, - { - "count": 0, - "date": "2019-01-31", - "level": 0, - "x": 4, - "y": 4, - }, - { - "count": 0, - "date": "2019-02-01", - "level": 0, - "x": 4, - "y": 5, - }, - { - "count": 0, - "date": "2019-02-02", - "level": 0, - "x": 4, - "y": 6, - }, - { - "count": 0, - "date": "2019-02-03", - "level": 0, - "x": 5, - "y": 0, - }, - { - "count": 0, - "date": "2019-02-04", - "level": 0, - "x": 5, - "y": 1, - }, - { - "count": 0, - "date": "2019-02-05", - "level": 0, - "x": 5, - "y": 2, - }, - { - "count": 0, - "date": "2019-02-06", - "level": 0, - "x": 5, - "y": 3, - }, - { - "count": 0, - "date": "2019-02-07", - "level": 0, - "x": 5, - "y": 4, - }, - { - "count": 0, - "date": "2019-02-08", - "level": 0, - "x": 5, - "y": 5, - }, - { - "count": 0, - "date": "2019-02-09", - "level": 0, - "x": 5, - "y": 6, - }, - { - "count": 0, - "date": "2019-02-10", - "level": 0, - "x": 6, - "y": 0, - }, - { - "count": 0, - "date": "2019-02-11", - "level": 0, - "x": 6, - "y": 1, - }, - { - "count": 0, - "date": "2019-02-12", - "level": 0, - "x": 6, - "y": 2, - }, - { - "count": 2, - "date": "2019-02-13", - "level": 1, - "x": 6, - "y": 3, - }, - { - "count": 0, - "date": "2019-02-14", - "level": 0, - "x": 6, - "y": 4, - }, - { - "count": 0, - "date": "2019-02-15", - "level": 0, - "x": 6, - "y": 5, - }, - { - "count": 4, - "date": "2019-02-16", - "level": 1, - "x": 6, - "y": 6, - }, - { - "count": 9, - "date": "2019-02-17", - "level": 2, - "x": 7, - "y": 0, - }, - { - "count": 0, - "date": "2019-02-18", - "level": 0, - "x": 7, - "y": 1, - }, - { - "count": 0, - "date": "2019-02-19", - "level": 0, - "x": 7, - "y": 2, - }, - { - "count": 0, - "date": "2019-02-20", - "level": 0, - "x": 7, - "y": 3, - }, - { - "count": 0, - "date": "2019-02-21", - "level": 0, - "x": 7, - "y": 4, - }, - { - "count": 0, - "date": "2019-02-22", - "level": 0, - "x": 7, - "y": 5, - }, - { - "count": 0, - "date": "2019-02-23", - "level": 0, - "x": 7, - "y": 6, - }, - { - "count": 0, - "date": "2019-02-24", - "level": 0, - "x": 8, - "y": 0, - }, - { - "count": 0, - "date": "2019-02-25", - "level": 0, - "x": 8, - "y": 1, - }, - { - "count": 0, - "date": "2019-02-26", - "level": 0, - "x": 8, - "y": 2, - }, - { - "count": 0, - "date": "2019-02-27", - "level": 0, - "x": 8, - "y": 3, - }, - { - "count": 0, - "date": "2019-02-28", - "level": 0, - "x": 8, - "y": 4, - }, - { - "count": 0, - "date": "2019-03-01", - "level": 0, - "x": 8, - "y": 5, - }, - { - "count": 0, - "date": "2019-03-02", - "level": 0, - "x": 8, - "y": 6, - }, - { - "count": 0, - "date": "2019-03-03", - "level": 0, - "x": 9, - "y": 0, - }, - { - "count": 0, - "date": "2019-03-04", - "level": 0, - "x": 9, - "y": 1, - }, - { - "count": 0, - "date": "2019-03-05", - "level": 0, - "x": 9, - "y": 2, - }, - { - "count": 0, - "date": "2019-03-06", - "level": 0, - "x": 9, - "y": 3, - }, - { - "count": 0, - "date": "2019-03-07", - "level": 0, - "x": 9, - "y": 4, - }, - { - "count": 1, - "date": "2019-03-08", - "level": 1, - "x": 9, - "y": 5, - }, - { - "count": 0, - "date": "2019-03-09", - "level": 0, - "x": 9, - "y": 6, - }, - { - "count": 0, - "date": "2019-03-10", - "level": 0, - "x": 10, - "y": 0, - }, - { - "count": 0, - "date": "2019-03-11", - "level": 0, - "x": 10, - "y": 1, - }, - { - "count": 0, - "date": "2019-03-12", - "level": 0, - "x": 10, - "y": 2, - }, - { - "count": 0, - "date": "2019-03-13", - "level": 0, - "x": 10, - "y": 3, - }, - { - "count": 0, - "date": "2019-03-14", - "level": 0, - "x": 10, - "y": 4, - }, - { - "count": 0, - "date": "2019-03-15", - "level": 0, - "x": 10, - "y": 5, - }, - { - "count": 0, - "date": "2019-03-16", - "level": 0, - "x": 10, - "y": 6, - }, - { - "count": 0, - "date": "2019-03-17", - "level": 0, - "x": 11, - "y": 0, - }, - { - "count": 0, - "date": "2019-03-18", - "level": 0, - "x": 11, - "y": 1, - }, - { - "count": 0, - "date": "2019-03-19", - "level": 0, - "x": 11, - "y": 2, - }, - { - "count": 0, - "date": "2019-03-20", - "level": 0, - "x": 11, - "y": 3, - }, - { - "count": 0, - "date": "2019-03-21", - "level": 0, - "x": 11, - "y": 4, - }, - { - "count": 0, - "date": "2019-03-22", - "level": 0, - "x": 11, - "y": 5, - }, - { - "count": 0, - "date": "2019-03-23", - "level": 0, - "x": 11, - "y": 6, - }, - { - "count": 7, - "date": "2019-03-24", - "level": 2, - "x": 12, - "y": 0, - }, - { - "count": 0, - "date": "2019-03-25", - "level": 0, - "x": 12, - "y": 1, - }, - { - "count": 0, - "date": "2019-03-26", - "level": 0, - "x": 12, - "y": 2, - }, - { - "count": 0, - "date": "2019-03-27", - "level": 0, - "x": 12, - "y": 3, - }, - { - "count": 0, - "date": "2019-03-28", - "level": 0, - "x": 12, - "y": 4, - }, - { - "count": 0, - "date": "2019-03-29", - "level": 0, - "x": 12, - "y": 5, - }, - { - "count": 0, - "date": "2019-03-30", - "level": 0, - "x": 12, - "y": 6, - }, - { - "count": 0, - "date": "2019-03-31", - "level": 0, - "x": 13, - "y": 0, - }, - { - "count": 0, - "date": "2019-04-01", - "level": 0, - "x": 13, - "y": 1, - }, - { - "count": 0, - "date": "2019-04-02", - "level": 0, - "x": 13, - "y": 2, - }, - { - "count": 0, - "date": "2019-04-03", - "level": 0, - "x": 13, - "y": 3, - }, - { - "count": 0, - "date": "2019-04-04", - "level": 0, - "x": 13, - "y": 4, - }, - { - "count": 0, - "date": "2019-04-05", - "level": 0, - "x": 13, - "y": 5, - }, - { - "count": 0, - "date": "2019-04-06", - "level": 0, - "x": 13, - "y": 6, - }, - { - "count": 0, - "date": "2019-04-07", - "level": 0, - "x": 14, - "y": 0, - }, - { - "count": 0, - "date": "2019-04-08", - "level": 0, - "x": 14, - "y": 1, - }, - { - "count": 0, - "date": "2019-04-09", - "level": 0, - "x": 14, - "y": 2, - }, - { - "count": 0, - "date": "2019-04-10", - "level": 0, - "x": 14, - "y": 3, - }, - { - "count": 0, - "date": "2019-04-11", - "level": 0, - "x": 14, - "y": 4, - }, - { - "count": 0, - "date": "2019-04-12", - "level": 0, - "x": 14, - "y": 5, - }, - { - "count": 0, - "date": "2019-04-13", - "level": 0, - "x": 14, - "y": 6, - }, - { - "count": 0, - "date": "2019-04-14", - "level": 0, - "x": 15, - "y": 0, - }, - { - "count": 0, - "date": "2019-04-15", - "level": 0, - "x": 15, - "y": 1, - }, - { - "count": 0, - "date": "2019-04-16", - "level": 0, - "x": 15, - "y": 2, - }, - { - "count": 0, - "date": "2019-04-17", - "level": 0, - "x": 15, - "y": 3, - }, - { - "count": 0, - "date": "2019-04-18", - "level": 0, - "x": 15, - "y": 4, - }, - { - "count": 0, - "date": "2019-04-19", - "level": 0, - "x": 15, - "y": 5, - }, - { - "count": 0, - "date": "2019-04-20", - "level": 0, - "x": 15, - "y": 6, - }, - { - "count": 0, - "date": "2019-04-21", - "level": 0, - "x": 16, - "y": 0, - }, - { - "count": 0, - "date": "2019-04-22", - "level": 0, - "x": 16, - "y": 1, - }, - { - "count": 0, - "date": "2019-04-23", - "level": 0, - "x": 16, - "y": 2, - }, - { - "count": 1, - "date": "2019-04-24", - "level": 1, - "x": 16, - "y": 3, - }, - { - "count": 1, - "date": "2019-04-25", - "level": 1, - "x": 16, - "y": 4, - }, - { - "count": 0, - "date": "2019-04-26", - "level": 0, - "x": 16, - "y": 5, - }, - { - "count": 0, - "date": "2019-04-27", - "level": 0, - "x": 16, - "y": 6, - }, - { - "count": 0, - "date": "2019-04-28", - "level": 0, - "x": 17, - "y": 0, - }, - { - "count": 1, - "date": "2019-04-29", - "level": 1, - "x": 17, - "y": 1, - }, - { - "count": 0, - "date": "2019-04-30", - "level": 0, - "x": 17, - "y": 2, - }, - { - "count": 0, - "date": "2019-05-01", - "level": 0, - "x": 17, - "y": 3, - }, - { - "count": 0, - "date": "2019-05-02", - "level": 0, - "x": 17, - "y": 4, - }, - { - "count": 1, - "date": "2019-05-03", - "level": 1, - "x": 17, - "y": 5, - }, - { - "count": 0, - "date": "2019-05-04", - "level": 0, - "x": 17, - "y": 6, - }, - { - "count": 1, - "date": "2019-05-05", - "level": 1, - "x": 18, - "y": 0, - }, - { - "count": 0, - "date": "2019-05-06", - "level": 0, - "x": 18, - "y": 1, - }, - { - "count": 0, - "date": "2019-05-07", - "level": 0, - "x": 18, - "y": 2, - }, - { - "count": 0, - "date": "2019-05-08", - "level": 0, - "x": 18, - "y": 3, - }, - { - "count": 0, - "date": "2019-05-09", - "level": 0, - "x": 18, - "y": 4, - }, - { - "count": 0, - "date": "2019-05-10", - "level": 0, - "x": 18, - "y": 5, - }, - { - "count": 0, - "date": "2019-05-11", - "level": 0, - "x": 18, - "y": 6, - }, - { - "count": 5, - "date": "2019-05-12", - "level": 1, - "x": 19, - "y": 0, - }, - { - "count": 0, - "date": "2019-05-13", - "level": 0, - "x": 19, - "y": 1, - }, - { - "count": 0, - "date": "2019-05-14", - "level": 0, - "x": 19, - "y": 2, - }, - { - "count": 0, - "date": "2019-05-15", - "level": 0, - "x": 19, - "y": 3, - }, - { - "count": 1, - "date": "2019-05-16", - "level": 1, - "x": 19, - "y": 4, - }, - { - "count": 1, - "date": "2019-05-17", - "level": 1, - "x": 19, - "y": 5, - }, - { - "count": 3, - "date": "2019-05-18", - "level": 1, - "x": 19, - "y": 6, - }, - { - "count": 0, - "date": "2019-05-19", - "level": 0, - "x": 20, - "y": 0, - }, - { - "count": 0, - "date": "2019-05-20", - "level": 0, - "x": 20, - "y": 1, - }, - { - "count": 2, - "date": "2019-05-21", - "level": 1, - "x": 20, - "y": 2, - }, - { - "count": 0, - "date": "2019-05-22", - "level": 0, - "x": 20, - "y": 3, - }, - { - "count": 0, - "date": "2019-05-23", - "level": 0, - "x": 20, - "y": 4, - }, - { - "count": 1, - "date": "2019-05-24", - "level": 1, - "x": 20, - "y": 5, - }, - { - "count": 0, - "date": "2019-05-25", - "level": 0, - "x": 20, - "y": 6, - }, - { - "count": 0, - "date": "2019-05-26", - "level": 0, - "x": 21, - "y": 0, - }, - { - "count": 0, - "date": "2019-05-27", - "level": 0, - "x": 21, - "y": 1, - }, - { - "count": 0, - "date": "2019-05-28", - "level": 0, - "x": 21, - "y": 2, - }, - { - "count": 0, - "date": "2019-05-29", - "level": 0, - "x": 21, - "y": 3, - }, - { - "count": 0, - "date": "2019-05-30", - "level": 0, - "x": 21, - "y": 4, - }, - { - "count": 1, - "date": "2019-05-31", - "level": 1, - "x": 21, - "y": 5, - }, - { - "count": 0, - "date": "2019-06-01", - "level": 0, - "x": 21, - "y": 6, - }, - { - "count": 0, - "date": "2019-06-02", - "level": 0, - "x": 22, - "y": 0, - }, - { - "count": 0, - "date": "2019-06-03", - "level": 0, - "x": 22, - "y": 1, - }, - { - "count": 0, - "date": "2019-06-04", - "level": 0, - "x": 22, - "y": 2, - }, - { - "count": 0, - "date": "2019-06-05", - "level": 0, - "x": 22, - "y": 3, - }, - { - "count": 0, - "date": "2019-06-06", - "level": 0, - "x": 22, - "y": 4, - }, - { - "count": 0, - "date": "2019-06-07", - "level": 0, - "x": 22, - "y": 5, - }, - { - "count": 0, - "date": "2019-06-08", - "level": 0, - "x": 22, - "y": 6, - }, - { - "count": 0, - "date": "2019-06-09", - "level": 0, - "x": 23, - "y": 0, - }, - { - "count": 0, - "date": "2019-06-10", - "level": 0, - "x": 23, - "y": 1, - }, - { - "count": 0, - "date": "2019-06-11", - "level": 0, - "x": 23, - "y": 2, - }, - { - "count": 0, - "date": "2019-06-12", - "level": 0, - "x": 23, - "y": 3, - }, - { - "count": 1, - "date": "2019-06-13", - "level": 1, - "x": 23, - "y": 4, - }, - { - "count": 1, - "date": "2019-06-14", - "level": 1, - "x": 23, - "y": 5, - }, - { - "count": 0, - "date": "2019-06-15", - "level": 0, - "x": 23, - "y": 6, - }, - { - "count": 0, - "date": "2019-06-16", - "level": 0, - "x": 24, - "y": 0, - }, - { - "count": 0, - "date": "2019-06-17", - "level": 0, - "x": 24, - "y": 1, - }, - { - "count": 1, - "date": "2019-06-18", - "level": 1, - "x": 24, - "y": 2, - }, - { - "count": 0, - "date": "2019-06-19", - "level": 0, - "x": 24, - "y": 3, - }, - { - "count": 0, - "date": "2019-06-20", - "level": 0, - "x": 24, - "y": 4, - }, - { - "count": 0, - "date": "2019-06-21", - "level": 0, - "x": 24, - "y": 5, - }, - { - "count": 0, - "date": "2019-06-22", - "level": 0, - "x": 24, - "y": 6, - }, - { - "count": 6, - "date": "2019-06-23", - "level": 1, - "x": 25, - "y": 0, - }, - { - "count": 0, - "date": "2019-06-24", - "level": 0, - "x": 25, - "y": 1, - }, - { - "count": 0, - "date": "2019-06-25", - "level": 0, - "x": 25, - "y": 2, - }, - { - "count": 0, - "date": "2019-06-26", - "level": 0, - "x": 25, - "y": 3, - }, - { - "count": 0, - "date": "2019-06-27", - "level": 0, - "x": 25, - "y": 4, - }, - { - "count": 0, - "date": "2019-06-28", - "level": 0, - "x": 25, - "y": 5, - }, - { - "count": 1, - "date": "2019-06-29", - "level": 1, - "x": 25, - "y": 6, - }, - { - "count": 1, - "date": "2019-06-30", - "level": 1, - "x": 26, - "y": 0, - }, - { - "count": 0, - "date": "2019-07-01", - "level": 0, - "x": 26, - "y": 1, - }, - { - "count": 6, - "date": "2019-07-02", - "level": 1, - "x": 26, - "y": 2, - }, - { - "count": 3, - "date": "2019-07-03", - "level": 1, - "x": 26, - "y": 3, - }, - { - "count": 0, - "date": "2019-07-04", - "level": 0, - "x": 26, - "y": 4, - }, - { - "count": 0, - "date": "2019-07-05", - "level": 0, - "x": 26, - "y": 5, - }, - { - "count": 0, - "date": "2019-07-06", - "level": 0, - "x": 26, - "y": 6, - }, - { - "count": 0, - "date": "2019-07-07", - "level": 0, - "x": 27, - "y": 0, - }, - { - "count": 0, - "date": "2019-07-08", - "level": 0, - "x": 27, - "y": 1, - }, - { - "count": 0, - "date": "2019-07-09", - "level": 0, - "x": 27, - "y": 2, - }, - { - "count": 0, - "date": "2019-07-10", - "level": 0, - "x": 27, - "y": 3, - }, - { - "count": 3, - "date": "2019-07-11", - "level": 1, - "x": 27, - "y": 4, - }, - { - "count": 0, - "date": "2019-07-12", - "level": 0, - "x": 27, - "y": 5, - }, - { - "count": 0, - "date": "2019-07-13", - "level": 0, - "x": 27, - "y": 6, - }, - { - "count": 0, - "date": "2019-07-14", - "level": 0, - "x": 28, - "y": 0, - }, - { - "count": 0, - "date": "2019-07-15", - "level": 0, - "x": 28, - "y": 1, - }, - { - "count": 0, - "date": "2019-07-16", - "level": 0, - "x": 28, - "y": 2, - }, - { - "count": 7, - "date": "2019-07-17", - "level": 2, - "x": 28, - "y": 3, - }, - { - "count": 8, - "date": "2019-07-18", - "level": 2, - "x": 28, - "y": 4, - }, - { - "count": 15, - "date": "2019-07-19", - "level": 3, - "x": 28, - "y": 5, - }, - { - "count": 0, - "date": "2019-07-20", - "level": 0, - "x": 28, - "y": 6, - }, - { - "count": 0, - "date": "2019-07-21", - "level": 0, - "x": 29, - "y": 0, - }, - { - "count": 0, - "date": "2019-07-22", - "level": 0, - "x": 29, - "y": 1, - }, - { - "count": 23, - "date": "2019-07-23", - "level": 4, - "x": 29, - "y": 2, - }, - { - "count": 65, - "date": "2019-07-24", - "level": 4, - "x": 29, - "y": 3, - }, - { - "count": 16, - "date": "2019-07-25", - "level": 3, - "x": 29, - "y": 4, - }, - { - "count": 7, - "date": "2019-07-26", - "level": 2, - "x": 29, - "y": 5, - }, - { - "count": 0, - "date": "2019-07-27", - "level": 0, - "x": 29, - "y": 6, - }, - { - "count": 6, - "date": "2019-07-28", - "level": 1, - "x": 30, - "y": 0, - }, - { - "count": 4, - "date": "2019-07-29", - "level": 1, - "x": 30, - "y": 1, - }, - { - "count": 10, - "date": "2019-07-30", - "level": 2, - "x": 30, - "y": 2, - }, - { - "count": 0, - "date": "2019-07-31", - "level": 0, - "x": 30, - "y": 3, - }, - { - "count": 2, - "date": "2019-08-01", - "level": 1, - "x": 30, - "y": 4, - }, - { - "count": 5, - "date": "2019-08-02", - "level": 1, - "x": 30, - "y": 5, - }, - { - "count": 1, - "date": "2019-08-03", - "level": 1, - "x": 30, - "y": 6, - }, - { - "count": 0, - "date": "2019-08-04", - "level": 0, - "x": 31, - "y": 0, - }, - { - "count": 0, - "date": "2019-08-05", - "level": 0, - "x": 31, - "y": 1, - }, - { - "count": 0, - "date": "2019-08-06", - "level": 0, - "x": 31, - "y": 2, - }, - { - "count": 0, - "date": "2019-08-07", - "level": 0, - "x": 31, - "y": 3, - }, - { - "count": 0, - "date": "2019-08-08", - "level": 0, - "x": 31, - "y": 4, - }, - { - "count": 7, - "date": "2019-08-09", - "level": 2, - "x": 31, - "y": 5, - }, - { - "count": 0, - "date": "2019-08-10", - "level": 0, - "x": 31, - "y": 6, - }, - { - "count": 0, - "date": "2019-08-11", - "level": 0, - "x": 32, - "y": 0, - }, - { - "count": 10, - "date": "2019-08-12", - "level": 2, - "x": 32, - "y": 1, - }, - { - "count": 12, - "date": "2019-08-13", - "level": 2, - "x": 32, - "y": 2, - }, - { - "count": 10, - "date": "2019-08-14", - "level": 2, - "x": 32, - "y": 3, - }, - { - "count": 0, - "date": "2019-08-15", - "level": 0, - "x": 32, - "y": 4, - }, - { - "count": 3, - "date": "2019-08-16", - "level": 1, - "x": 32, - "y": 5, - }, - { - "count": 0, - "date": "2019-08-17", - "level": 0, - "x": 32, - "y": 6, - }, - { - "count": 2, - "date": "2019-08-18", - "level": 1, - "x": 33, - "y": 0, - }, - { - "count": 12, - "date": "2019-08-19", - "level": 2, - "x": 33, - "y": 1, - }, - { - "count": 22, - "date": "2019-08-20", - "level": 4, - "x": 33, - "y": 2, - }, - { - "count": 9, - "date": "2019-08-21", - "level": 2, - "x": 33, - "y": 3, - }, - { - "count": 16, - "date": "2019-08-22", - "level": 3, - "x": 33, - "y": 4, - }, - { - "count": 65, - "date": "2019-08-23", - "level": 4, - "x": 33, - "y": 5, - }, - { - "count": 3, - "date": "2019-08-24", - "level": 1, - "x": 33, - "y": 6, - }, - { - "count": 5, - "date": "2019-08-25", - "level": 1, - "x": 34, - "y": 0, - }, - { - "count": 10, - "date": "2019-08-26", - "level": 2, - "x": 34, - "y": 1, - }, - { - "count": 8, - "date": "2019-08-27", - "level": 2, - "x": 34, - "y": 2, - }, - { - "count": 6, - "date": "2019-08-28", - "level": 1, - "x": 34, - "y": 3, - }, - { - "count": 3, - "date": "2019-08-29", - "level": 1, - "x": 34, - "y": 4, - }, - { - "count": 0, - "date": "2019-08-30", - "level": 0, - "x": 34, - "y": 5, - }, - { - "count": 3, - "date": "2019-08-31", - "level": 1, - "x": 34, - "y": 6, - }, - { - "count": 0, - "date": "2019-09-01", - "level": 0, - "x": 35, - "y": 0, - }, - { - "count": 8, - "date": "2019-09-02", - "level": 2, - "x": 35, - "y": 1, - }, - { - "count": 7, - "date": "2019-09-03", - "level": 2, - "x": 35, - "y": 2, - }, - { - "count": 5, - "date": "2019-09-04", - "level": 1, - "x": 35, - "y": 3, - }, - { - "count": 24, - "date": "2019-09-05", - "level": 4, - "x": 35, - "y": 4, - }, - { - "count": 6, - "date": "2019-09-06", - "level": 1, - "x": 35, - "y": 5, - }, - { - "count": 0, - "date": "2019-09-07", - "level": 0, - "x": 35, - "y": 6, - }, - { - "count": 0, - "date": "2019-09-08", - "level": 0, - "x": 36, - "y": 0, - }, - { - "count": 0, - "date": "2019-09-09", - "level": 0, - "x": 36, - "y": 1, - }, - { - "count": 2, - "date": "2019-09-10", - "level": 1, - "x": 36, - "y": 2, - }, - { - "count": 0, - "date": "2019-09-11", - "level": 0, - "x": 36, - "y": 3, - }, - { - "count": 14, - "date": "2019-09-12", - "level": 3, - "x": 36, - "y": 4, - }, - { - "count": 2, - "date": "2019-09-13", - "level": 1, - "x": 36, - "y": 5, - }, - { - "count": 6, - "date": "2019-09-14", - "level": 1, - "x": 36, - "y": 6, - }, - { - "count": 0, - "date": "2019-09-15", - "level": 0, - "x": 37, - "y": 0, - }, - { - "count": 2, - "date": "2019-09-16", - "level": 1, - "x": 37, - "y": 1, - }, - { - "count": 9, - "date": "2019-09-17", - "level": 2, - "x": 37, - "y": 2, - }, - { - "count": 12, - "date": "2019-09-18", - "level": 2, - "x": 37, - "y": 3, - }, - { - "count": 7, - "date": "2019-09-19", - "level": 2, - "x": 37, - "y": 4, - }, - { - "count": 15, - "date": "2019-09-20", - "level": 3, - "x": 37, - "y": 5, - }, - { - "count": 0, - "date": "2019-09-21", - "level": 0, - "x": 37, - "y": 6, - }, - { - "count": 0, - "date": "2019-09-22", - "level": 0, - "x": 38, - "y": 0, - }, - { - "count": 3, - "date": "2019-09-23", - "level": 1, - "x": 38, - "y": 1, - }, - { - "count": 22, - "date": "2019-09-24", - "level": 4, - "x": 38, - "y": 2, - }, - { - "count": 9, - "date": "2019-09-25", - "level": 2, - "x": 38, - "y": 3, - }, - { - "count": 1, - "date": "2019-09-26", - "level": 1, - "x": 38, - "y": 4, - }, - { - "count": 0, - "date": "2019-09-27", - "level": 0, - "x": 38, - "y": 5, - }, - { - "count": 0, - "date": "2019-09-28", - "level": 0, - "x": 38, - "y": 6, - }, - { - "count": 0, - "date": "2019-09-29", - "level": 0, - "x": 39, - "y": 0, - }, - { - "count": 0, - "date": "2019-09-30", - "level": 0, - "x": 39, - "y": 1, - }, - { - "count": 0, - "date": "2019-10-01", - "level": 0, - "x": 39, - "y": 2, - }, - { - "count": 6, - "date": "2019-10-02", - "level": 1, - "x": 39, - "y": 3, - }, - { - "count": 8, - "date": "2019-10-03", - "level": 2, - "x": 39, - "y": 4, - }, - { - "count": 1, - "date": "2019-10-04", - "level": 1, - "x": 39, - "y": 5, - }, - { - "count": 0, - "date": "2019-10-05", - "level": 0, - "x": 39, - "y": 6, - }, - { - "count": 0, - "date": "2019-10-06", - "level": 0, - "x": 40, - "y": 0, - }, - { - "count": 5, - "date": "2019-10-07", - "level": 1, - "x": 40, - "y": 1, - }, - { - "count": 1, - "date": "2019-10-08", - "level": 1, - "x": 40, - "y": 2, - }, - { - "count": 4, - "date": "2019-10-09", - "level": 1, - "x": 40, - "y": 3, - }, - { - "count": 18, - "date": "2019-10-10", - "level": 3, - "x": 40, - "y": 4, - }, - { - "count": 13, - "date": "2019-10-11", - "level": 3, - "x": 40, - "y": 5, - }, - { - "count": 0, - "date": "2019-10-12", - "level": 0, - "x": 40, - "y": 6, - }, - { - "count": 0, - "date": "2019-10-13", - "level": 0, - "x": 41, - "y": 0, - }, - { - "count": 8, - "date": "2019-10-14", - "level": 2, - "x": 41, - "y": 1, - }, - { - "count": 7, - "date": "2019-10-15", - "level": 2, - "x": 41, - "y": 2, - }, - { - "count": 4, - "date": "2019-10-16", - "level": 1, - "x": 41, - "y": 3, - }, - { - "count": 2, - "date": "2019-10-17", - "level": 1, - "x": 41, - "y": 4, - }, - { - "count": 13, - "date": "2019-10-18", - "level": 3, - "x": 41, - "y": 5, - }, - { - "count": 5, - "date": "2019-10-19", - "level": 1, - "x": 41, - "y": 6, - }, - { - "count": 0, - "date": "2019-10-20", - "level": 0, - "x": 42, - "y": 0, - }, - { - "count": 7, - "date": "2019-10-21", - "level": 2, - "x": 42, - "y": 1, - }, - { - "count": 8, - "date": "2019-10-22", - "level": 2, - "x": 42, - "y": 2, - }, - { - "count": 11, - "date": "2019-10-23", - "level": 2, - "x": 42, - "y": 3, - }, - { - "count": 13, - "date": "2019-10-24", - "level": 3, - "x": 42, - "y": 4, - }, - { - "count": 6, - "date": "2019-10-25", - "level": 1, - "x": 42, - "y": 5, - }, - { - "count": 0, - "date": "2019-10-26", - "level": 0, - "x": 42, - "y": 6, - }, - { - "count": 0, - "date": "2019-10-27", - "level": 0, - "x": 43, - "y": 0, - }, - { - "count": 4, - "date": "2019-10-28", - "level": 1, - "x": 43, - "y": 1, - }, - { - "count": 1, - "date": "2019-10-29", - "level": 1, - "x": 43, - "y": 2, - }, - { - "count": 1, - "date": "2019-10-30", - "level": 1, - "x": 43, - "y": 3, - }, - { - "count": 3, - "date": "2019-10-31", - "level": 1, - "x": 43, - "y": 4, - }, - { - "count": 0, - "date": "2019-11-01", - "level": 0, - "x": 43, - "y": 5, - }, - { - "count": 2, - "date": "2019-11-02", - "level": 1, - "x": 43, - "y": 6, - }, - { - "count": 0, - "date": "2019-11-03", - "level": 0, - "x": 44, - "y": 0, - }, - { - "count": 8, - "date": "2019-11-04", - "level": 2, - "x": 44, - "y": 1, - }, - { - "count": 9, - "date": "2019-11-05", - "level": 2, - "x": 44, - "y": 2, - }, - { - "count": 24, - "date": "2019-11-06", - "level": 4, - "x": 44, - "y": 3, - }, - { - "count": 13, - "date": "2019-11-07", - "level": 3, - "x": 44, - "y": 4, - }, - { - "count": 0, - "date": "2019-11-08", - "level": 0, - "x": 44, - "y": 5, - }, - { - "count": 3, - "date": "2019-11-09", - "level": 1, - "x": 44, - "y": 6, - }, - { - "count": 0, - "date": "2019-11-10", - "level": 0, - "x": 45, - "y": 0, - }, - { - "count": 9, - "date": "2019-11-11", - "level": 2, - "x": 45, - "y": 1, - }, - { - "count": 9, - "date": "2019-11-12", - "level": 2, - "x": 45, - "y": 2, - }, - { - "count": 4, - "date": "2019-11-13", - "level": 1, - "x": 45, - "y": 3, - }, - { - "count": 0, - "date": "2019-11-14", - "level": 0, - "x": 45, - "y": 4, - }, - { - "count": 2, - "date": "2019-11-15", - "level": 1, - "x": 45, - "y": 5, - }, - { - "count": 0, - "date": "2019-11-16", - "level": 0, - "x": 45, - "y": 6, - }, - { - "count": 0, - "date": "2019-11-17", - "level": 0, - "x": 46, - "y": 0, - }, - { - "count": 8, - "date": "2019-11-18", - "level": 2, - "x": 46, - "y": 1, - }, - { - "count": 8, - "date": "2019-11-19", - "level": 2, - "x": 46, - "y": 2, - }, - { - "count": 1, - "date": "2019-11-20", - "level": 1, - "x": 46, - "y": 3, - }, - { - "count": 6, - "date": "2019-11-21", - "level": 1, - "x": 46, - "y": 4, - }, - { - "count": 10, - "date": "2019-11-22", - "level": 2, - "x": 46, - "y": 5, - }, - { - "count": 2, - "date": "2019-11-23", - "level": 1, - "x": 46, - "y": 6, - }, - { - "count": 0, - "date": "2019-11-24", - "level": 0, - "x": 47, - "y": 0, - }, - { - "count": 0, - "date": "2019-11-25", - "level": 0, - "x": 47, - "y": 1, - }, - { - "count": 1, - "date": "2019-11-26", - "level": 1, - "x": 47, - "y": 2, - }, - { - "count": 1, - "date": "2019-11-27", - "level": 1, - "x": 47, - "y": 3, - }, - { - "count": 0, - "date": "2019-11-28", - "level": 0, - "x": 47, - "y": 4, - }, - { - "count": 0, - "date": "2019-11-29", - "level": 0, - "x": 47, - "y": 5, - }, - { - "count": 2, - "date": "2019-11-30", - "level": 1, - "x": 47, - "y": 6, - }, - { - "count": 3, - "date": "2019-12-01", - "level": 1, - "x": 48, - "y": 0, - }, - { - "count": 3, - "date": "2019-12-02", - "level": 1, - "x": 48, - "y": 1, - }, - { - "count": 3, - "date": "2019-12-03", - "level": 1, - "x": 48, - "y": 2, - }, - { - "count": 21, - "date": "2019-12-04", - "level": 4, - "x": 48, - "y": 3, - }, - { - "count": 21, - "date": "2019-12-05", - "level": 4, - "x": 48, - "y": 4, - }, - { - "count": 1, - "date": "2019-12-06", - "level": 1, - "x": 48, - "y": 5, - }, - { - "count": 1, - "date": "2019-12-07", - "level": 1, - "x": 48, - "y": 6, - }, - { - "count": 12, - "date": "2019-12-08", - "level": 2, - "x": 49, - "y": 0, - }, - { - "count": 20, - "date": "2019-12-09", - "level": 4, - "x": 49, - "y": 1, - }, - { - "count": 0, - "date": "2019-12-10", - "level": 0, - "x": 49, - "y": 2, - }, - { - "count": 20, - "date": "2019-12-11", - "level": 4, - "x": 49, - "y": 3, - }, - { - "count": 0, - "date": "2019-12-12", - "level": 0, - "x": 49, - "y": 4, - }, - { - "count": 0, - "date": "2019-12-13", - "level": 0, - "x": 49, - "y": 5, - }, - { - "count": 0, - "date": "2019-12-14", - "level": 0, - "x": 49, - "y": 6, - }, - { - "count": 1, - "date": "2019-12-15", - "level": 1, - "x": 50, - "y": 0, - }, - { - "count": 0, - "date": "2019-12-16", - "level": 0, - "x": 50, - "y": 1, - }, - { - "count": 0, - "date": "2019-12-17", - "level": 0, - "x": 50, - "y": 2, - }, - { - "count": 1, - "date": "2019-12-18", - "level": 1, - "x": 50, - "y": 3, - }, - { - "count": 0, - "date": "2019-12-19", - "level": 0, - "x": 50, - "y": 4, - }, - { - "count": 0, - "date": "2019-12-20", - "level": 0, - "x": 50, - "y": 5, - }, - { - "count": 0, - "date": "2019-12-21", - "level": 0, - "x": 50, - "y": 6, - }, - { - "count": 0, - "date": "2019-12-22", - "level": 0, - "x": 51, - "y": 0, - }, - { - "count": 0, - "date": "2019-12-23", - "level": 0, - "x": 51, - "y": 1, - }, - { - "count": 0, - "date": "2019-12-24", - "level": 0, - "x": 51, - "y": 2, - }, - { - "count": 0, - "date": "2019-12-25", - "level": 0, - "x": 51, - "y": 3, - }, - { - "count": 0, - "date": "2019-12-26", - "level": 0, - "x": 51, - "y": 4, - }, - { - "count": 2, - "date": "2019-12-27", - "level": 1, - "x": 51, - "y": 5, - }, - { - "count": 0, - "date": "2019-12-28", - "level": 0, - "x": 51, - "y": 6, - }, - { - "count": 0, - "date": "2019-12-29", - "level": 0, - "x": 52, - "y": 0, - }, - { - "count": 2, - "date": "2019-12-30", - "level": 1, - "x": 52, - "y": 1, - }, - { - "count": 0, - "date": "2019-12-31", - "level": 0, - "x": 52, - "y": 2, - }, -] -`; diff --git a/packages/github-user-contribution/__tests__/formatParams.spec.ts b/packages/github-user-contribution/__tests__/formatParams.spec.ts deleted file mode 100644 index 93a1c2b..0000000 --- a/packages/github-user-contribution/__tests__/formatParams.spec.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { formatParams } from "../formatParams"; - -const params = [ - // - [{}, ""], - [{ year: 2017 }, "from=2017-01-01&to=2017-12-31"], - [{ from: "2017-12-03" }, "from=2017-12-03"], - [{ to: "2017-12-03" }, "to=2017-12-03"], -] as const; - -params.forEach(([params, res]) => - it(`should format ${JSON.stringify(params)}`, () => { - expect(formatParams(params)).toBe(res); - }) -); - -it("should fail if the date is in the future", () => { - expect(() => formatParams({ to: "9999-01-01" })).toThrow(Error); -}); diff --git a/packages/github-user-contribution/__tests__/getGithubUserContribution.spec.ts b/packages/github-user-contribution/__tests__/getGithubUserContribution.spec.ts index fa014ff..18e5418 100644 --- a/packages/github-user-contribution/__tests__/getGithubUserContribution.spec.ts +++ b/packages/github-user-contribution/__tests__/getGithubUserContribution.spec.ts @@ -1,9 +1,18 @@ import { getGithubUserContribution } from ".."; +import { config } from "dotenv"; +config({ path: __dirname + "/../../../.env" }); describe("getGithubUserContribution", () => { - const promise = getGithubUserContribution("platane"); + const promise = getGithubUserContribution("platane", { + githubToken: process.env.GITHUB_TOKEN!, + }); it("should resolve", async () => { + console.log( + "process.env.GITHUB_TOKEN", + process.env.GITHUB_TOKEN?.replace(/\d/g, "x") + ); + await promise; }); @@ -27,9 +36,3 @@ describe("getGithubUserContribution", () => { expect(undefinedDays).toEqual([]); }); }); - -xit("should match snapshot for year=2019", async () => { - expect( - await getGithubUserContribution("platane", { year: 2019 }) - ).toMatchSnapshot(); -}); diff --git a/packages/github-user-contribution/formatParams.ts b/packages/github-user-contribution/formatParams.ts deleted file mode 100644 index cf0fa91..0000000 --- a/packages/github-user-contribution/formatParams.ts +++ /dev/null @@ -1,38 +0,0 @@ -export type Options = { from?: string; to?: string } | { year: number }; - -export const formatParams = (options: Options = {}) => { - const sp = new URLSearchParams(); - - const o: any = { ...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: Date) => { - 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("-"); -}; diff --git a/packages/github-user-contribution/index.ts b/packages/github-user-contribution/index.ts index 33fcf81..6ae5c58 100644 --- a/packages/github-user-contribution/index.ts +++ b/packages/github-user-contribution/index.ts @@ -1,5 +1,4 @@ import fetch from "node-fetch"; -import { formatParams, Options } from "./formatParams"; /** * get the contribution grid from a github user page @@ -19,57 +18,83 @@ import { formatParams, Options } from "./formatParams"; */ export const getGithubUserContribution = async ( userName: string, - options: Options = {} + o: { githubToken: string } ) => { - // 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 query = /* GraphQL */ ` + query ($login: String!) { + user(login: $login) { + contributionsCollection { + contributionCalendar { + weeks { + contributionDays { + contributionCount + contributionLevel + weekday + date + } + } + } + } + } + } + `; + const variables = { login: userName }; - const res = await fetch(url); + const res = await fetch("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(); + const { data, errors } = (await res.json()) as { + data: GraphQLRes; + errors?: { message: string }[]; + }; - return parseUserPage(resText); + 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, + })) + ); }; -const parseUserPage = (content: string) => { - // 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; +type GraphQLRes = { + user: { + contributionsCollection: { + contributionCalendar: { + weeks: { + contributionDays: { + contributionCount: number; + contributionLevel: + | "FOURTH_QUARTILE" + | "THIRD_QUARTILE" + | "SECOND_QUARTILE" + | "FIRST_QUARTILE" + | "NONE"; + date: string; + weekday: number; + }[]; + }[]; + }; + }; + }; }; export type Res = Awaited>; diff --git a/packages/github-user-contribution/package.json b/packages/github-user-contribution/package.json index 39197e6..d657943 100644 --- a/packages/github-user-contribution/package.json +++ b/packages/github-user-contribution/package.json @@ -5,6 +5,7 @@ "node-fetch": "2.6.12" }, "devDependencies": { - "@types/node-fetch": "2.6.2" + "@types/node-fetch": "2.6.4", + "dotenv": "16.3.1" } } diff --git a/yarn.lock b/yarn.lock index a350080..b9cf2d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1264,14 +1264,6 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw== -"@types/node-fetch@2.6.2": - version "2.6.2" - resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.2.tgz#d1a9c5fd049d9415dce61571557104dec3ec81da" - integrity sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A== - dependencies: - "@types/node" "*" - form-data "^3.0.0" - "@types/node-fetch@2.6.3": version "2.6.3" resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.3.tgz#175d977f5e24d93ad0f57602693c435c57ad7e80" @@ -1280,6 +1272,14 @@ "@types/node" "*" form-data "^3.0.0" +"@types/node-fetch@2.6.4": + version "2.6.4" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.4.tgz#1bc3a26de814f6bf466b25aeb1473fa1afe6a660" + integrity sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg== + dependencies: + "@types/node" "*" + form-data "^3.0.0" + "@types/node@*": version "14.0.23" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.23.tgz#676fa0883450ed9da0bb24156213636290892806" @@ -2695,6 +2695,11 @@ dot-case@^3.0.4: no-case "^3.0.4" tslib "^2.0.3" +dotenv@16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + download@^6.2.2: version "6.2.5" resolved "https://registry.yarnpkg.com/download/-/download-6.2.5.tgz#acd6a542e4cd0bb42ca70cfc98c9e43b07039714"