Skip to content

Commit

Permalink
jenkins: improve logging related to creating comments on GitHub
Browse files Browse the repository at this point in the history
As the previous logging didn't provide enough details about what went
wrong; was it fetching info about existing comments, while editing
or creating comment?
  • Loading branch information
phillipj committed Jun 11, 2019
1 parent 1cbae04 commit 98f7322
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/github-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,22 @@ exports.getFirstBotComment = function getFirstBotComment ({ owner, repo, number
}

exports.createPrComment = function createPrComment ({ owner, repo, number, logger }, body) {
exports.getFirstBotComment({ owner, repo, number, logger }).then((comment) => {
if (comment) {
const { id: nodeId, body: oldBody } = comment
exports.getFirstBotComment({ owner, repo, number, logger }).then((existingComment) => {
if (existingComment) {
const { id: nodeId, body: oldBody } = existingComment
const newBody = `${oldBody}\n${body}`
const id = graphQlIdToRestId(nodeId)
return githubClient.issues.editComment({ owner, repo, id, body: newBody })
const updatedComment = { owner, repo, id, body: newBody }

return githubClient.issues.editComment(updatedComment).catch((err) => {
logger.error({ existingComment, updatedComment, err }, 'Error while editing existing comment on GitHub')
})
}
return githubClient.issues.createComment({ owner, repo, number, body })
}).catch((err) => {
logger.error(err, 'Error while creating comment on GitHub')
// swallow error

return githubClient.issues.createComment({ owner, repo, number, body }).catch((err) => {
logger.error(err, 'Error while creating comment on GitHub')
})
}, (err) => {
logger.error(err, 'Error while trying to fetch existing bot comment on GitHub')
})
}

0 comments on commit 98f7322

Please sign in to comment.