Skip to content

Commit 98f7322

Browse files
committed
jenkins: improve logging related to creating comments on GitHub
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?
1 parent 1cbae04 commit 98f7322

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

lib/github-comment.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,22 @@ exports.getFirstBotComment = function getFirstBotComment ({ owner, repo, number
4646
}
4747

4848
exports.createPrComment = function createPrComment ({ owner, repo, number, logger }, body) {
49-
exports.getFirstBotComment({ owner, repo, number, logger }).then((comment) => {
50-
if (comment) {
51-
const { id: nodeId, body: oldBody } = comment
49+
exports.getFirstBotComment({ owner, repo, number, logger }).then((existingComment) => {
50+
if (existingComment) {
51+
const { id: nodeId, body: oldBody } = existingComment
5252
const newBody = `${oldBody}\n${body}`
5353
const id = graphQlIdToRestId(nodeId)
54-
return githubClient.issues.editComment({ owner, repo, id, body: newBody })
54+
const updatedComment = { owner, repo, id, body: newBody }
55+
56+
return githubClient.issues.editComment(updatedComment).catch((err) => {
57+
logger.error({ existingComment, updatedComment, err }, 'Error while editing existing comment on GitHub')
58+
})
5559
}
56-
return githubClient.issues.createComment({ owner, repo, number, body })
57-
}).catch((err) => {
58-
logger.error(err, 'Error while creating comment on GitHub')
59-
// swallow error
60+
61+
return githubClient.issues.createComment({ owner, repo, number, body }).catch((err) => {
62+
logger.error(err, 'Error while creating comment on GitHub')
63+
})
64+
}, (err) => {
65+
logger.error(err, 'Error while trying to fetch existing bot comment on GitHub')
6066
})
6167
}

0 commit comments

Comments
 (0)