sfcoe-ailabs
Version:
AI-powered code review tool with static analysis integration for comprehensive code quality assessment.
76 lines (75 loc) • 3.25 kB
TypeScript
import GitProvider from './gitProvider.js';
import { PullRequestComment } from './index.js';
export default class GitHub extends GitProvider {
/**
* Check if a comment was created by this bot using multiple identification methods
*
* Identification Methods (in order of priority):
* 1. Hidden HTML Comment: <!-- AI-PR-Review-Bot: sfcoe-ailabs --> (backward compatibility)
* 2. Visible Bot Header: Comments starting with "🤖 **AI Code Quality Review Bot**"
* 3. Footer Signature: "*Generated using the npm package sfcoe-ailabs"
*
* @param comment - GitHub comment object
* @returns true if comment was created by this bot
*/
private static isBotComment;
/**
* Create a PR comment using GitHub API
*
* @param url - The GitHub API URL for creating comments
* @param headers - HTTP headers including authorization
* @param prComment - The pull request comment data to post
* @param isGeneralComment - Whether this is a general comment (Issues API) or line-specific (Pull Requests API)
* @returns Promise that resolves when comment is created
* @throws Error if GitHub API request fails
*/
private static createComment;
/**
* Upserts a pull request comment to GitHub.
* This method handles both general comments and line-specific comments.
* It checks for existing bot comments and updates them if found, or creates a new comment if not.
*
* @param prComment - The pull request comment data to post
*/
upsertPRComment(prComment: PullRequestComment): Promise<void>;
/**
* Delete an existing bot comment from the PR
*
* @param prNumber - Pull request number
* @param isGeneralComment - Whether to look for general or line-specific comments
* @returns Promise that resolves when comment is deleted, or null if no comment found
*/
deleteBotComment(prNumber: string, isGeneralComment?: boolean): Promise<void>;
/**
* Get the appropriate GitHub API URL for PR comments
*
* @param prNumber - Pull request number
* @param isGeneralComment - Whether this is a general comment (issues API) or line-specific (pulls API)
* @param commentId - Optional comment ID for update operations
* @returns The GitHub API URL for the comment operation
*/
private getCommentUrl;
/**
* Get the standard headers for GitHub API requests
*
* @returns Headers object with authorization and API version
*/
private getApiHeaders;
/**
* Find existing bot comment in the PR using multiple identification methods
*
* @param prNumber - Pull request number
* @param isGeneralComment - Whether to look for general or line-specific comments
* @returns Promise that resolves to the comment ID if found, null otherwise
*/
private findExistingBotComment;
/**
* Update an existing comment
*
* @param commentId - The ID of the comment to update
* @param body - The new comment body
* @param isGeneralComment - Whether this is a general or line-specific comment
* @returns Promise that resolves when comment is updated
*/
private updateExistingComment;
}