{"id":49397483,"url":"https://github.com/rithviknishad/leaderboard-bot","last_synced_at":"2026-04-28T16:38:29.336Z","repository":{"id":325010330,"uuid":"1099447139","full_name":"rithviknishad/leaderboard-bot","owner":"rithviknishad","description":"Cloudflare Worker for GitHub App webhook handling","archived":false,"fork":false,"pushed_at":"2025-11-19T03:13:33.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-19T05:24:57.195Z","etag":null,"topics":["cloudflare","github","leaderboard","webhook","worker"],"latest_commit_sha":null,"homepage":"https://contributors.ohc.network","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rithviknishad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-19T02:14:18.000Z","updated_at":"2025-11-19T03:13:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rithviknishad/leaderboard-bot","commit_stats":null,"previous_names":["rithviknishad/leaderboard-bot"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/rithviknishad/leaderboard-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rithviknishad%2Fleaderboard-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rithviknishad%2Fleaderboard-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rithviknishad%2Fleaderboard-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rithviknishad%2Fleaderboard-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rithviknishad","download_url":"https://codeload.github.com/rithviknishad/leaderboard-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rithviknishad%2Fleaderboard-bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32390053,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","github","leaderboard","webhook","worker"],"created_at":"2026-04-28T16:38:28.538Z","updated_at":"2026-04-28T16:38:29.330Z","avatar_url":"https://github.com/rithviknishad.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Leaderboard Bot - Cloudflare Worker\n\nA Cloudflare Worker that handles GitHub App webhook events and forwards installation events to the automation repository for processing.\n\n## Features\n\n- Receives GitHub App webhook events (installation and installation_repositories)\n- **Secure webhook signature verification** using HMAC-SHA256\n- Forwards relevant events to the automation repository via `repository_dispatch`\n- **Automated repository setup** via GitHub Actions workflow\n- Built with TypeScript for type safety\n- Comprehensive test coverage with Vitest\n- Easy deployment with Wrangler\n\n## Prerequisites\n\n- [Node.js](https://nodejs.org/) (v18 or later)\n- [pnpm](https://pnpm.io/) package manager\n- [Cloudflare account](https://dash.cloudflare.com/sign-up)\n- [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/) (installed via pnpm)\n- GitHub Personal Access Token with `repo` scope\n\n## Setup\n\n### 1. Install Dependencies\n\n```bash\npnpm install\n```\n\n### 2. Configure Wrangler\n\nEdit `wrangler.toml` and set your Cloudflare account ID:\n\n```toml\naccount_id = \"your-account-id-here\"\n```\n\nYou can find your account ID in the Cloudflare dashboard or by running:\n\n```bash\npnpm wrangler whoami\n```\n\n### 3. Set Secrets\n\nSet the required secrets for the worker:\n\n```bash\n# GitHub Personal Access Token for triggering repository_dispatch\npnpm wrangler secret put AUTOMATION_REPO_TRIGGER_TOKEN\n\n# GitHub webhook secret for signature verification\npnpm wrangler secret put GITHUB_WEBHOOK_SECRET\n```\n\n**AUTOMATION_REPO_TRIGGER_TOKEN** - GitHub Personal Access Token that needs:\n- `repo` scope (to trigger repository_dispatch events)\n- Access to the `rithviknishad/leaderboard-bot` repository\n\n**GITHUB_WEBHOOK_SECRET** - The webhook secret you configure in your GitHub App settings. This is used to verify that webhook requests are actually coming from GitHub using HMAC-SHA256 signatures.\n\n### 4. Configure GitHub Repository Secrets and Variables\n\nFor the automation workflow to work, add these to your `rithviknishad/leaderboard-bot` repository:\n\n1. Go to repository Settings → Secrets and variables → Actions\n\n2. Under the **Variables** tab, add:\n   - **LEADERBOARD_BOT_ID**: Your GitHub App ID (found in App settings)\n\n3. Under the **Secrets** tab, add:\n   - **LEADERBOARD_BOT_PRIVATE_KEY**: Your GitHub App private key (PEM format)\n\nTo generate a private key for your GitHub App:\n1. Go to your GitHub App settings\n2. Scroll to \"Private keys\" section\n3. Click \"Generate a private key\"\n4. Save the downloaded `.pem` file contents as the secret value\n\n## Development\n\n### Run Locally\n\nStart the development server:\n\n```bash\npnpm dev\n```\n\nThis will start a local server (typically at `http://localhost:8787`) where you can test the worker.\n\n### Test the Worker\n\nYou can test the worker locally using curl:\n\n```bash\n# Test GET request (should return \"ok\")\ncurl http://localhost:8787\n\n# Test POST with installation event\ncurl -X POST http://localhost:8787 \\\n  -H \"x-github-event: installation\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"action\":\"created\",\"installation\":{\"id\":12345}}'\n```\n\n### Run Tests\n\nRun the test suite:\n\n```bash\n# Run tests once\npnpm test\n\n# Run tests in watch mode\npnpm test:watch\n```\n\n### Type Check\n\nCheck TypeScript types:\n\n```bash\npnpm type-check\n```\n\n## Deployment\n\n### Deploy to Cloudflare Workers\n\n```bash\npnpm deploy\n```\n\nThis will:\n1. Build your worker\n2. Upload it to Cloudflare\n3. Make it available at your worker URL\n\n### Configure GitHub Webhook\n\nAfter deployment:\n\n1. Go to your GitHub App settings\n2. Set the Webhook URL to your worker URL (e.g., `https://leaderboard-bot.your-subdomain.workers.dev`)\n3. **Set a webhook secret** - Generate a secure random string and save it (you'll need to add it as `GITHUB_WEBHOOK_SECRET` in Wrangler secrets)\n4. Subscribe to these events:\n   - `installation`\n   - `installation_repositories`\n\n**Important:** The worker requires webhook signature verification. Make sure the webhook secret in your GitHub App settings matches the `GITHUB_WEBHOOK_SECRET` you configured in step 3 of the setup.\n\n## How It Works\n\n1. GitHub sends webhook events to the worker when:\n   - Your app is installed on a repository (`installation` event)\n   - Repositories are added/removed from the installation (`installation_repositories` event)\n\n2. The worker **verifies the webhook signature** using HMAC-SHA256 to ensure the request is authentic\n\n3. The worker validates the request and filters for relevant events\n\n4. For installation-related events, the worker forwards them to `rithviknishad/leaderboard-bot` via the GitHub API's `repository_dispatch` endpoint\n\n5. The automation repository can then handle the event with a GitHub Actions workflow\n\n## Installation Handler Workflow\n\nThe repository includes a GitHub Actions workflow (`.github/workflows/auto-setup.yml`) that automatically processes installation events:\n\n### What It Does\n\n1. **Receives repository_dispatch events** from the Cloudflare Worker\n2. **Authenticates as the GitHub App** using the app credentials stored in this repository\n3. **Sets up credentials on each installed repository**:\n   - Sets `LEADERBOARD_BOT_ID` as a repository variable\n   - Sets `LEADERBOARD_BOT_PRIVATE_KEY` as a repository secret\n\nThis allows the target repositories to use these credentials in their own workflows to generate installation tokens and interact with the GitHub API as the leaderboard bot.\n\n### How It Works\n\n```mermaid\ngraph LR\n    A[GitHub App Installed] --\u003e B[Webhook to Worker]\n    B --\u003e C[Worker Verifies Signature]\n    C --\u003e D[Worker Dispatches Event]\n    D --\u003e E[Workflow Triggered]\n    E --\u003e F[Authenticate as App]\n    F --\u003e G[Get Installation Token]\n    G --\u003e H[Set Secrets/Variables on Target Repos]\n```\n\n### Using the Bot in Target Repositories\n\nOnce the bot is installed, target repositories will have access to:\n- `LEADERBOARD_BOT_ID` (variable)\n- `LEADERBOARD_BOT_PRIVATE_KEY` (secret)\n\nThese can be used in GitHub Actions workflows to generate installation tokens:\n\n```yaml\n- name: Generate app token\n  id: app_token\n  uses: actions/create-github-app-token@v1\n  with:\n    app-id: ${{ vars.LEADERBOARD_BOT_ID }}\n    private-key: ${{ secrets.LEADERBOARD_BOT_PRIVATE_KEY }}\n\n- name: Use the token\n  env:\n    GH_TOKEN: ${{ steps.app_token.outputs.token }}\n  run: |\n    gh api /user\n```\n\n## Project Structure\n\n```\n.\n├── .github/\n│   └── workflows/\n│       ├── test.yml           # CI/CD test workflow\n│       └── auto-setup.yml     # Installation handler workflow\n├── src/\n│   ├── index.ts          # Main worker code\n│   └── index.test.ts     # Test suite\n├── wrangler.toml         # Cloudflare Worker configuration\n├── tsconfig.json         # TypeScript configuration\n├── vitest.config.ts      # Vitest configuration\n├── package.json          # Dependencies and scripts\n├── SECURITY.md          # Security documentation\n└── README.md            # This file\n```\n\n## Environment Variables\n\n### Cloudflare Worker Secrets (via `wrangler secret put`)\n\n- `AUTOMATION_REPO_TRIGGER_TOKEN`: GitHub Personal Access Token for triggering repository_dispatch events\n- `GITHUB_WEBHOOK_SECRET`: Webhook secret for verifying GitHub webhook signatures (must match the secret configured in GitHub App settings)\n\n### GitHub Repository Configuration (in `rithviknishad/leaderboard-bot` repository settings)\n\n**Variables** (Settings → Secrets and variables → Actions → Variables):\n- `LEADERBOARD_BOT_ID`: GitHub App ID\n\n**Secrets** (Settings → Secrets and variables → Actions → Secrets):\n- `LEADERBOARD_BOT_PRIVATE_KEY`: GitHub App private key (PEM format)\n\n### Target Repository Configuration (automatically set by the workflow)\n\nWhen the bot is installed on a repository, the workflow automatically sets:\n\n**Variables**:\n- `LEADERBOARD_BOT_ID`: GitHub App ID (same as above)\n\n**Secrets**:\n- `LEADERBOARD_BOT_PRIVATE_KEY`: GitHub App private key (same as above)\n\n## Troubleshooting\n\n### Worker returns \"missing AUTOMATION_REPO_TRIGGER_TOKEN\"\n\nMake sure you've set the secret:\n\n```bash\npnpm wrangler secret put AUTOMATION_REPO_TRIGGER_TOKEN\n```\n\n### Worker returns \"invalid signature\" (401)\n\nThis means the webhook signature verification failed. Check that:\n- You've set the `GITHUB_WEBHOOK_SECRET` in Wrangler: `pnpm wrangler secret put GITHUB_WEBHOOK_SECRET`\n- The secret matches exactly what you configured in your GitHub App webhook settings\n- The request is actually coming from GitHub (not a test request without proper signature)\n\n### Worker returns \"missing x-hub-signature-256 header\" (401)\n\nThe webhook request is missing the signature header. This typically means:\n- The request is not coming from GitHub\n- You need to configure a webhook secret in your GitHub App settings\n\n### GitHub API returns 401 Unauthorized\n\nCheck that your token has the correct permissions:\n- `repo` scope\n- Access to the target repository\n\n### Events are being ignored\n\nVerify that:\n- The `x-github-event` header is set to `installation` or `installation_repositories`\n- The request body contains valid JSON\n- The webhook signature is valid\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frithviknishad%2Fleaderboard-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frithviknishad%2Fleaderboard-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frithviknishad%2Fleaderboard-bot/lists"}