diff --git a/index.js b/index.js index 275fd4d..bba0964 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ const api = module.exports = { addLabels, isPullRequest, main, - removeLabels + removeLabel } async function main () { @@ -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) } } @@ -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 }) } diff --git a/test/conventional-release-labels.js b/test/conventional-release-labels.js index 8934b70..6384152 100644 --- a/test/conventional-release-labels.js +++ b/test/conventional-release-labels.js @@ -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) }) })