Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: labels must be removed one at a time #14

Merged
merged 2 commits into from Oct 10, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})
})