Skip to content

Commit 8243996

Browse files
committed
Add test verifying edited CI comments
1 parent 4b1fbfc commit 8243996

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

lib/github-comment.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ const getPRComments = `query getPRComments($owner: String!, $repo: String!, $num
2626
}
2727
}`
2828

29+
function graphQlIdToRestId(nodeId) {
30+
const decoded = Buffer.from(nodeId, 'base64').toString();
31+
return decoded.match(/\d+$/)[0]
32+
}
33+
2934
exports.getFirstBotComment = function getFirstBotComment ({ owner, repo, number }, cursor = null) {
3035
return GQL(getPRComments, { owner, repo, number, cursor }).then(data => {
3136
const { nodes, pageInfo } = data.repository.pullRequest.comments
@@ -43,8 +48,9 @@ exports.getFirstBotComment = function getFirstBotComment ({ owner, repo, number
4348
exports.createPrComment = function createPrComment ({ owner, repo, number, logger }, body) {
4449
exports.getFirstBotComment({ owner, repo, number, logger }).then((comment) => {
4550
if (comment) {
46-
const { id, body: oldBody } = comment
51+
const { id: nodeId, body: oldBody } = comment
4752
const newBody = `${oldBody}\n${body}`
53+
const id = graphQlIdToRestId(nodeId)
4854
return githubClient.issues.editComment({ owner, repo, id, body: newBody })
4955
}
5056
return githubClient.issues.createComment({ owner, repo, number, body })
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequest": {
5+
"comments": {
6+
"nodes": [
7+
{
8+
"id": "MDEyOklzc3VlQ29tbWVudDQ4ODM3NzY4Mg==",
9+
"body": "Lite-CI: https://ci.nodejs.org/job/node-test-pull-request-lite-pipeline/3416",
10+
"viewerDidAuthor": true
11+
},
12+
{
13+
"id": "MDEyOklzc3VlQ29tbWVudDQ4ODM3ODU5MA==",
14+
"body": "/to @nodejs/crypto @nodejs/lts ",
15+
"viewerDidAuthor": false
16+
},
17+
{
18+
"id": "MDEyOklzc3VlQ29tbWVudDQ4ODc4MDk5Nw==",
19+
"body": "CI: https://ci.nodejs.org/job/node-test-pull-request/22894/",
20+
"viewerDidAuthor": true
21+
}
22+
],
23+
"pageInfo": {
24+
"endCursor": "Y3Vyc29yOnYyOpHOHSI0xQ==",
25+
"hasNextPage": false
26+
}
27+
},
28+
"labels": {
29+
"nodes": [
30+
{
31+
"name": "C++"
32+
},
33+
{
34+
"name": "tls"
35+
}
36+
]
37+
}
38+
}
39+
}
40+
}
41+
}

test/integration/push-jenkins-update.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,39 @@ tap.test('Posts a CI comment in the related PR when Jenkins build is named node-
166166
})
167167
})
168168

169+
tap.test('Edits existing comment in the related PR when Jenkins build is named node-test-pull-request', (t) => {
170+
const fixture = readFixture('jenkins-test-pull-request-success-payload.json')
171+
const commentScope = nock('https://api.github.com')
172+
.filteringPath(ignoreQueryParams)
173+
.patch('/repos/nodejs/node/issues/comments/488377682', {
174+
body: 'Lite-CI: https://ci.nodejs.org/job/node-test-pull-request-lite-pipeline/3416\nCI: https://ci.nodejs.org/job/node-test-pull-request/21633/'
175+
})
176+
.reply(200)
177+
178+
nock('https://api.github.com')
179+
.filteringPath(ignoreQueryParams)
180+
.post('/graphql')
181+
.reply(200, readFixture('pull-request-three-comments-gql.json'))
182+
183+
// we don't care about asserting the scopes below, just want to stop the requests from actually being sent
184+
setupGetCommitsMock('node')
185+
nock('https://api.github.com')
186+
.filteringPath(ignoreQueryParams)
187+
.post('/repos/nodejs/node/statuses/8a5fec2a6bade91e544a30314d7cf21f8a200de1')
188+
.reply(201)
189+
190+
t.plan(1)
191+
192+
supertest(app)
193+
.post('/node/jenkins/start')
194+
.send(fixture)
195+
.expect(201)
196+
.end((err, res) => {
197+
commentScope.done()
198+
t.equal(err, null)
199+
})
200+
})
201+
169202
tap.test('Responds with 400 / "Bad request" when incoming request has invalid payload', (t) => {
170203
const fixture = readFixture('invalid-payload.json')
171204

0 commit comments

Comments
 (0)