GitHub API Integration
Relevant source files
The following files were used as context for generating this wiki page:
The GitHub API integration serves as the backbone of the GeNCorE Command Center, enabling seamless interaction between the web interface and GitHub repositories. The system acts as a proxy, abstracting complex GitHub REST API v3 calls into simplified internal endpoints for managing AI agents (Copilot, Claude, and Codex).
The integration primarily focuses on three areas: task assignment through GitHub Issues, Pull Request management (listing, reviewing, and merging), and automated agent identification based on repository metadata. All communications with GitHub are performed server-side to ensure the security of the GITHUB_TOKEN.
Sources: README.md:1-15, app/api/prs/route.ts:1-10
Core Configuration and Security
The integration relies on environment variables to define the target repository and authenticate requests. Security is maintained by keeping the GITHUB_TOKEN exclusively on the server side, preventing exposure to the client-side browser.
| Variable | Description | Source |
|---|---|---|
GITHUB_TOKEN | Personal Access Token with repo scope | README.md:46 |
NEXT_PUBLIC_REPO_OWNER | Owner of the target GitHub repository | README.md:55 |
NEXT_PUBLIC_REPO_NAME | Name of the target GitHub repository | README.md:56 |
All API routes implement a validation check for the GITHUB_TOKEN and input parameters. For instance, prNumber is validated as a safe positive integer (up to 2,147,483,647) to prevent Server-Side Request Forgery (SSRF) attacks.
Sources: app/api/merge/route.ts:7-35, README.md:78-83
Architecture and Data Flow
The system follows a modular architecture where the Next.js App Router handles incoming client requests and translates them into GitHub API calls using the fetch API.
Pull Request Management Flow
This diagram illustrates how the application fetches and processes open Pull Requests from GitHub.
The application specifically targets open pull requests, retrieving up to 20 items per request without caching to ensure data freshness.
Sources: app/api/prs/route.ts:15-40, app/page.tsx:21-35
Task Creation (GitHub Issues)
The /task feature allows users to delegate work to AI agents by creating GitHub Issues. The system automatically formats the issue body, assigns labels, and designates the specific agent as the assignee.
Task Logic
- Endpoint:
/api/task(POST) - Data Structure:
agent: The ID of the targeted AI agent (copilot, claude, codex).description: The task details provided by the user.
Pull Request Review and Merging
The integration provides granular control over the Pull Request lifecycle through dedicated endpoints for reviewing (approving/requesting changes) and merging code.
Merge Operations
The /api/merge endpoint supports different merge strategies. By default, the system utilizes the squash method.
- Supported Methods:
merge,squash,rebase. - Validation: Ensures the
prNumberis valid and the method is within the allowed list.
Sources: app/api/merge/route.ts:28-45
Review Operations
The /api/review endpoint manages PR feedback. It requires a comment body for REQUEST_CHANGES or COMMENT events, while APPROVE can be sent without a body.
| Event | Required Fields | GitHub API Path |
|---|---|---|
APPROVE | prNumber | /pulls/:num/reviews |
REQUEST_CHANGES | prNumber, body | /pulls/:num/reviews |
COMMENT | prNumber, body | /pulls/:num/reviews |
Sources: app/api/review/route.ts:12-45
Agent Detection Logic
The system includes a utility to identify which AI agent is responsible for a Pull Request by analyzing the branch name (head.ref) or the author's GitHub login.
// Path: lib/agents.ts
export function detectAgentFromPR(headRef: string, authorLogin: string): AgentConfig | null {
const branch = headRef.toLowerCase();
const author = authorLogin.toLowerCase();
if (branch.includes('copilot') || author.includes('copilot')) return AGENTS_BY_ID.copilot;
if (branch.includes('claude') || author.includes('claude')) return AGENTS_BY_ID.claude;
if (branch.includes('codex') || author.includes('codex')) return AGENTS_BY_ID.codex;
return null;
}
Sources: lib/agents.ts:89-115
Summary
The GitHub API Integration provides a secure, server-side interface for the GeNCorE Command Center to manage repository workflows. By leveraging the GitHub REST API v3, it enables automated tasking via Issues and centralized Pull Request management, while abstracting the underlying complexity and security requirements (like token management and input sanitization) away from the user interface.