Skip to content

Commit c9555a8

Browse files
authored
Merge pull request #641 from repository-settings/labels
2 parents 4c11a26 + 2ed8cc6 commit c9555a8

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

lib/plugins/labels.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = class Labels extends Diffable {
1111
if (label.color) {
1212
label.color = String(label.color).replace(/^#/, '')
1313
if (label.color.length < 6) {
14-
label.color.padStart(6, '0')
14+
label.color = label.color.padStart(6, '0')
1515
}
1616
}
1717
})

test/fixtures/labels-config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
labels:
2+
- name: bug
3+
color: ee0701
4+
- name: enhancement
5+
color: 008672
6+
- name: help wanted
7+
color: d876e3
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const { initializeNock, loadInstance, teardownNock, repository, buildTriggerEvent } = require('../common')
2+
const path = require('path')
3+
const fs = require('fs')
4+
const settings = require('../../../lib/settings')
5+
const { OK, CREATED, NO_CONTENT } = require('http-status-codes')
6+
describe('branches plugin', function () {
7+
let probot, githubScope
8+
9+
beforeEach(async () => {
10+
githubScope = initializeNock()
11+
probot = await loadInstance()
12+
})
13+
14+
afterEach(() => {
15+
teardownNock(githubScope)
16+
})
17+
18+
it('configures labels', async () => {
19+
const pathToConfig = path.resolve(__dirname, '..', '..', 'fixtures', 'labels-config.yml')
20+
const configFile = Buffer.from(fs.readFileSync(pathToConfig, 'utf8'))
21+
const config = configFile.toString()
22+
githubScope
23+
.get(`/repos/${repository.owner.name}/${repository.name}/contents/${encodeURIComponent(settings.FILE_NAME)}`)
24+
.reply(OK, config)
25+
githubScope.get(`/repos/${repository.owner.name}/${repository.name}/labels?per_page=100`).reply(OK, [
26+
{ name: 'bug', color: 'ee0701' },
27+
{ name: 'duplicate', color: 'cccccc' },
28+
{ name: 'help wanted', color: '128A0C' }
29+
])
30+
githubScope
31+
.post(`/repos/${repository.owner.name}/${repository.name}/labels`, body => {
32+
expect(body).toMatchObject({ name: 'enhancement', color: '008672' })
33+
return true
34+
})
35+
.reply(CREATED)
36+
githubScope
37+
.patch(`/repos/${repository.owner.name}/${repository.name}/labels/help%20wanted`, body => {
38+
expect(body).toMatchObject({ color: 'd876e3' })
39+
return true
40+
})
41+
.reply(OK)
42+
githubScope.delete(`/repos/${repository.owner.name}/${repository.name}/labels/duplicate`).reply(NO_CONTENT)
43+
44+
await probot.receive(buildTriggerEvent())
45+
})
46+
})

0 commit comments

Comments
 (0)