Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Pull Request Comment Handling Infrastructure #13

Merged
merged 8 commits into from
Nov 21, 2024
Merged

Added Pull Request Comment Handling Infrastructure #13

merged 8 commits into from
Nov 21, 2024

Conversation

bstanga
Copy link
Contributor

@bstanga bstanga commented Nov 20, 2024

Add skeleton for handling comments

Copy link

github-actions bot commented Nov 20, 2024

PR Summary

Implemented infrastructure for handling and responding to pull request review comments. Added functionality to track comment threads, filter relevant comments, and generate AI-powered responses to review comments. The system now supports identifying comment threads, managing review comment context, and providing appropriate responses while maintaining the conversation flow.

Changes

File Summary
src/comments.ts Created new module for managing PR review comments with types ReviewComment and ReviewCommentThread. Implemented functions to list comment threads, check relevancy, and handle comment identification.
src/context.ts Updated context loading to handle comment-related data, including new fields for comment ID and comment payload information.
src/diff.ts Restructured diff handling to work with comment threads, moved comment types to comments.ts, and improved thread filtering for diff hunks.
src/main.ts Extended main event handler to support pull request review comment events by integrating handlePullRequestComment function.
src/messages.ts Added COMMENT_SIGNATURE constant for identifying presubmit.ai generated comments.
src/prompts.ts Implemented new prompt system for generating responses to review comments, including comment thread context and AI response formatting.
src/pull_request.ts Modified PR handling to use new comment thread functionality and improved review comment integration.
src/pull_request_comment.ts Created new module to handle PR review comments, including comment relevancy checking, thread context loading, and response generation.
dist/index.js Generated distribution file from source changes.

autogenerated by presubmit.ai

@github-actions github-actions bot changed the title @presubmit Added Pull Request Comment Handling Infrastructure Nov 20, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
  • 7d7f1dd: add skeleton for handling comments
Files Processed (2)
  • src/main.ts (2 hunks)
  • src/messages.ts (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
  • src/main.ts [13-13]

    best practice: "Missing error handling for new function call"

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
Files Processed (1)
  • src/pull_request_comment.ts (1 hunk)
Actionable Comments (0)
Skipped Comments (2)
  • src/pull_request_comment.ts [9-12]

    best practice: "Event name validation could be more specific"

  • src/pull_request_comment.ts [35-37]

    possible issue: "Comment signature check might have false positives"

Comment on lines +14 to +30
const { comment, pull_request } = context.payload;
if (!comment) {
warning("`comment` is missing from payload");
return;
}
if (context.payload.action !== "created") {
warning("only consider newly created comments");
return;
}
if (!pull_request) {
warning("`pull_request` is missing from payload");
return;
}
if (isOwnComment(comment.body)) {
info("ignoring own comments");
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@presubmitai can we somehow improve this part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually nevermind. It's fine. No longer needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually you know what, you can actually help me. Can you replace warning statement with console.error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bstanga Sure! You'll need to update the import statement and replace all instances of warning() with console.error(). Here's what needs to be changed:

  1. Remove warning from the import statement on line 1
  2. Replace these lines:
warning("unsupported github event");
warning("`comment` is missing from payload");
warning("only consider newly created comments");
warning("`pull_request` is missing from payload");

with:

console.error("unsupported github event");
console.error("`comment` is missing from payload");
console.error("only consider newly created comments");
console.error("`pull_request` is missing from payload");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you show me how to code will look like after I replace those? So that I can simply copy paste?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bstanga Here's how the code will look after replacing warning with console.error:

import { info } from "@actions/core";
import { loadContext } from "./context";
import config from "./config";
import { initOctokit } from "./octokit";
import { COMMENT_SIGNATURE } from "./messages";

export async function handlePullRequestComment() {
  const context = await loadContext();
  if (context.eventName !== "pull_request_review_comment") {
    console.error("unsupported github event");
    return;
  }

  const { comment, pull_request } = context.payload;
  if (!comment) {
    console.error("`comment` is missing from payload");
    return;
  }
  if (context.payload.action !== "created") {
    console.error("only consider newly created comments");
    return;
  }
  if (!pull_request) {
    console.error("`pull_request` is missing from payload");
    return;
  }
  if (isOwnComment(comment.body)) {
    info("ignoring own comments");
    return;
  }

  // TODO: implement
}

function isOwnComment(comment: string): boolean {
  return comment.includes(COMMENT_SIGNATURE);
}

Note that I removed warning from the import statement since it's no longer needed, but kept info since it's still being used.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🚨 Pull request needs attention.

Review Summary

Commits Considered (2)
Files Processed (7)
  • dist/index.js (0 hunks)
  • src/comments.ts (1 hunk)
  • src/context.ts (2 hunks)
  • src/diff.ts (6 hunks)
  • src/prompts.ts (3 hunks)
  • src/pull_request.ts (4 hunks)
  • src/pull_request_comment.ts (1 hunk)
Actionable Comments (2)
  • src/comments.ts [36-42]

    possible bug: "Potential issue with user login mapping"

  • src/comments.ts [80-82]

    possible bug: "Potential issue with comment filtering"

Skipped Comments (1)
  • src/pull_request_comment.ts [78-85]

    best practice: "Missing error handling in API call"

src/comments.ts Show resolved Hide resolved
src/comments.ts Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

LGTM!

Review Summary

Commits Considered (1)
Files Processed (1)
  • src/comments.ts (1 hunk)
Actionable Comments (0)
Skipped Comments (3)
  • src/comments.ts [81-81]

    possible issue: "Potential issue with comment filtering logic"

  • src/comments.ts [67-74]

    enhancement: "Function marked as async but doesn't use any await operations"

  • src/comments.ts [71-73]

    enhancement: "Redundant mention checks in comment relevance"

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🚨 Pull request needs attention.

Review Summary

Commits Considered (2)
Files Processed (3)
  • dist/index.js (0 hunks)
  • src/comments.ts (1 hunk)
  • src/pull_request_comment.ts (1 hunk)
Actionable Comments (1)
  • src/pull_request_comment.ts [87-87]

    possible bug: "Potential runtime error due to undefined property"

Skipped Comments (2)
  • src/comments.ts [78-80]

    possible issue: "Potential issue with comment filtering logic"

  • src/pull_request_comment.ts [58-58]

    enhancement: "Inefficient array mapping with empty array parameter"

src/pull_request_comment.ts Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

🚨 Pull request needs attention.

Review Summary

Commits Considered (1)
Files Processed (1)
  • src/pull_request_comment.ts (1 hunk)
Actionable Comments (1)
  • src/pull_request_comment.ts [76-76]

    possible bug: "Potential undefined behavior in response handling"

Skipped Comments (2)
  • src/pull_request_comment.ts [58-58]

    performance: "Potential memory inefficiency in file diff processing"

  • src/pull_request_comment.ts [34-34]

    best practice: "Potential error handling improvement needed"

});

// Submit response if action requested
if (!response.action_requested || !response.response_comment.length) {

Choose a reason for hiding this comment

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

The condition !response.action_requested || !response.response_comment.length might throw if response_comment is undefined. Consider adding a null check: !response.action_requested || !response.response_comment?.length

@bstanga bstanga merged commit ba50bfd into main Nov 21, 2024
2 checks passed
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