Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: allow certain conventional commit types to be ignored (#24)
  • Loading branch information
bcoe committed Oct 14, 2021
1 parent 5aad398 commit b5da323
Show file tree
Hide file tree
Showing 5 changed files with 494 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -51,8 +51,10 @@ changelog:

| input | description |
|:---:|---|
| `token` | A GitHub secret token, the action defaults to using the special `secrets.GITHUB_TOKEN` |
| `type_labels` | Mapping from Conventional Commit `types` to pull request labels `{"feat": "feature", "fix": "fix", "breaking": "breaking"}` |
| `token` | A GitHub secret token, the action defaults to using the special, default: `secrets.GITHUB_TOKEN` |
| `type_labels` | Mapping from Conventional Commit `types` to pull request labels, default: `{"feat": "feature", "fix": "fix", "breaking": "breaking"}` |
| `ignored_types` | Conventional commit types that should have `ignore_label` applied, default: `["chore"]` |
| `ignore_label` | label to apply for ignored commits, default: `ignore-for-release` |

Enjoy 🎉

Expand Down
10 changes: 10 additions & 0 deletions action.yml
Expand Up @@ -11,6 +11,16 @@ inputs:
required: false
default: '{"feat": "feature", "fix": "fix", "breaking": "breaking"}'
type: string
ignored_types:
description: 'Conventional Commit types that should have ignore_label applied'
required: false
default: '["chore"]'
type: string
ignore_label:
description: 'label to apply for ignored commits'
required: false
default: 'ignore-for-release'
type: string

branding:
icon: 'align-justify'
Expand Down
15 changes: 13 additions & 2 deletions index.js
Expand Up @@ -14,6 +14,8 @@ const api = module.exports = {
async function main () {
const { visit } = await import('unist-util-visit')
const labelMap = JSON.parse(core.getInput('type_labels'))
const ignoreLabel = core.getInput('ignore_label')
const ignoredTypes = JSON.parse(core.getInput('ignored_types'))
if (!process.env.GITHUB_EVENT_PATH) {
console.warn('no event payload found')
return
Expand Down Expand Up @@ -54,11 +56,20 @@ async function main () {
const labels = []
if (cc.breaking) labels.push(labelMap.breaking)
if (labelMap[cc.type]) labels.push(labelMap[cc.type])
if (labels.length) {
if (labels.length || ignoredTypes.includes(cc.type)) {
// Remove all configured Conventional Commit labels:
for (const label of Object.values(labelMap)) {
await api.removeLabel(label, payload)
}
await api.addLabels(labels, payload)
// Also remove the special ignore label:
await api.removeLabel(ignoreLabel, payload)
// Add special ignore label to conventional commit types like "chore:":
if (ignoredTypes.includes(cc.type)) {
await api.addLabels([ignoreLabel], payload)
} else {
// Otherwise apply label associated with type:
await api.addLabels(labels, payload)
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions test/conventional-release-labels.js
Expand Up @@ -33,6 +33,7 @@ describe('conventional-release-labels', () => {
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(removeLabel, 'ignore-for-release', sandbox.match.any)
sandbox.assert.calledWith(addLabels, ['feature'], sandbox.match.any)
})
it('it adds breaking label along with type', async () => {
Expand All @@ -43,6 +44,18 @@ describe('conventional-release-labels', () => {
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(removeLabel, 'ignore-for-release', sandbox.match.any)
sandbox.assert.calledWith(addLabels, ['breaking', 'fix'], sandbox.match.any)
})
it('it applies ignore label to list of ignored types', async () => {
const addLabels = sandbox.stub(api, 'addLabels').resolves(undefined)
const removeLabel = sandbox.stub(api, 'removeLabel').resolves(undefined)
sandbox.stub(process.env, 'GITHUB_EVENT_PATH').value('./test/fixtures/ignored.json')
await api.main()
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(removeLabel, 'ignore-for-release', sandbox.match.any)
sandbox.assert.calledWith(addLabels, ['ignore-for-release'], sandbox.match.any)
})
})

0 comments on commit b5da323

Please sign in to comment.