Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions src/axios.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 6 additions & 2 deletions src/interface.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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."),
},
Expand Down