Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/node-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ function getBotPrLabels (options, cb) {
page: 1,
per_page: 100, // we probably won't hit this
issue_number: options.prId
}, (err, events) => {
}, (err, res) => {
if (err) {
return cb(err)
}

const events = res.data || []
const ourLabels = []

for (const event of events) {
Expand Down
22 changes: 22 additions & 0 deletions test/_fixtures/pull-request-events-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": [
{
"event": "labeled",
"actor": {
"login": "nodejs-github-bot"
},
"label": {
"name": "testlabel"
}
},
{
"event": "unlabeled",
"actor": {
"login": "nodejs-github-bot"
},
"label": {
"name": "testlabel"
}
}
]
}
13 changes: 13 additions & 0 deletions test/_fixtures/pull-request-events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"data": [
{
"event": "labeled",
"actor": {
"login": "nodejs-github-bot"
},
"label": {
"name": "testlabel"
}
}
]
}
30 changes: 30 additions & 0 deletions test/unit/node-repo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,33 @@ tap.test('fetchExistingLabels(): can retrieve more than 100 labels', (t) => {
t.ok(existingLabels.includes('windows'))
})
})

tap.test('getBotPrLabels(): returns labels added by nodejs-github-bot', (t) => {
const events = readFixture('pull-request-events.json')
sinon.stub(githubClient.issues, 'getEvents', (options, cb) => { cb(null, events) })
const nodeRepo = proxyquire('../../lib/node-repo', {'./github-client': githubClient})

t.plan(1)
t.tearDown(() => {
githubClient.issues.getEvents.restore()
})

nodeRepo.getBotPrLabels({ owner: 'nodejs', repo: 'node', prId: '1' }, (_, labels) => {
t.same(labels, ['testlabel'])
})
})

tap.test('getBotPrLabels(): returns net labels added/removed by nodejs-github-bot', (t) => {
const events = readFixture('pull-request-events-2.json')
sinon.stub(githubClient.issues, 'getEvents', (options, cb) => { cb(null, events) })
const nodeRepo = proxyquire('../../lib/node-repo', {'./github-client': githubClient})

t.plan(1)
t.tearDown(() => {
githubClient.issues.getEvents.restore()
})

nodeRepo.getBotPrLabels({ owner: 'nodejs', repo: 'node', prId: '1' }, (_, labels) => {
t.same(labels, [])
})
})