Skip to content

Commit

Permalink
fix empty object foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Jan 8, 2021
1 parent 0b48d69 commit dc49321
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions .res/labels.merge3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_extends: ghaction-github-labeler:.res/labels.merge1.yml
23 changes: 23 additions & 0 deletions __tests__/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,27 @@ describe('run', () => {
expect(fileLabels[1]).toEqual(expect.objectContaining({name: ':bug: bug', description: 'Damn bugs'}));
expect(() => labeler.run()).not.toThrow();
});
it('extends', async () => {
const input = <Inputs>{
githubToken: process.env.GITHUB_TOKEN || 'test',
yamlFile: '.res/labels.merge3.yml',
skipDelete: true,
dryRun: true,
exclude: []
};
nock('https://api.github.com').get('/repos/crazy-max/ghaction-github-labeler/labels').reply(200, labelsFixture());

nock('https://api.github.com')
.get(`/repos/crazy-max/ghaction-github-labeler/contents/${encodeURIComponent(input.yamlFile as string)}`)
.reply(200, configFixture(input.yamlFile as string));

nock('https://api.github.com')
.get(`/repos/crazy-max/ghaction-github-labeler/contents/${encodeURIComponent('.res/labels.merge1.yml')}`)
.reply(200, configFixture('.res/labels.merge1.yml'));

const labeler = new Labeler(input);
const fileLabels = await labeler.fileLabels;
expect(fileLabels.length).toBe(15);
expect(() => labeler.run()).not.toThrow();
});
});
4 changes: 3 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export class Labeler {
const output = [] as Label[];
configs
.map(config => {
const labels = config.labels ? config.labels : config;
let labels = config.labels ? config.labels : config;
if (Object.keys(labels).length === 0) labels = undefined;
return {labels: labels || []};
})
.map(config => {
Expand Down

0 comments on commit dc49321

Please sign in to comment.