Skip to content

Commit

Permalink
feat: add support for checkboxes in issue form
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Apr 30, 2024
1 parent 3cba48b commit 824aa5f
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 27 deletions.
13 changes: 6 additions & 7 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions dist/issue-form.js

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

2 changes: 1 addition & 1 deletion dist/issue-form.js.map

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

13 changes: 7 additions & 6 deletions src/issue-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export class IssueForm {
}

listKeywords(key: string, blockList: string[]) {
const propertySection = this.getSafeProperty(key);
let propertySection = this.getSafeProperty(key);

if (!propertySection) return undefined;
// Array can be only checkbox type - currently unsupported
if (Array.isArray(propertySection)) return undefined;

return propertySection
.split(', ', 25)
.filter(label => !this.isCompliant(blockList, label));
// Only Checkboxes are in form of array, dropdowns are strings separated by ', '
if (!Array.isArray(propertySection)) {
propertySection = propertySection.split(', ', 25);
}

return propertySection.filter(label => !this.isCompliant(blockList, label));
}

isCompliant(policy: string[], keyword: string) {
Expand Down
6 changes: 3 additions & 3 deletions test/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ describe('Integration test', () => {

// Check outputs
expect(process.env['OUTPUT_LABELS']).toMatchInlineSnapshot(
`"["bug πŸ›","RFE 🎁","high"]"`
`"["bug πŸ›","RFE 🎁","high","type: two","type: three"]"`
);
expect(process.env['OUTPUT_POLICY']).toMatchInlineSnapshot(
`"{"template":"bug.yml","section":{"type":["bug πŸ›","RFE 🎁"],"severity":["high"]}}"`
`"{"template":"bug.yml","section":{"type":["bug πŸ›","RFE 🎁"],"severity":["high"],"checkList":["type: two","type: three"]}}"`
);

// Check if the action has set the labels
Expand All @@ -282,7 +282,7 @@ describe('Integration test', () => {
owner: 'redhat-plumbers-in-action',
repo: 'advanced-issue-labeler',
issue_number: 1,
labels: ['bug πŸ›', 'RFE 🎁', 'high'],
labels: ['bug πŸ›', 'RFE 🎁', 'high', 'type: two', 'type: three'],
}
);
});
Expand Down
9 changes: 9 additions & 0 deletions test/unit/config.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export const templateConfig = {
{ name: 'low', keys: ['Low'] },
],
},
{
id: ['checkList'],
'block-list': ['one'],
label: [
{ name: 'type: one', keys: ['one'] },
{ name: 'type: two', keys: ['two'] },
{ name: 'type: three', keys: ['three'] },
],
},
],
},
{
Expand Down
28 changes: 28 additions & 0 deletions test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,34 @@ describe('Test Config class', () => {
},
],
},
{
"block-list": [
"one",
],
"id": [
"checkList",
],
"label": [
{
"keys": [
"one",
],
"name": "type: one",
},
{
"keys": [
"two",
],
"name": "type: two",
},
{
"keys": [
"three",
],
"name": "type: three",
},
],
},
],
"template": [
"bug.yml",
Expand Down
9 changes: 7 additions & 2 deletions test/unit/issue-form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ describe('Test IssueForm class', () => {
]
`);

// Checklists are unsupported at the moment
expect(issueForm.listKeywords('checkList', [])).toBeUndefined();
expect(issueForm.listKeywords('checkList', ['one'])).toMatchInlineSnapshot(`
[
"two",
"three",
]
`);

expect(issueForm.listKeywords('nonexistent', ['none'])).toBeUndefined();
});
});
8 changes: 8 additions & 0 deletions test/unit/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ describe('Test Labeler class', () => {
"bug πŸ›",
"RFE 🎁",
"high",
"type: two",
"type: three",
]
`);
});
Expand All @@ -163,6 +165,10 @@ describe('Test Labeler class', () => {
expect(labeler.outputPolicy).toMatchInlineSnapshot(`
{
"section": {
"checkList": [
"type: two",
"type: three",
],
"severity": [
"high",
],
Expand All @@ -179,6 +185,8 @@ describe('Test Labeler class', () => {
"bug πŸ›",
"RFE 🎁",
"high",
"type: two",
"type: three",
]
`);
});
Expand Down

0 comments on commit 824aa5f

Please sign in to comment.