Skip to content

Add fallback mechanism for bot API when GitHub App is not configured - #118

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/bot-api-function-invocation-failed-error
Oct 8, 2025
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/bot-api-function-invocation-failed-error

Conversation

@ishaileshpant

Copy link
Copy Markdown
Collaborator

🔧 Fix Bot API Function Invocation Failed Error

Problem

The bot API was failing with "FUNCTION_INVOCATION_FAILED" error because it requires GitHub App configuration (GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY, GITHUB_APP_INSTALLATION_ID) that is not set up in the environment.

Root Cause

The bot API was designed to use GitHub App authentication, but the GitHub App is not configured in the deployment environment. This caused the serverless function to fail when trying to initialize the GitHub App.

Solution

  • Added fallback mechanism when GitHub App is not configured
  • Uses user token directly to create PR via fork instead of bot API
  • Maintains same API interface and response format
  • Provides graceful degradation for content submission functionality

Technical Changes

// Before - would fail if GitHub App not configured
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 - provides fallback when GitHub App not configured
const isGitHubAppConfigured = process.env.GITHUB_APP_ID && process.env.GITHUB_APP_PRIVATE_KEY && process.env.GITHUB_APP_INSTALLATION_ID;

if (!isGitHubAppConfigured) {
    return await handleFallbackSubmission(req, res, contentData, userToken);
}

Fallback Method

The fallback method:

  1. Verifies user authentication using their GitHub token
  2. Checks for user fork of the repository
  3. Creates branch in the user's fork
  4. Creates content payload file in the branch
  5. Creates pull request from fork to main repository

Files Changed

  • api/github/create-content-pr.js - Added fallback mechanism and handleFallbackSubmission function

Impact

  • 🎯 Resolves FUNCTION_INVOCATION_FAILED error
  • 🚀 Enables content submission without GitHub App configuration
  • 🛡️ Provides graceful degradation for missing configuration
  • 🔄 Maintains backward compatibility with existing API

Testing

  • Fallback method works when GitHub App is not configured
  • Bot API still works when GitHub App is configured
  • Same API interface and response format maintained
  • No linting errors

- Implement fallback submission handler when GitHub App env vars are missing
- Use user token directly to create PR via fork instead of bot API
- Resolves FUNCTION_INVOCATION_FAILED error when GitHub App is not set up
- Provides graceful degradation for content submission functionality

The bot API was failing because it requires GitHub App configuration
(GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY, GITHUB_APP_INSTALLATION_ID) which
is not set up. This fallback allows content submission to work using
the traditional fork-based approach when the bot API is not available.

Changes:
1. Added isGitHubAppConfigured check
2. Implemented handleFallbackSubmission function
3. Uses user token to create PR via fork
4. Maintains same API interface and response format
@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:49pm

@ishaileshpant

Copy link
Copy Markdown
Collaborator Author

/approve

@github-actions
github-actions Bot merged commit 5c4fc05 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**: `5c4fc05a28ca6a013da7824eec3bf8a711d4b83a`
📅 **Merged at**: 2025-10-08T18:53:22.755Z
👤 **Approved by**: Admin/Maintainer/Owner

Thank you for your contribution! 🎉

@ishaileshpant
ishaileshpant deleted the fix/bot-api-function-invocation-failed-error 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