Skip to content

Commit

Permalink
action.cjs: include filtered diff in the watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Dec 17, 2024
1 parent e1da98e commit 4cfffb6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions action.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,14 @@ module.exports = async ({ github, context, inputs, actionPath }) => {
: `openai debug - ${watermark}`
}

const header = '<details><summary>Diff</summary>\n\n```\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,
Expand Down
3 changes: 2 additions & 1 deletion src/submitReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}) {
Expand Down Expand Up @@ -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
})
}
}
3 changes: 2 additions & 1 deletion src/subtleSubmitReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4cfffb6

Please sign in to comment.