From d1e0f30063b359ee7387262ed81ea14b0d584351 Mon Sep 17 00:00:00 2001 From: Andrea Brancaleoni Date: Tue, 14 May 2024 00:32:21 +0200 Subject: [PATCH] src/utils.js: overly complicated regex since claude cannot respect order --- src/utils.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index f629d52..fbfe67f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -15,6 +15,8 @@ Desired format: // Describe the main changes in the PR, organizing them by filename \n` +const re = /(### Changes[\s\S]*?\n)###\s/g + export async function explainPatchHelper (patchBody, owner, repo, models, debug, getResponse) { models = Array.isArray(models) ? models : models.split(' ') @@ -44,6 +46,12 @@ export async function explainPatchHelper (patchBody, owner, repo, models, debug, } response = response.replaceAll('### Changes', '
\nChanges\n\n### Changes') - response += `
\n\n` + + if (re.test(response)) { + response = response.replaceAll(/(### Changes[\s\S]*?\n)###\s/g, '$1\n\n### ') + } else { + response += '' + } + response += `\n\n` return response }