Skip to content

Commit

Permalink
utils.js: reorder mermaid inside Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Nov 20, 2024
1 parent e1f55d3 commit 1fe878f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Desired format:
\n`

const re = /(### Changes[\s\S]*?\n)###\s/g
const mermaidRe = /```mermaid\n[\s\S]*?```/g

export async function explainPatchHelper (patchBody, owner, repo, models, debug, getResponse) {
models = Array.isArray(models) ? models : models.split(' ')
Expand Down Expand Up @@ -53,12 +54,20 @@ export async function explainPatchHelper (patchBody, owner, repo, models, debug,
}
}

const diagrams = []
// put diagrams inside Changes section
for (const match of response.matchAll(mermaidRe)) {
const diagram = match[0]
response = response.replace(diagram, '')
diagrams.push(diagram)
}

response = response.replaceAll('### Changes', '<details>\n<summary><i>Changes</i></summary>\n\n### Changes')

if (re.test(response)) {
response = response.replaceAll(/(### Changes[\s\S]*?\n)###\s/g, '$1\n</details>\n\n### ')
response = response.replaceAll(/(### Changes[\s\S]*?\n)###\s/g, `$1${diagrams.join('\n')}\n</details>\n\n### `)
} else {
response += '\n</details>'
response += `${diagrams.join('\n')}\n</details>`
}
response += `\n\n<!-- Generated by ${model} -->`
return response
Expand Down

0 comments on commit 1fe878f

Please sign in to comment.