This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Google-GitHub Sync is a tool that synchronizes Google Workspace users with GitHub organization members and Atlassian. It automatically invites users with GitHub usernames to a GitHub organization and removes users who are no longer in Google Workspace. It automatically removes users who are no longer in Google Workspace from Atlassian. It automatically suspends users who are no longer active in Atlassian. The tool provides both a Slack bot interface for manual triggers and scheduled synchronization via cron jobs.
Install dependencies:
bun installRun the application:
bun run index.tsFormat code:
bun run format*Lint code:
bun run lintDocker commands:
docker build -t google-github-sync .
docker run -d google-github-syncThe application is organized into modular services with centralized configuration:
File Structure:
config.ts - Centralized configuration with validation
services/
├── google-workspace.ts - Google Workspace API integration
├── github-sync.ts - GitHub sync logic (WorkspaceGitHubSync class)
└── slack-notifier.ts - Slack message formatting
index.ts - Application bootstrap, Slack bot, cron job
Main Components:
-
Configuration Module (
config.ts):- Validates all required environment variables at startup
- Exports typed configuration object organized by service (google, github, slack, app)
- Fails fast with descriptive errors if required variables are missing
- Parses Google credentials JSON automatically
-
WorkspaceGitHubSync class (
services/github-sync.ts):- Core synchronization logic
- Fetches Google Workspace users via Google Admin SDK API
- Manages GitHub organization membership via Octokit
- Handles invitations and removals based on custom schema field
3rd-party_tools.GitHub_Username
-
Slack Bot (
index.ts):- Built with @slack/bolt using Socket Mode
- Listens for
/sync-githubslash command for manual sync triggers - Posts formatted sync results with user links and email addresses
-
Cron Job (
index.ts):- Scheduled synchronization
- Uses
cronpackage with configurable schedule - Automatically notifies Slack DM group when changes occur
- Only sends notifications when there are actual changes (invites, removals, or errors)
Google Workspace Integration:
- Uses service account credentials with domain-wide delegation
- Requires
admin.directory.user.readonlyscope - Impersonates admin user via
subjectfield - Fetches up to 300 users with custom schema projection
- GitHub usernames are stored in
customSchemas['3rd-party_tools'].GitHub_Username
GitHub Integration:
- Uses Octokit with personal access token
- Requires organization admin permissions
- Uses pagination for listing members and pending invitations
- Invites users by
invitee_id(not by email) - All username comparisons are case-insensitive via
.toLowerCase()
Remove Stop List:
- Environment variable
REMOVE_STOP_LISTcontains comma-separated usernames - These users will never be removed from GitHub org, even if not in Workspace
- Useful for bot accounts or external collaborators
Sync Logic:
- Fetch all Google Workspace users with full projection
- Fetch current GitHub org members and pending invitations
- Filter Workspace users who have GitHub usernames in custom schema
- Invite users not currently in org or pending (looks up GitHub user by username first)
- Remove members not in Workspace and not in stop list
- Return structured results with invited users (with emails), removed usernames, and errors
Cron Notifications:
syncPeriodically()creates a multi-user DM channel with all bot conversations- Only sends notification if there are changes AND multiple users exist
- Filters out USLACKBOT from recipient list
- Uses
conversations.open()with multiple user IDs to create/find group DM
All configuration is centralized in config.ts which validates environment variables at startup and provides typed access throughout the application. The application will fail fast with descriptive error messages if required variables are missing.
Required environment variables in .env:
GOOGLE_APPLICATION_CREDENTIALS: JSON string of service account credentialsGOOGLE_ADMIN_EMAIL: Admin email to impersonateGITHUB_TOKEN: GitHub personal access token with org admin permissionsGITHUB_ORG_NAME: GitHub organization nameSLACK_BOT_TOKEN: Bot user OAuth token (xoxb-)SLACK_SIGNING_SECRET: Slack app signing secretSLACK_APP_TOKEN: App-level token for Socket Mode (xapp-)REMOVE_STOP_LIST: Comma-separated GitHub usernames to never remove (optional)CRON_SCHEDULE: Cron schedule string (optional, defaults to midnight daily)PORT: Port for Slack app (optional, defaults to 3000)
- Built for Bun runtime (not Node.js)
- Uses TypeScript with strict mode enabled
- No build step required (noEmit: true in tsconfig)
- Runs as long-lived process with Slack Socket Mode and cron job
- Prefer imports without extensions, DO NOT use .js extensions in import paths