Skip to content

Commit 72712e1

Browse files
committed
jenkins: revert edit of existing comment back to create a new comment
Reverting changes related to editing existing comments, going back to the previous behaviour of always creating new comments in PRs about CI / Jenkins runs. This is done primarily due to two things: * It has broken node-core-utils' ability to check if CI's have been run * There's not collaborator consensus about editing comments is actually better than creating new comments Future plans for bot PR comments going forward has to be discussed more thorougly and ensured it doesn't break other automation tools used by collaborators. Refs nodejs#228
1 parent 392a437 commit 72712e1

8 files changed

+30
-347
lines changed
+8-59
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,16 @@
11
'use strict'
22

33
const githubClient = require('./github-client')
4-
const GQL = require('./github-graphql-client')
5-
6-
const getPRComments = `query getPRComments($owner: String!, $repo: String!, $number: Int!, $cursor: String){
7-
repository(owner: $owner, name: $repo) {
8-
pullRequest(number: $number) {
9-
comments(first: 20, after:$cursor) {
10-
nodes {
11-
id
12-
body
13-
viewerDidAuthor
14-
}
15-
pageInfo {
16-
endCursor
17-
hasNextPage
18-
}
19-
}
20-
labels(first: 15) {
21-
nodes {
22-
name
23-
}
24-
}
25-
}
26-
}
27-
}`
28-
29-
function graphQlIdToRestId (nodeId) {
30-
const decoded = Buffer.from(nodeId, 'base64').toString()
31-
return decoded.match(/\d+$/)[0]
32-
}
33-
34-
exports.getFirstBotComment = function getFirstBotComment ({ owner, repo, number }, cursor = null) {
35-
return GQL(getPRComments, { owner, repo, number, cursor }).then(data => {
36-
const { nodes, pageInfo } = data.repository.pullRequest.comments
37-
const firstBotComment = nodes.find(e => e.viewerDidAuthor)
38-
if (firstBotComment) {
39-
return firstBotComment
40-
}
41-
if (pageInfo.hasNextPage) {
42-
return exports.getFirstBotComment({ owner, repo, number }, pageInfo.endCursor)
43-
}
44-
return null
45-
})
46-
}
474

485
exports.createPrComment = function createPrComment ({ owner, repo, number, logger }, body) {
49-
exports.getFirstBotComment({ owner, repo, number, logger }).then((existingComment) => {
50-
if (existingComment) {
51-
const { id: nodeId, body: oldBody } = existingComment
52-
const newBody = `${oldBody}\n${body}`
53-
const id = graphQlIdToRestId(nodeId)
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-
})
59-
}
60-
61-
return githubClient.issues.createComment({ owner, repo, number, body }).catch((err) => {
62-
logger.error(err, 'Error while creating comment on GitHub')
63-
})
6+
githubClient.issues.createComment({
7+
owner,
8+
repo,
9+
number,
10+
body
6411
}, (err) => {
65-
logger.error(err, 'Error while trying to fetch existing bot comment on GitHub')
12+
if (err) {
13+
logger.error(err, 'Error while creating comment on GitHub')
14+
}
6615
})
6716
}

lib/github-graphql-client.js

-10
This file was deleted.

0 commit comments

Comments
 (0)