Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: test removeLabel
This was the last GitHub API call not covered by our tests.
  • Loading branch information
mmarchini committed Aug 15, 2020
commit 948ee8229fc83c23da722eb2e3f4f35dc36bf7a0
9 changes: 5 additions & 4 deletions lib/node-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ async function updatePrWithLabels (options, labels) {
}
}

function removeLabelFromPR (options, label) {
function removeLabelFromPR (options, label, cb) {
// no need to request github if we didn't resolve a label
if (!label) {
return
return cb()
}

options.logger.debug('Trying to remove label: ' + label)
Expand All @@ -99,11 +99,12 @@ function removeLabelFromPR (options, label) {
}, (err) => {
if (err) {
if (err.code === 404) return options.logger.info('Label to remove did not exist, bailing ' + label)

return options.logger.error(err, 'Error while removing a label')
options.logger.error(err, 'Error while removing a label')
return cb(err, null)
}

options.logger.info('Removed a label ' + label)
return cb(null, label)
})
}

Expand Down
18 changes: 18 additions & 0 deletions test/unit/node-repo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,21 @@ tap.test('getBotPrLabels(): returns net labels added/removed by nodejs-github-bo
scope.done()
})
})

tap.test('removeLabelFromPR(): should remove label', (t) => {
const owner = 'nodejs'
const repo = 'node7'
const prId = '3'
const label = '3'

const scope = nock('https://api.github.com')
.filteringPath(ignoreQueryParams)
.delete(`/repos/${owner}/${repo}/issues/${prId}/labels/${label}`)
.reply(200)
t.plan(1)

nodeRepo.removeLabelFromPR({ owner, repo, prId, logger }, label, (_, response) => {
t.same(label, response)
scope.done()
})
})