Skip to content

Commit

Permalink
bug: duplicates (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Sep 16, 2023
1 parent 31ae1fe commit 3b67c67
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
32 changes: 21 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

35 changes: 23 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,35 @@ async function action(): Promise<void> {
pull_number: context.payload.number
})

// Note: Any of these checks can work
// body.includes(markdown)
// body.endsWith(markdown)
// body.match(new RegExp(markdown))
// !~body.indexOf(markdown)
// !~body.search(markdown)

// Exit/return if our markdown message is already present
let body = pullRequest.body || ''
if (body.includes(markdown)) {
const body = pullRequest.body || ''
if (body.endsWith(markdown)) {
info('Markdown message is already present. Exiting.')
return
}

// There have been issues with duplicate messages, so remove those
body = body.split(markdown)[0]

// If we're here update the body
info('Description is being updated.')
await octokit.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.number,
body: body.concat(`\n\n${markdown}`)
})
if (!body.endsWith(markdown)) {
info('Description is being updated.')
await octokit.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.number,
// Split out any duplicate messages, has been an issue
body: body.split(markdown)[0].concat(`\n\n${markdown}`)
})
return
}

// If here, something went wrong ...which seems to happen a lot
error('Unexpected result. Please verify the action has performed correctly.')
}

// Run main function
Expand Down

0 comments on commit 3b67c67

Please sign in to comment.