GitHub Integration Setup
Configure GitHub integration to commit content directly from the editor
GitHub Integration Setup
Overview
The GitHub integration allows you to commit articles and categories directly to your GitHub repository from the built-in editor. This eliminates the need to manually download files and upload them to your repository.
Quick Setup
Step 1: Create a GitHub Personal Access Token
- Go to GitHub.com and sign in
- Navigate to Settings β Developer settings β Personal access tokens β Tokens (classic)
- Click "Generate new token (classic)"
- Configure your token:
- Note: "Help Center Content Management"
- Expiration: Choose your preferred duration
- Scopes: Select
repo
(Full control of private repositories)
- Click "Generate token"
- Copy the token immediately (you won't see it again!)
Step 1.1: Required Token Permissions
For the GitHub integration to work properly, your token needs specific permissions:
β Required Scopes
Scope | Purpose | Required |
---|---|---|
repo | Full control of private repositories | β Yes |
π What repo
scope provides:
Contents (Read & Write)
- Repository contents, commits, branches, downloads, releases, and merges
- This allows the integration to:
- Read existing files to check for duplicates
- Create new markdown files for articles and categories
- Commit changes with custom commit messages
- Update existing articles when modified
Metadata (Read Only)
- Search repositories, list collaborators, and access repository metadata
- This allows the integration to:
- Verify repository exists and is accessible
- Check branch information
- Validate repository structure
π Permission Explanation
The repo
scope is required because the integration needs these specific permissions:
Contents (Read & Write) - Essential for:
- Reading repository contents - To check if files already exist before creating
- Creating new files - To add new articles (
article-slug.md
) and categories (_category.md
) - Updating existing files - To modify articles when content is edited
- Committing changes - To save content with descriptive commit messages
- Managing branches - To work with your specified target branch
Metadata (Read Only) - Required for:
- Repository verification - To confirm the repository exists and is accessible
- Branch validation - To ensure the target branch exists before committing
- Access validation - To verify the token has proper permissions
These permissions ensure the integration can safely manage your help center content while maintaining proper version control.
β οΈ Security Note
The repo
scope provides full repository access. For maximum security:
- Use a dedicated GitHub account for content management
- Regularly rotate tokens (every 6-12 months)
- Monitor repository activity for unauthorized changes
- Revoke tokens when no longer needed
Step 2: Configure Environment Variables
Add the following to your .env.local
file:
# GitHub Integration
GITHUB_TOKEN=ghp_your_actual_token_here
NEXT_PUBLIC_GITHUB_ENABLED=true
GITHUB_OWNER=your-github-username
GITHUB_REPO=your-repository-name
GITHUB_BRANCH=main
Step 3: Verify Your Repository Structure
Your repository should have this structure:
your-repo/
βββ content/
β βββ getting-started/
β βββ features/
β βββ ... other categories
βββ ... other project files
The integration will create/update files in the content/
folder.
Configuration Options
Required Environment Variables
Variable | Description | Example |
---|---|---|
GITHUB_TOKEN | Your personal access token | ghp_abc123... |
GITHUB_OWNER | Your GitHub username/organization | daviddunnington |
GITHUB_REPO | Repository name | markdown-help-center |
GITHUB_BRANCH | Target branch for commits | main |
Optional Settings
Variable | Description | Default |
---|---|---|
NEXT_PUBLIC_GITHUB_ENABLED | Enable/disable GitHub features in UI | true |
Testing Your Setup
1. Start Development Server
npm run dev
2. Access the Editor
- Navigate to
/editor
- Sign in (authentication required for GitHub features)
3. Test GitHub Integration
- Create a test article with some content
- Look for GitHub buttons:
- π Commit Article to GitHub
- π Commit Category to GitHub (if creating new category)
- Click a commit button
- Add a commit message (e.g., "Test article creation")
- Submit - you should see success notification
- Check your GitHub repository - files should appear in the
content/
folder
How It Works
File Structure
When you commit content, files are organized as:
content/
βββ category-name/
β βββ _category.md # Category configuration
β βββ article-slug.md # Your article
Commit Types
Single Article Commit:
- Creates:
content/[category]/[article-slug].md
- Updates existing article if it already exists
Category Commit:
- Creates:
content/[category]/_category.md
- Creates:
content/[category]/[article-slug].md
- Commits both files together
Authentication Requirements
- User must be signed in to access GitHub features
- GitHub token must be valid and have repo permissions
- Repository must exist and be accessible
Troubleshooting
β "GitHub integration not enabled"
Problem: GitHub features don't appear in the editor
Solution:
# Enable GitHub integration
NEXT_PUBLIC_GITHUB_ENABLED=true
β "GitHub token not configured"
Problem: Token is missing or invalid
Solution:
- Check your token in
.env.local
- Ensure token has
repo
scope - Verify token hasn't expired
β "Repository not found"
Problem: Can't access the specified repository
Solution:
# Verify these match your actual repository
GITHUB_OWNER=your-actual-username
GITHUB_REPO=your-actual-repo-name
β "Branch not found"
Problem: Target branch doesn't exist
Solution:
# Use an existing branch (usually 'main' or 'master')
GITHUB_BRANCH=main
β "Unauthorized" errors
Problem: Token permissions insufficient
Solution:
- Regenerate token with
repo
scope - For organization repos, ensure token has org access
- Check repository visibility settings
β "API rate limit exceeded"
Problem: Too many requests to GitHub API
Solution:
- Wait for rate limit reset (1 hour)
- GitHub allows 5,000 requests/hour for authenticated users
- Consider spacing out commits
Security Considerations
π Token Security
- Never commit your
.env.local
file - Use specific scopes - only
repo
is needed - Rotate tokens regularly (every 6-12 months)
- Revoke unused tokens in GitHub settings
π‘οΈ Repository Access
- Private repos recommended for internal content
- Public repos work but content is visible to everyone
- Organization repos require proper team permissions
π€ User Access Control
- Authentication required - users must sign in to commit
Production Deployment
Environment Variables
Add these to your hosting platform (Vercel, Netlify, etc.):
GITHUB_TOKEN=ghp_your_production_token_here
NEXT_PUBLIC_GITHUB_ENABLED=true
GITHUB_OWNER=your-github-username
GITHUB_REPO=your-repository-name
GITHUB_BRANCH=main
Token Management
- Use separate tokens for development and production
- Set appropriate expiration dates
- Document token purpose for team members
Benefits
For Content Teams
- β No technical setup required for content creators
- β Instant publishing - commits trigger deployments
- β Version control - full history of all changes
- β Collaboration - multiple team members can contribute
For Developers
- β Automated workflow - no manual file management
- β Git integration - leverages existing development workflow
- β Audit trail - track all content changes
- β Backup protection - content automatically backed up
Example Workflow
- Content creator opens
/editor
- Creates new article with title, description, content
- Reviews preview to ensure formatting is correct
- Clicks "Commit to GitHub" with descriptive message
- GitHub receives commit and triggers deployment
- Content goes live automatically
Quick Start: Get your GitHub token, add it to
.env.local
with your repo details, setNEXT_PUBLIC_GITHUB_ENABLED=true
, and start committing content directly from the editor!