Skip to content

add support for commands on Github PRs#2

Merged
code-crusher merged 2 commits intomainfrom
feat-pr-cmd-support
Feb 26, 2025
Merged

add support for commands on Github PRs#2
code-crusher merged 2 commits intomainfrom
feat-pr-cmd-support

Conversation

@code-crusher
Copy link
Member

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)

How Has This Been Tested?

  • Unit Tests
  • Integration Tests
  • Manual Testing

Screenshots (if applicable)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Related Issues

Copy link
Contributor

@matter-ai-bot matter-ai-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*/
* 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
owner,
} catch (error) {
console.error("Error during PR review:", error);
try {


const syncUpdatedEventAndStoreInDb = async (event: any, githubPayload: any) => {

const installationId: number = githubPayload?.installation?.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const installationId: number = githubPayload?.installation?.id
} catch (error) {
console.error("Error generating PR summary:", error);
// Notify about the error

}
}

if (eventType === 'issue_comment') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good implementation of the comment addition function with proper error handling.

}
};

const filterPRFiles = (files: any[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@code-crusher
Copy link
Member Author

/matter summary

@matter-ai-bot
Copy link
Contributor

matter-ai-bot bot commented Feb 26, 2025

I'm generating a summary for this PR. I'll post it shortly.

@matter-ai-bot
Copy link
Contributor

matter-ai-bot bot commented Feb 26, 2025

PR Summary: Add Support for Commands on GitHub PRs

🔄 What Changed

  • Added functionality to support commands in GitHub PR comments
  • Implemented two main commands: /ai review and /ai summary
  • Created dedicated handler functions for review and summary requests
  • Added utility functions for processing AI analysis output and filtering PR files
  • Improved handling of code suggestion blocks in PR reviews

🔍 Impact of the Change

  • Users can now request AI reviews and summaries directly through PR comments
  • Enhanced user experience with immediate feedback when commands are issued
  • Better handling of code suggestion blocks in the review process
  • More modular code structure with dedicated functions for different operations

📁 Total Files Changed

  • 1 file modified (src/integrations/github.ts)
  • 328 lines added, 27 lines deleted

🧪 Test Added

  • No explicit tests mentioned in the PR description

@code-crusher code-crusher merged commit 303263d into main Feb 26, 2025
1 check passed
@code-crusher code-crusher deleted the feat-pr-cmd-support branch February 26, 2025 09:33
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