Skip to content

Latest commit

 

History

History
324 lines (249 loc) · 14.2 KB

github-app-setup.md

File metadata and controls

324 lines (249 loc) · 14.2 KB

GitHub App Setup Guide

Overview

Gitdog uses a GitHub App to access user repositories. This provides:

  • Access to private and organization repositories
  • Better permission control than OAuth Apps
  • Multiple organization installations
  • Webhook integration for real-time updates

Important Notes

Gitdog uses GitHub App for both user authentication and repository access. This provides better security and permission control than traditional OAuth Apps.

Creating the GitHub App

1. Create New GitHub App

Go to: https://github.com/settings/apps/new

2. Basic Information

  • GitHub App name: Choose a unique name whose slug matches VITE_GITHUB_APP_SLUG (the local default slug is gitdogbot-dev)
  • Homepage URL: http://localhost:5173 (production: https://gitdog.dev)
  • Callback URLs (add both):
    • ${CONVEX_SITE_URL}/oauth/github/callback, the sign-in callback served by the authGithub component of @convex-dev/auth
    • ${CUSTOM_AUTH_SITE_URL ?? CONVEX_SITE_URL}/github/access/callback, the "Verify GitHub access" callback that records which installations a signed-in user can reach
    • Use the concrete CUSTOM_AUTH_SITE_URL when it is configured; otherwise, use the target deployment's concrete CONVEX_SITE_URL, such as https://example-deployment.convex.site
    • These are OAuth callbacks; they are not the frontend Setup URL
  • Setup URL: http://localhost:5173/repositories/connect
    • ✅ Check "Redirect on update"

3. Webhook Configuration

  • Webhook URL: https://your-deployment.convex.site/github/webhook
  • Webhook secret: Generate a random string and save it
  • Active: ✅ Checked

4. Permissions

Repository permissions:

  • Contents: Read-only
  • Pull requests: Read & write
  • Issues: Read & write
  • Discussions: Read & write
  • Metadata: Read-only (automatic)

Organization permissions (optional):

  • Members: Read-only, with the Organization and Member events below

Account permissions:

  • Email addresses: Read-only

5. Subscribe to Events

  • ✅ Installation
  • ✅ Installation repositories
  • ✅ Repository
  • ✅ Push
  • ✅ Pull requests
  • ✅ Issues
  • ✅ Issue comments
  • ✅ Discussions
  • ✅ Discussion comments
  • Optional: Organization and Member (need the Members permission above)

The Repository event keeps stored repository metadata current after repository metadata changes. Gitdog identifies rename and transfer events by GitHub's immutable numeric repository ID, then fail-closes cached free eligibility until the next live generation verification. Installation and Installation repositories events pause repositories when access is removed; an access-added event reactivates the existing row and schedules a fresh index. The Push event keeps the index current after default-branch commits.

With the issue or discussion assistant on, new issues and discussions, and comments that mention the app, start assistant work. Content written by a bot is skipped. An edit is answered again after a 90-second wait, so a burst of edits is answered once, for the latest content. A GitHub user who starts more than 10 answers an hour, or 40 a day, on one repository (new issues, discussions, edits and follow-up mentions counted together, with the same limits as pull request commands) is paused there and accepted again within 24 hours. An edit that only replaces an answer that has not started yet is not counted again. The repository owner and authors GitHub reports as the owner, an organization member or a collaborator are not limited. When the connected account runs out of tokens, Gitdog posts at most one notice a day per repository saying so.

PR reviews are opt-in per repository. Enable Pull request reviews and retain Approve before posting to inspect proposals in Tickets. The GitHub App requires the Pull requests permission and event above on both dev and production; existing installations must accept the expanded permission. Reviews inspect immutable head/merge-base source and never execute pull-request code.

Every changed file's head source is read. When a single review cannot hold them all, the rest are reviewed in coverage passes of their own, implementation files first; a batched review covers files through its groups instead. Passes stop at the account's token limit, at a provider error, or four minutes into the review, and the files left, or any whose candidate could not be validated, are reported as not fully reviewed. A candidate is dropped in verification only when the verifier quotes source that refutes it. e2e/recall/cases.json lists past commits with the issues other reviewers found there; bun run test:e2e:recall replays the reviewer on them.

Gitdog reviews a pull request once, when it is opened or marked ready for review. When pull request reviews are turned on (web, CLI or project key), or a repository with them on is reactivated, reconnected or regains GitHub access, up to five open pull requests updated in the last 30 days that were never reviewed get their first review, 12 minutes apart. Drafts and bot pull requests are skipped, it runs at most once an hour per repository, and nothing is scheduled when the account has no tokens and no usable key of its own. Later reviews run when the author or a collaborator comments @<app-slug> review (changes since the last review) or @<app-slug> full review; @<app-slug> resolve resolves Gitdog's threads and @<app-slug> help lists the commands; gitdog reviews request|resolve runs the same from the CLI. A command is a comment line that starts with the mention, or follows another review bot's command on the same line; in production, @gitdogbot (the app's former name), @gitdogdev and the @gitdog shorthand also work, for commands and for issue and discussion mentions. The pull request author can run review and help; a full review and resolve need a collaborator. These arrive through the Issue comments event. A commenter who sends more than 10 commands an hour or 40 a day to one repository is paused there for 24 hours. A review keeps one status comment while it runs and removes it once the review is posted. Each single review also reads the pull request conversation (comments, review summaries and open threads, at most 8,000 characters, without Gitdog's own posts) and lists a reviewer's request the code does not make yet; such a request, an open thread from anyone or a reviewer's standing request for changes keeps a clean review from approving. Only a pull request whose author has write access to the repository is approved, checked with GitHub before the review is posted; a clean review of anyone else's is posted as a comment. When a review cannot finish, for example because the account ran out of tokens, its status comment says why; for automatic reviews Gitdog posts at most one such comment a day per pull request.

6. Installation Settings

Where can this GitHub App be installed?

  • ✅ Any account (IMPORTANT: This allows users to install on multiple organizations)

7. Create GitHub App

Click Create GitHub App button

After Creation

  1. Note your App ID
  2. Note your Client ID
  3. Generate a Client secret
  4. Generate a private key (downloads a .pem file)

Setting Up Environment Variables

Convert Private Key to PKCS#8 Format

The downloaded private key is in PKCS#1 format. Convert it to PKCS#8:

openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt \
  -in your-app.private-key.pem \
  -out your-app.pkcs8.pem

Set Convex Environment Variables

bunx convex env set GITHUB_APP_SLUG gitdogbot-dev
bunx convex env set GITHUB_APP_ID "your_app_id"
bunx convex env set GITHUB_APP_CLIENT_ID "your_client_id"

# Prefer the Convex Dashboard for secrets. If using the CLI, read each secret
# from a permission-restricted file so it is not stored in shell history.
bunx convex env set GITHUB_APP_CLIENT_SECRET < github-app-client-secret.txt
bunx convex env set GITHUB_WEBHOOK_SECRET < github-webhook-secret.txt
bunx convex env set GITHUB_APP_PRIVATE_KEY < your-app.pkcs8.pem

Set the Frontend GitHub App Slug

Set the slug from the GitHub App URL (github.com/apps/<slug>) as a Vite build-time variable. It must contain only lowercase letters, numbers, and hyphens:

# .env.local
VITE_GITHUB_APP_SLUG=gitdogbot-dev

Set the matching Convex environment variable for each backend deployment:

# Production Convex deployment
bunx convex env set GITHUB_APP_SLUG gitdogai --prod

The backend fails closed for mentions and bot-authorship checks when this value is missing or invalid. Never configure both bot slugs in one deployment.

GitHub Actions preview builds use the repository variable VITE_CONVEX_DEV_URL (a variable, not a secret: the URL ships in the preview bundle). The preview workflow maps it to VITE_CONVEX_URL and pins VITE_GITHUB_APP_SLUG=gitdogbot-dev, so testing a pull request cannot authenticate against or mutate the production Convex deployment. The job that builds the pull request receives no secrets; only the publish job, which never runs pull request code, receives the Firebase service account. Keep the production VITE_CONVEX_URL secret reserved for the main-branch deployment.

When the frontend VITE_GITHUB_APP_SLUG variable is omitted, Gitdog defaults to gitdogbot-dev in development and gitdogai in production. The backend variable has no fallback and must match the frontend deployment exactly.

Verify Environment Variables

