From a0d7ab20fd90d8379f51de1e4c5ee58a04626a81 Mon Sep 17 00:00:00 2001 From: ben-wilson-peak <117664255+ben-wilson-peak@users.noreply.github.com> Date: Thu, 18 May 2023 02:53:32 +0100 Subject: [PATCH] fix: improve regex matching (#91) --- index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 733d3a9..40e30ba 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const regex = /\n\n/ +const regex = /(\n\n|\r\n)/ module.exports = (context, issue = null) => { const github = context.octokit || context.github @@ -17,7 +17,7 @@ module.exports = (context, issue = null) => { const match = body.match(regex) if (match) { - const data = JSON.parse(match[1])[prefix] + const data = JSON.parse(match[2])[prefix] return key ? data && data[key] : data } }, @@ -28,10 +28,13 @@ module.exports = (context, issue = null) => { if (!body) body = (await github.issues.get(issue)).data.body || '' - body = body.replace(regex, (_, json) => { - data = JSON.parse(json) - return '' - }) + const match = body.match(regex) + + if (match) { + data = JSON.parse(match[2]) + } + + body = body.replace(regex, '') if (!data[prefix]) data[prefix] = {}