From fba7b92e3bb57dfb0805773545a4b5d58104a983 Mon Sep 17 00:00:00 2001 From: Bobby Date: Thu, 21 Apr 2022 16:44:29 -0400 Subject: Coming soon page --- api/github.js | 80 ----------------------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 api/github.js (limited to 'api/github.js') diff --git a/api/github.js b/api/github.js deleted file mode 100644 index 318d084..0000000 --- a/api/github.js +++ /dev/null @@ -1,80 +0,0 @@ -const { Octokit: OctokitRest } = require("@octokit/rest"); -const fetch = (...args) => - import("node-fetch").then(({ default: fetch }) => fetch(...args)); - -require("dotenv").config(); -class Github { - octokit = null; - username = null; - constructor(username) { - this.octokitRest = new OctokitRest({ - auth: process.env.GITHUB_TOKEN, - }); - this.username = username; - } - async getRepos(page) { - const { data } = await this.octokitRest.repos.listForUser({ - username: this.username, - type: "all", - sort: "updated", - per_page: 10, - page: page, - }); - return data; - } - - async getUserDetails() { - const { data } = await this.octokitRest.users.getByUsername({ - username: this.username, - }); - return data; - } - - async getOneYearUserContributions() { - const body = { - query: `query { - user(login: "${this.username}") { - name - contributionsCollection { - contributionCalendar { - colors - totalContributions - weeks { - contributionDays { - color - contributionCount - date - weekday - } - firstDay - } - } - } - } - }`, - }; - const headers = { - Authorization: `bearer ${process.env.GITHUB_TOKEN}`, - }; - const response = await fetch("https://api.github.com/graphql", { - method: "POST", - body: JSON.stringify(body), - headers: headers, - }); - const data = await response.json(); - const contributionData = []; - data.data.user.contributionsCollection.contributionCalendar.weeks.forEach( - (week) => { - let weeklyContributionCount = 0; - - week.contributionDays.forEach((day) => { - weeklyContributionCount += day.contributionCount; - }); - contributionData.push(weeklyContributionCount); - } - ); - return contributionData; - } -} - -exports.Github = Github; -- cgit v1.2.3