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

action.cjs: include filtered diff in the watermark #221

Merged
merged 3 commits into from
Dec 17, 2024

Conversation

thypon
Copy link
Member

@thypon thypon commented Dec 17, 2024

No description provided.

@brave brave deleted a comment from github-actions bot Dec 17, 2024
@thypon thypon force-pushed the features/filtered-patch-in-watermark branch from 6998aeb to cce9970 Compare December 17, 2024 10:53
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@thypon thypon force-pushed the features/filtered-patch-in-watermark branch from cce9970 to 4cfffb6 Compare December 17, 2024 11:27
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@thypon thypon force-pushed the features/filtered-patch-in-watermark branch from 4cfffb6 to 563bc16 Compare December 17, 2024 11:30
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@thypon thypon force-pushed the features/filtered-patch-in-watermark branch from 563bc16 to 752a7cf Compare December 17, 2024 11:31
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
Copy link

anthropic debug - [puLL-Merge] - brave/pull-merge@221

Diff
diff --git action.cjs action.cjs
index 4d88768..ca3271b 100644
--- action.cjs
+++ action.cjs
@@ -106,11 +106,14 @@ module.exports = async ({ github, context, inputs, actionPath }) => {
           : `openai debug - ${watermark}`
     }
 
+    const header = '<details><summary>Diff</summary>\n\n```diff\n\n' + filteredPatch + '\n\n```\n\n</details>'
+
     await submitReview({
       owner: options.owner,
       repo: options.repo,
       prnum: options.prnum,
       watermark,
+      header,
       explainPatch: explainPatchCb,
       debounceTime: options.debounce_time,
       debug,
diff --git src/submitReview.js src/submitReview.js
index 169bcbf..da46407 100644
--- src/submitReview.js
+++ src/submitReview.js
@@ -16,6 +16,7 @@ export default async function submitReview ({
   owner, repo, prnum, watermark, debounceTime,
   explainPatch = async () => 'no explanation provided<!-- Generated by STUB -->',
   githubToken = null,
+  header = '',
   github = null,
   debug = false
 }) {
@@ -81,7 +82,7 @@ export default async function submitReview ({
       owner,
       repo,
       issue_number: prnum,
-      body: watermark + '\n\n' + patchExplained
+      body: watermark + '\n\n' + header + '\n\n' + patchExplained
     })
   }
 }
diff --git src/subtleSubmitReview.js src/subtleSubmitReview.js
index 4bd0bc5..2912323 100644
--- src/subtleSubmitReview.js
+++ src/subtleSubmitReview.js
@@ -21,6 +21,7 @@ export default async function subtleSubmitReview ({
   explainPatch = async () => 'no explanation provided<!-- Generated by STUB -->',
   githubToken = null,
   github = null,
+  header = '',
   debug = false
 }) {
   if (!github && githubToken) {
@@ -63,7 +64,7 @@ export default async function subtleSubmitReview ({
   const end = escapeRegex('<!-- Generated by ') + '\\w+' + escapeRegex(' --></details>')
   const re = new RegExp(`${begin}.*${end}`, 's')
 
-  const newExplaination = '<details><summary>AI Review</summary>' + '\n\n' + watermark + '\n\n' + await explainPatch() + '</details>'
+  const newExplaination = '<details><summary>AI Review</summary>' + '\n\n' + watermark + '\n\n' + header + '\n\n' + await explainPatch() + '</details>'
 
   // fetch the message twice, to decrease the chances of race condition, but still debounce
   const msg = (await github.graphql(query, variables)).repository.pullRequest

Description

This PR enhances the pull request review process by adding a diff header to the review comments. It modifies the action.cjs, submitReview.js, and subtleSubmitReview.js files to include a collapsible diff section in the review comment, improving the context and readability of the AI-generated reviews.

Changes

Changes

  1. action.cjs:

    • Added a new header variable containing a collapsible diff section.
    • Passed the header to the submitReview function.
  2. src/submitReview.js:

    • Added a new header parameter with a default empty string.
    • Modified the review body to include the header between the watermark and the patch explanation.
  3. src/subtleSubmitReview.js:

    • Added a new header parameter with a default empty string.
    • Modified the newExplaination to include the header between the watermark and the patch explanation.

This sequence diagram illustrates the flow of the review process with the new header inclusion. The action creates the header, which is then passed to both submitReview and subtleSubmitReview functions. These functions incorporate the header into their respective review comments before submitting them to the GitHub API.```mermaid
sequenceDiagram
participant A as Action
participant SR as submitReview
participant SSR as subtleSubmitReview
participant G as GitHub API

A->>A: Create header with diff
A->>SR: Call submitReview with header
SR->>SR: Prepare review body
SR->>G: Submit review comment
A->>SSR: Call subtleSubmitReview with header
SSR->>SSR: Prepare new explanation
SSR->>G: Fetch existing comments
SSR->>SSR: Update or create comment
SSR->>G: Submit updated/new comment
</details>

<!-- Generated by claude-3-5-sonnet-20240620 -->

@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@thypon thypon force-pushed the features/filtered-patch-in-watermark branch from 444ca9a to f0cc5a8 Compare December 17, 2024 11:41
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
@brave brave deleted a comment from github-actions bot Dec 17, 2024
Copy link

openai debug - [puLL-Merge] - brave/pull-merge@221

Description

This Pull Request (PR) enhances the repository's action by introducing an option to include diffs in the review comments. The main motivation is to provide detailed information within the review, potentially improving code collaboration and review efficiency. The new include_diff input has been added, which, when set to true, will include the diff in the generated text.

Possible Issues

None identified.

Security Hotspots

None identified.

Changes

Changes

  • action.cjs
    • Added include_diff option to the configuration object.
    • Parsed include_diff and checked its boolean value.
    • Included the diff in the header if include_diff is set to true or if the actor's username ends with '[bot]'.
  • action.yml
    • Added a new include_diff input parameter.
  • src/submitReview.js
    • Added an optional header parameter to the submitReview function.
    • Included the header content in the body of the review comments.
  • src/subtleSubmitReview.js
    • Added an optional header parameter to the subtleSubmitReview function.
    • Included the header content in the body of the subtle review comments.
sequenceDiagram
    participant User
    participant GitHub
    participant Action
    participant ReviewFunction
    User->>GitHub: Create Pull Request or Push Changes
    GitHub->>Action: Trigger GitHub Action
    Action->>Action: Parse options, including include_diff
    Action->>ReviewFunction: Call submitReview with parsed options
    Action->>ReviewFunction: Call subtleSubmitReview with parsed options
    ReviewFunction->>Action: Generate Review Body with Diff if include_diff == true
    Action->>GitHub: Submit Review
    GitHub->>User: Display Review with optional Diff
Loading

Copy link

bedrock debug - [puLL-Merge] - brave/pull-merge@221

Description

This PR enhances the pull request review functionality by adding an option to include the diff in the generated text and making several related adjustments. The main motivation appears to be improving the visibility and context of the changes being reviewed.

Changes

Changes

  1. In action.cjs:

    • Added a new option include_diff to the configuration.
    • Modified the logic to include the diff in the header when include_diff is true or when the actor is a bot.
    • Updated the submitReview function call to pass the new header parameter.
  2. In action.yml:

    • Added a new input include_diff to allow users to specify whether to include the diff in the generated text.
  3. In src/submitReview.js:

    • Modified the submitReview function to accept a new header parameter.
    • Updated the body of the review comment to include the header before the patch explanation.
  4. In src/subtleSubmitReview.js:

    • Similar to submitReview.js, added a header parameter and included it in the new explanation.
sequenceDiagram
    participant User
    participant GitHub
    participant ActionRunner
    participant ReviewBot

    User->>GitHub: Create/Update Pull Request
    GitHub->>ActionRunner: Trigger Action
    ActionRunner->>ReviewBot: Run review process
    ReviewBot->>GitHub: Fetch PR details
    ReviewBot->>ReviewBot: Generate explanation
    alt include_diff is true or actor is bot
        ReviewBot->>ReviewBot: Include diff in header
    end
    ReviewBot->>GitHub: Submit review comment
    GitHub->>User: Display review comment
Loading

Possible Issues

  • The diff inclusion might make the review comments very long, potentially affecting readability for large PRs.

Security Hotspots

None identified.

@thypon thypon merged commit 44f7c5e into main Dec 17, 2024
6 of 7 checks passed
@thypon thypon deleted the features/filtered-patch-in-watermark branch December 17, 2024 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant