Skip to content

Commit

Permalink
fix: labels must be removed one at a time (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 10, 2021
1 parent d98700c commit 5d98472
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 7 additions & 5 deletions index.js
Expand Up @@ -8,7 +8,7 @@ const api = module.exports = {
addLabels,
isPullRequest,
main,
removeLabels
removeLabel
}

async function main () {
Expand Down Expand Up @@ -55,7 +55,9 @@ async function main () {
if (cc.breaking) labels.push(labelMap.breaking)
if (labelMap[cc.type]) labels.push(labelMap[cc.type])
if (labels.length) {
await api.removeLabels(Object.values(labelMap), payload)
for (const label of Object.values(labelMap)) {
await api.removeLabel(label, payload)
}
await api.addLabels(labels, payload)
}
}
Expand All @@ -74,13 +76,13 @@ async function addLabels (labels, payload) {
})
}

async function removeLabels (labels, payload) {
async function removeLabel (name, payload) {
const octokit = getOctokit()
await octokit.rest.issues.removeLabels({
await octokit.rest.issues.removeLabel({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.pull_request.number,
labels
name
})
}

Expand Down
12 changes: 8 additions & 4 deletions test/conventional-release-labels.js
Expand Up @@ -27,18 +27,22 @@ describe('conventional-release-labels', () => {
})
it('it adds feature label', async () => {
const addLabels = sandbox.stub(api, 'addLabels').resolves(undefined)
const removeLabels = sandbox.stub(api, 'removeLabels').resolves(undefined)
const removeLabel = sandbox.stub(api, 'removeLabel').resolves(undefined)
sandbox.stub(process.env, 'GITHUB_EVENT_PATH').value('./test/fixtures/feature.json')
await api.main()
sandbox.assert.calledWith(removeLabels, ['feature', 'fix', 'breaking'], sandbox.match.any)
sandbox.assert.calledWith(removeLabel, 'feature', sandbox.match.any)
sandbox.assert.calledWith(removeLabel, 'fix', sandbox.match.any)
sandbox.assert.calledWith(removeLabel, 'breaking', sandbox.match.any)
sandbox.assert.calledWith(addLabels, ['feature'], sandbox.match.any)
})
it('it adds breaking label along with type', async () => {
const addLabels = sandbox.stub(api, 'addLabels').resolves(undefined)
const removeLabels = sandbox.stub(api, 'removeLabels').resolves(undefined)
const removeLabel = sandbox.stub(api, 'removeLabel').resolves(undefined)
sandbox.stub(process.env, 'GITHUB_EVENT_PATH').value('./test/fixtures/breaking-fix.json')
await api.main()
sandbox.assert.calledWith(removeLabels, ['feature', 'fix', 'breaking'], sandbox.match.any)
sandbox.assert.calledWith(removeLabel, 'feature', sandbox.match.any)
sandbox.assert.calledWith(removeLabel, 'fix', sandbox.match.any)
sandbox.assert.calledWith(removeLabel, 'breaking', sandbox.match.any)
sandbox.assert.calledWith(addLabels, ['breaking', 'fix'], sandbox.match.any)
})
})

0 comments on commit 5d98472

Please sign in to comment.