Skip to content

Commit

Permalink
fix: improve regex matching (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-wilson-peak authored May 18, 2023
1 parent f59878a commit a0d7ab2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const regex = /\n\n<!-- probot = (.*) -->/
const regex = /(\n\n|\r\n)<!-- probot = (.*) -->/

module.exports = (context, issue = null) => {
const github = context.octokit || context.github
Expand All @@ -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
}
},
Expand All @@ -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] = {}

Expand Down

0 comments on commit a0d7ab2

Please sign in to comment.