get-all-github-contributions
v0.1.7
Published
Get all GitHub contributions
Maintainers
Readme
get-all-github-contributions
Sync all your GitHub contributions (commits) across multiple accounts, organizations, and repositories using the GitHub GraphQL API.
Installation
npm install get-all-github-contributionsUsage
As a library
import { GetAllGitHubContributions } from "get-all-github-contributions";
import type { ImportConfig, ImportData } from "get-all-github-contributions";
const config: ImportConfig = {
tokens: {
"your-github-username": "ghp_yourPersonalAccessToken",
},
import: {
concurrency: 10,
maxRetries: 2,
},
};
// Optionally pass existing data to do an incremental sync
const data: ImportData = {
accounts: {},
languageColors: {},
importState: { accountProgress: {} },
};
const sync = new GetAllGitHubContributions({ config, data });
await sync.sync();
// `data` is mutated in place and now contains all contributions
console.log(data.accounts);As a CLI script
- Copy
config.example.jsontoconfig.jsonand add your GitHub personal access tokens - Run the import:
npm run importData is saved to data/data.json and persisted every 30 seconds during the sync.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
| tokens | Record<string, string> | required | Map of GitHub username to personal access token |
| import.concurrency | number | 10 | Maximum concurrent API requests |
| import.maxRetries | number | 2 | Retry attempts for failed requests |
| import.pageSize | number | 50 | Number of items per page for GraphQL pagination |
| import.rateLimitGracePeriod | number | 1000 | Grace period in ms added when waiting for rate limit reset |
| import.recheckWithRemainingRateLimit | boolean | false | Recheck branches for new commits using remaining rate limit after initial sync |
| import.skip.organizations | string[] | [] | Organization logins to skip |
| import.skip.repositories | string[] | [] | Repositories to skip (owner/repo) |
GitHub Token
Create a personal access token at github.com/settings/tokens with the repo and read:org scopes.
Data Structure
The synced ImportData contains:
- accounts - Per-account data including user profile, organizations, repositories, branches, and commits
- languageColors - Map of language names to their GitHub colors
- importState - Sync progress and timestamps for incremental syncs
Each user profile includes:
interface User {
id: string;
login: string;
name: string;
bio: string;
avatarUrl: string;
url: string;
gistCount: number;
followerCount: number;
followingCount: number;
commitCommentCount: number;
issueCommentCount: number;
commitCommentTimestamps: number[];
issueCommentTimestamps: number[];
}Each repository includes:
interface Repository {
name: string;
description?: string;
stargazerCount: number;
forkCount: number;
isPrivate: boolean;
url: string;
homepageUrl?: string;
languages: string[];
owner: string;
defaultBranch: string;
}Each commit includes:
interface Commit {
oid: string; // Git commit SHA
additions: number; // Lines added
deletions: number; // Lines deleted
changedFiles: number; // Number of files changed
commitedAtTimestamp: number; // Unix timestamp
}How It Works
- Fetches user profile (including bio, follower/following counts, gist count) and organizations for each configured account
- Syncs commit comment and issue comment timestamps
- Discovers all repositories (owned, collaborator, and organization member) with metadata (description, stars, forks, homepage)
- Enumerates branches per repository
- Fetches commits authored by the authenticated user per branch
- Skips repositories and branches that haven't changed since the last sync
All API calls use pagination and respect GitHub's rate limits with automatic retry and backoff.
License
MIT
