add support for commands on Github PRs#2
Conversation
There was a problem hiding this comment.
The implementation of GitHub PR commands is well-structured and adds valuable functionality. I've suggested a few improvements to enhance error handling, logging, and code organization. These changes will make the code more maintainable and robust.
| * Processes AI analysis output by handling code suggestion blocks properly | ||
| * @param analysis The raw analysis string from the AI | ||
| * @returns Parsed content with code blocks properly restored | ||
| */ |
There was a problem hiding this comment.
| */ | |
| * Processes AI analysis output by handling code suggestion blocks properly | |
| * @param analysis The raw analysis string from the AI | |
| * @returns Parsed content with code blocks properly restored | |
| */ | |
| const processAnalysisOutput = (analysis: string): any => { |
| try { | ||
| await addCommentToPullRequest( | ||
| githubToken, | ||
| owner, |
There was a problem hiding this comment.
| owner, | |
| } catch (error) { | |
| console.error("Error during PR review:", error); | |
| try { |
|
|
||
| const syncUpdatedEventAndStoreInDb = async (event: any, githubPayload: any) => { | ||
|
|
||
| const installationId: number = githubPayload?.installation?.id |
There was a problem hiding this comment.
| const installationId: number = githubPayload?.installation?.id | |
| } catch (error) { | |
| console.error("Error generating PR summary:", error); | |
| // Notify about the error |
| } | ||
| } | ||
|
|
||
| if (eventType === 'issue_comment') { |
There was a problem hiding this comment.
| if (eventType === 'issue_comment') { | |
| if (eventType === 'issue_comment') { | |
| const action = eventPayload.action | |
| const issue = eventPayload.issue | |
| const comment = eventPayload.comment | |
| const repo = eventPayload.repository.name | |
| // Only process newly created comments | |
| if (action === 'created') { |
| const comment = eventPayload.comment | ||
| const repo = eventPayload.repository.name | ||
|
|
||
| if (action === 'created') { |
There was a problem hiding this comment.
| if (action === 'created') { | |
| // Check for app mentions in the comment | |
| const commentBody = comment.body.toLowerCase(); | |
| const isMentioned = commentBody.includes('/ai'); | |
| const hasReviewCommand = commentBody.includes('review'); | |
| const hasSummaryCommand = commentBody.includes('summary'); |
| if (issue.pull_request) { | ||
| // Check for app mentions in the comment | ||
| const isMentioned = comment.body.includes('/ai'); | ||
| const hasReviewCommand = comment.body.includes('review'); |
There was a problem hiding this comment.
| const hasReviewCommand = comment.body.includes('review'); | |
| if (isMentioned) { | |
| console.log(`Processing command in PR #${issue.number}: ${comment.body}`); | |
| if (hasReviewCommand) { |
| }); | ||
|
|
||
| const response = await octokit.issues.createComment({ | ||
| owner, |
There was a problem hiding this comment.
Good implementation of the comment addition function with proper error handling.
| } | ||
| }; | ||
|
|
||
| const filterPRFiles = (files: any[]) => { |
There was a problem hiding this comment.
Nice utility function for filtering PR files. This helps maintain consistency across the codebase by centralizing this logic.
| // Call the dedicated function to handle the review request | ||
| await handleReviewRequest( | ||
| githubToken, | ||
| owner, |
There was a problem hiding this comment.
The command parsing logic is simple but effective. In the future, you might want to consider a more structured approach if more commands are added.
|
/matter summary |
|
I'm generating a summary for this PR. I'll post it shortly. |
PR Summary: Add Support for Commands on GitHub PRs🔄 What Changed
🔍 Impact of the Change
📁 Total Files Changed
🧪 Test Added
|
Description
Type of Change
How Has This Been Tested?
Screenshots (if applicable)
Checklist
Related Issues