Skip to content

Fix GitHub App detection logic to use bot API instead of fallback - #120

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/github-app-detection-logic
Oct 8, 2025
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/github-app-detection-logic

Conversation

@ishaileshpant

Copy link
Copy Markdown
Collaborator

🔧 Fix GitHub App Detection Logic

Problem

The bot API was still failing with "FUNCTION_INVOCATION_FAILED" error because it was incorrectly falling back to the user token method instead of using the configured GitHub App.

Root Cause

The code was still checking for GITHUB_APP_INSTALLATION_ID as a required environment variable, causing it to fall back to the user token method instead of using the GitHub App that's already configured in Vercel.

Solution

  • Removed GITHUB_APP_INSTALLATION_ID requirement from configuration check
  • Added dynamic installation ID lookup for prepguides organization
  • Ensures bot API uses GitHub App instead of falling back to user token method
  • Proper GitHub App initialization with dynamic installation discovery

Technical Changes

// Before - required GITHUB_APP_INSTALLATION_ID causing fallback
const isGitHubAppConfigured = process.env.GITHUB_APP_ID && process.env.GITHUB_APP_PRIVATE_KEY && process.env.GITHUB_APP_INSTALLATION_ID;

// After - only requires App ID and Private Key
const isGitHubAppConfigured = process.env.GITHUB_APP_ID && process.env.GITHUB_APP_PRIVATE_KEY;

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

How It Works

  1. Checks for App ID and Private Key (which are configured in Vercel)
  2. Creates app auth to get app token
  3. Lists installations to find 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 detection and initialization logic

Impact

  • 🎯 Resolves FUNCTION_INVOCATION_FAILED error
  • 🚀 Uses GitHub App instead of falling back to user token method
  • 🛡️ Creates PRs directly on origin repository using bot account
  • 🔄 Maintains backward compatibility with explicit installation ID

Testing

  • GitHub App detection now works with existing Vercel configuration
  • Dynamic installation ID lookup implemented
  • Bot API uses GitHub App instead of fallback method
  • No linting errors

- Remove GITHUB_APP_INSTALLATION_ID requirement from configuration check
- Add dynamic installation ID lookup for prepguides organization
- Ensure bot API uses GitHub App instead of falling back to user token method
- Resolves FUNCTION_INVOCATION_FAILED by properly detecting GitHub App configuration

The issue was that the code was still checking for GITHUB_APP_INSTALLATION_ID
as a required environment variable, causing it to fall back to the user token
method instead of using the configured GitHub App. This fix allows the bot
to work with just GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY, then dynamically
finds the installation ID for the prepguides organization.
@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:58pm

@ishaileshpant

Copy link
Copy Markdown
Collaborator Author

/approve

@github-actions
github-actions Bot merged commit 2b1d36c into main Oct 8, 2025
11 checks passed
@github-actions

github-actions Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

🚀 Admin-Approved and Auto-Merged!

This PR has been automatically merged to main after admin approval by @ishaileshpant.

✅ **Status**: Merged and deployed
🔗 **Commit**: `2b1d36c9f4d6058f9cd0ae1e171d26f6be7cd8f5`
📅 **Merged at**: 2025-10-08T19:00:54.779Z
👤 **Approved by**: Admin/Maintainer/Owner

Thank you for your contribution! 🎉

@ishaileshpant
ishaileshpant deleted the fix/github-app-detection-logic 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