Skip to content

Fix GitHub App configuration detection and dynamic installation ID lookup - #119

Closed
ishaileshpant wants to merge 1 commit into
mainfrom
fix/github-app-configuration-detection
Closed

ishaileshpant wants to merge 1 commit into
mainfrom
fix/github-app-configuration-detection

Conversation

@ishaileshpant

Copy link
Copy Markdown
Collaborator

🔧 Fix GitHub App Configuration Detection

Problem

The bot API was failing with "FUNCTION_INVOCATION_FAILED" error because it required GITHUB_APP_INSTALLATION_ID as an environment variable, but the GitHub App is installed and configured in Vercel.

Root Cause

The bot API was checking for GITHUB_APP_INSTALLATION_ID as a required environment variable, but GitHub Apps can dynamically find their installation ID using the GitHub API.

Solution

  • Removed requirement for GITHUB_APP_INSTALLATION_ID environment variable
  • Added dynamic installation ID lookup for prepguides organization
  • Improved GitHub App initialization with better error handling
  • Maintains backward compatibility with explicit installation ID if provided

Technical Changes

// Before - required GITHUB_APP_INSTALLATION_ID env var
if (!process.env.GITHUB_APP_ID || !process.env.GITHUB_APP_PRIVATE_KEY || !process.env.GITHUB_APP_INSTALLATION_ID) {
    return res.status(503).json({ error: 'GitHub App not configured' });
}

// After - dynamically finds installation ID
if (!process.env.GITHUB_APP_ID || !process.env.GITHUB_APP_PRIVATE_KEY) {
    return res.status(503).json({ error: 'GitHub App not configured' });
}

// Dynamic installation ID lookup
const installations = await tempOctokit.apps.listInstallations();
const targetInstallation = installations.data.find(installation => 
    installation.account.login === 'prepguides'
);

How It Works

  1. Creates app auth with just App ID and Private Key
  2. Gets app token to access GitHub API
  3. Lists installations to find the prepguides organization
  4. Uses found installation ID to create authenticated Octokit instance
  5. Creates PRs directly on origin repository using bot account

Files Changed

  • api/github/create-content-pr.js - Fixed GitHub App configuration detection and initialization

Impact

  • 🎯 Resolves FUNCTION_INVOCATION_FAILED error
  • 🚀 Enables bot API to work with existing GitHub App configuration
  • 🛡️ Uses bot account to create PRs directly on origin repository
  • 🔄 Maintains backward compatibility with explicit installation ID

Testing

  • GitHub App configuration detection now works properly
  • Dynamic installation ID lookup implemented
  • Bot API can create PRs using bot account
  • No linting errors

…okup

- Remove requirement for GITHUB_APP_INSTALLATION_ID environment variable
- Add dynamic installation ID lookup for prepguides organization
- Improve GitHub App initialization with better error handling
- Resolves FUNCTION_INVOCATION_FAILED error by properly detecting GitHub App

The bot API was failing because it required GITHUB_APP_INSTALLATION_ID as an
environment variable, but GitHub Apps can dynamically find their installation
ID. This fix allows the bot to work with just GITHUB_APP_ID and
GITHUB_APP_PRIVATE_KEY, then automatically finds the installation ID for
the prepguides organization.

Changes:
1. Removed GITHUB_APP_INSTALLATION_ID requirement from env check
2. Added dynamic installation ID lookup using GitHub API
3. Improved error handling and logging for GitHub App initialization
4. Maintains backward compatibility with explicit installation ID if provided
@vercel

vercel Bot commented Oct 8, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
prepguides-dev Ready Ready Preview Comment Oct 8, 2025 6:52pm

@ishaileshpant

Copy link
Copy Markdown
Collaborator Author

Closing this PR as it's no longer needed. PR #118 was merged which includes the fallback mechanism, making this GitHub App configuration fix unnecessary.

@ishaileshpant
ishaileshpant deleted the fix/github-app-configuration-detection branch October 13, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant