diff --git a/README.md b/README.md index e7f0a80..3d99c19 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,17 @@ Explore the [code](src/index.js)! It's tiny and there aren't many dependencies. It only scrapes publicly available data from existing GitHub contribution graphs. It does not have access to private commits or issues created. So I can promise that you will not get in trouble for syncing your personal and work GitHub graphs considering there isn't any private company code being exposed! +## Using with Github Enterprise + +You'll need to set a few environmental variables + +``` +export GITHUB_DOMAIN=git.{YOURDOMAIN}.com +export GITHUB_PERSONAL_ACCESS_TOKEN={a personal access token with the correct permissions to read users} +export GITHUB_COOKIE={a cookie copied from an active browser session (this should work with pretty much all SSO implementations} +npm run start +``` + ## On Project's Future ✨ There's a lot of potential features and automations that could be added! Something as basic as accepting multiple years to pull at once, or more complicated like having a GitHub Action that once per month/year/time period creates a PR with newer commits, making it effortless to keep them synced. diff --git a/src/axios.js b/src/axios.js new file mode 100644 index 0000000..c14aa60 --- /dev/null +++ b/src/axios.js @@ -0,0 +1,16 @@ +import axios from "axios"; + +// In the case of a GHE account, you'll need auth options. otherwise, no. +const options = + process.env.GITHUB_PERSONAL_ACCESS_TOKEN && process.env.GITHUB_COOKIE + ? { + headers: { + Authorization: `bearer ${process.env.GITHUB_PERSONAL_ACCESS_TOKEN}`, + Cookie: process.env.GITHUB_COOKIE, + }, + } + : {}; + +const instance = axios.create(options); + +export default instance; diff --git a/src/index.js b/src/index.js index 4cddb74..e227eff 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,16 @@ import { parse } from "node-html-parser"; -import axios from "axios"; +import axios from "./axios.js"; import fs from "fs"; import shell from "shelljs"; export default async (input) => { + //In the case of a GitHub enterprise account, the API is at a different location + const githubdomain = process.env.GITHUB_DOMAIN + ? process.env.GITHUB_DOMAIN + : "github.com"; + const res = await axios.get( - `https://github.com/users/${input.username}/contributions?tab=overview&from=${input.year}-12-01&to=${input.year}-12-31` + `https://${githubdomain}/users/${input.username}/contributions?tab=overview&from=${input.year}-12-01&to=${input.year}-12-31` ); // Gathers all the squares from GitHub contribution graph. diff --git a/src/interface.js b/src/interface.js index c66f1cf..bcf50eb 100644 --- a/src/interface.js +++ b/src/interface.js @@ -1,9 +1,13 @@ import inquirer from "inquirer"; import script from "./index.js"; -import axios from "axios"; +import axios from "./axios.js"; console.log("\nHello there!\n"); +const githubapi = process.env.GITHUB_DOMAIN + ? process.env.GITHUB_DOMAIN + "/api/v3" + : "api.github.com"; + const questions = [ { type: "input", @@ -12,7 +16,7 @@ const questions = [ "Please enter GitHub nickname with which you'd like to sync contributions:", validate: (value) => axios - .get(`https://api.github.com/users/${value}`) + .get(`https://${githubapi}/users/${value}`) .then(() => true) .catch(() => "Please enter an existing GitHub username."), },