Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions lib/plugins/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module.exports = class Labels extends Diffable {
return this.github.rest.repos.get(this.repo).then(() => {
return this.github.paginate(options)
})
// Excluded labels are never deleted, so leave them out of the comparison
// (and the dry-run deletions) unless the config manages them.
.then(labels => labels.filter(label => !this.isExcluded(label) || this.entries.some(entry => this.comparator(label, entry))))
.catch(e => {
this.logError(` Error ${JSON.stringify(e)}`)
if (e.status === 404) {
Expand Down
40 changes: 40 additions & 0 deletions test/unit/lib/plugins/labels.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,45 @@ describe('Labels', () => {
expect(github.rest.issues.createLabel).toHaveBeenCalledTimes(1)
})
})

describe('dry-run with excluded labels', () => {
const config = {
exclude: [{ name: '.*' }],
include: [
{ name: 'managed', color: 'FFFFFF', description: '' },
{ name: 'renamed', oldname: 'old-name', color: '000000', description: '' },
{ name: 'added', color: '0000FF', description: '' }
]
}

beforeEach(() => {
github.paginate.mockReturnValueOnce(Promise.resolve([
{ name: 'keep-me', color: '000000', description: '' },
{ name: 'managed', color: 'FF0000', description: '' },
{ name: 'old-name', color: '000000', description: '' }
]))
github.rest.issues.createLabel.endpoint = jest.fn().mockReturnValue({})
github.rest.issues.updateLabel.endpoint = jest.fn().mockReturnValue({})
})

it('does not report excluded labels as deletions', () => {
const plugin = new Labels(true, github, { owner: 'bkeepers', repo: 'test' }, config, log, [])

return plugin.sync().then(results => {
expect(JSON.stringify(results)).not.toContain('keep-me')
})
})

it('still updates and renames excluded labels that the config manages', () => {
const plugin = new Labels(true, github, { owner: 'bkeepers', repo: 'test' }, config, log, [])

return plugin.sync().then(() => {
const updatedNames = github.rest.issues.updateLabel.endpoint.mock.calls.map(([params]) => params.current_name)
const createdNames = github.rest.issues.createLabel.endpoint.mock.calls.map(([params]) => params.name)
expect(updatedNames.sort()).toEqual(['managed', 'old-name'])
expect(createdNames).toEqual(['added'])
})
})
})
})
})