Skip to content

Commit

Permalink
fix(labels): fixed the color padding when code has leading zeros
Browse files Browse the repository at this point in the history
and added an integration test for configuring labels

for #145, for #259
  • Loading branch information
travi committed Sep 20, 2022
1 parent 4c11a26 commit 2ed8cc6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/labels.js
Expand Up @@ -11,7 +11,7 @@ module.exports = class Labels extends Diffable {
if (label.color) {
label.color = String(label.color).replace(/^#/, '')
if (label.color.length < 6) {
label.color.padStart(6, '0')
label.color = label.color.padStart(6, '0')
}
}
})
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/labels-config.yml
@@ -0,0 +1,7 @@
labels:
- name: bug
color: ee0701
- name: enhancement
color: 008672
- name: help wanted
color: d876e3
46 changes: 46 additions & 0 deletions test/integration/plugins/labels.test.js
@@ -0,0 +1,46 @@
const { initializeNock, loadInstance, teardownNock, repository, buildTriggerEvent } = require('../common')
const path = require('path')
const fs = require('fs')
const settings = require('../../../lib/settings')
const { OK, CREATED, NO_CONTENT } = require('http-status-codes')
describe('branches plugin', function () {
let probot, githubScope

beforeEach(async () => {
githubScope = initializeNock()
probot = await loadInstance()
})

afterEach(() => {
teardownNock(githubScope)
})

it('configures labels', async () => {
const pathToConfig = path.resolve(__dirname, '..', '..', 'fixtures', 'labels-config.yml')
const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8'))
const config = configFile.toString()
githubScope
.get(`/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(settings.FILE_NAME)}`)
.reply(OK, config)
githubScope.get(`/repos/${repository.owner.name}/${repository.name}/labels?per_page=100`).reply(OK, [
{ name: 'bug', color: 'ee0701' },
{ name: 'duplicate', color: 'cccccc' },
{ name: 'help wanted', color: '128A0C' }
])
githubScope
.post(`/repos/${repository.owner.name}/${repository.name}/labels`, body => {
expect(body).toMatchObject({ name: 'enhancement', color: '008672' })
return true
})
.reply(CREATED)
githubScope
.patch(`/repos/${repository.owner.name}/${repository.name}/labels/help%20wanted`, body => {
expect(body).toMatchObject({ color: 'd876e3' })
return true
})
.reply(OK)
githubScope.delete(`/repos/${repository.owner.name}/${repository.name}/labels/duplicate`).reply(NO_CONTENT)

await probot.receive(buildTriggerEvent())
})
})

0 comments on commit 2ed8cc6

Please sign in to comment.