BA
babblebey/fix-contributor-table
fix-contributor-table
A JavaScript tool to fix and maintain contributor tables by syncing GitHub repository contributors with Supabase database.
Features
- Fetches contributor data from GitHub API
- Stores contributor information in Supabase database
- Supports manual GitHub Actions workflow dispatch
- Environment variable validation
- Error handling and logging
Prerequisites
- Node.js 18+
- npm or yarn
- Supabase project with a
contributorstable - GitHub personal access token
Installation
- Clone the repository:
git clone <repository-url>
cd fix-contributor-table- Install dependencies:
npm installEnvironment Variables
The following environment variables are required:
SUPABASE_URL: Your Supabase project URLSUPABASE_SERVICE_ROLE_KEY: Your Supabase service role key (with database access)GITHUB_TOKEN: GitHub personal access token with repo access
Optional environment variables:
REPO_OWNER: GitHub repository owner (defaults to current repository owner)REPO_NAME: GitHub repository name (defaults to current repository name)
Usage
Local Development
- Set up your environment variables:
export SUPABASE_URL="your-supabase-url"
export SUPABASE_SERVICE_ROLE_KEY="your-service-role-key"
export GITHUB_TOKEN="your-github-token"- Run the script:
npm run fix-contributor
# or
npm startGitHub Actions
The repository includes a GitHub Actions workflow that can be manually triggered:
- Go to the "Actions" tab in your GitHub repository
- Select "Fix Contributor Table" workflow
- Click "Run workflow"
- Optionally specify:
- Repository owner (defaults to current repo owner)
- Repository name (defaults to current repo name)
- Dry run mode (test without making changes)
Required Secrets
Configure the following secrets in your GitHub repository settings:
SUPABASE_URLSUPABASE_SERVICE_ROLE_KEYGITHUB_TOKEN(automatically available in GitHub Actions)
Database Schema
The script expects a contributors table in Supabase with the following structure:
CREATE TABLE contributors (
id SERIAL PRIMARY KEY,
username TEXT NOT NULL,
github_id BIGINT NOT NULL,
avatar_url TEXT,
html_url TEXT,
contributions INTEGER DEFAULT 0,
repository TEXT NOT NULL,
type TEXT DEFAULT 'User',
updated_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(github_id, repository)
);Project Structure
fix-contributor-table/
├── .github/
│ └── workflows/
│ └── fix-contributor.yml # GitHub Actions workflow
├── fix-contributor.js # Main script
├── package.json # Project configuration
├── .gitignore # Git ignore rules
└── README.md # This file
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
License
ISC