Open Convex Dashboard → Settings → Environment Variables and confirm that these variable names are present. Do not paste their values into logs, issues, or support messages. Avoid convex env list for this check because it prints secret values.

  • GITHUB_APP_SLUG
  • GITHUB_APP_ID
  • GITHUB_APP_CLIENT_ID
  • GITHUB_APP_CLIENT_SECRET
  • GITHUB_APP_PRIVATE_KEY
  • GITHUB_WEBHOOK_SECRET

How It Works

User Flow

  1. User logs in with GitHub App (authentication)
  2. User navigates to /repositories/connect
  3. User clicks "Install GitHub App" (if not already installed)
  4. User is redirected to GitHub installation page
  5. User selects account (personal or organization)
  6. User selects repositories to grant access
  7. After installation, GitHub redirects to /repositories/connect?installation_id=XXXXX
  8. GitHub's signed installation webhook binds the installation to the webhook sender's verified OAuth account
  9. User can now see all accessible repositories (including private and org repos)

Multiple Installations

Users can install the app on:

  • Their personal account
  • Organization A
  • Organization B
  • Any other organizations they have access to

Each installation is separate with its own installation ID. All installations can be managed at https://github.com/settings/installations

An organization installation stays bound to the GitHub account that installed it. Once a day Gitdog asks GitHub whether that account can still write to a repository of the installation (its collaborator permission, read with the Metadata permission). When two checks at least an hour apart say it cannot, the installation is paused like a suspended one: nothing is deleted, and it resumes by itself once the account can write again. A failed or rate-limited request never pauses an installation. An app with the optional Members permission and the Organization and Member events also runs this check as soon as that account's organization membership changes.

Do not connect the same repository to both gitdogai and gitdogbot-dev. The placeholder gitdogbot app only holds the production app's former name; it has no webhook or permissions and is never installed. Mentions are isolated by GITHUB_APP_SLUG, but GitHub sends automatic issue, discussion, repository, and push events to every App installed on that repository. Use a dedicated test repository for the development App.

Production Setup

For production deployment:

  1. Update GitHub App settings:

    • Homepage URL: https://gitdog.dev
    • Callback URLs: the concrete production ${CONVEX_SITE_URL}/oauth/github/callback, and ${CUSTOM_AUTH_SITE_URL ?? CONVEX_SITE_URL}/github/access/callback using the production custom auth site URL when configured
    • Setup URL: https://gitdog.dev/repositories/connect
    • Redirect on update: ✅ Checked
    • Webhook URL: https://your-production.convex.site/github/webhook
  2. Update Convex environment variables for production deployment:

    bunx convex env set GITHUB_APP_SLUG gitdogai --prod
    bunx convex env set GITHUB_APP_ID "your_app_id" --prod
    bunx convex env set GITHUB_APP_CLIENT_ID "your_client_id" --prod
    bunx convex env set GITHUB_APP_CLIENT_SECRET --prod < github-app-client-secret.txt
    bunx convex env set GITHUB_WEBHOOK_SECRET --prod < github-webhook-secret.txt
    bunx convex env set GITHUB_APP_PRIVATE_KEY --prod < your-app.pkcs8.pem

Troubleshooting

Installation not being saved

  • Check webhook is active in GitHub App settings
  • Verify webhook URL is correct
  • Check Convex logs for webhook events: bunx convex logs
  • Verify the user is signed in with the same GitHub account that installed the app

Private key error

  • Ensure private key is converted to PKCS#8 format
  • Confirm GITHUB_APP_PRIVATE_KEY is present in the Convex Dashboard without revealing its value. If its contents are uncertain, convert the downloaded key again and overwrite the variable from the file.
  • Key should start with -----BEGIN PRIVATE KEY----- (not BEGIN RSA PRIVATE KEY)

Repositories not showing

  • Verify the installation is saved: gitdog github installations lists the installations bound to your account
  • Check user has installed the app: https://github.com/settings/installations
  • Verify app has permission to access repositories

Architecture

User Login Flow:
GitHub OAuth → convex/auth.ts (@convex-dev/auth 2.0) → User session created

Repository Access Flow:
Verify GitHub access (`/github/access/callback`) → Short-lived `/user/installations` attestation → Recover personal installations
Organization installation/update → Signed webhook → Save installation
Setup callback → Coordinate verification and repository reconnect UI
User requests repos → convex/github/action.ts → Generate JWT → Get installation token → Fetch repos