Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for labeling based on checkboxes ☑️ #342

Merged
merged 3 commits into from
Apr 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ policy:
- name: 'kind: reptiles'
keys: ['🐊 Crocodile']
- name: 'invertebrates'
keys: ['🐛 Bug', '🕷️ Spider']
keys: ['🐛 Bug', '🕷️ Spider']
```

GitHub workflow that automatically marks issues with animal types labels:
Expand Down
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
8 changes: 4 additions & 4 deletions test/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('Integration test', () => {
setDefaultInputs();
vi.stubEnv('INPUT_ISSUE-FORM', JSON.stringify(dropdownForm));
vi.stubEnv('INPUT_SECTION', 'type');
vi.stubEnv('INPUT_BLOCK-LIST', 'other\nnone');
vi.stubEnv('INPUT_BLOCK-LIST', 'other\nnone\nOther');

vi.mocked(mocks['@octokit/core']).config.get.mockImplementation(
async (params: { owner: string; repo: string; path: string }) => {
Expand Down 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
11 changes: 11 additions & 0 deletions test/unit/config.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,30 @@ export const templateConfig = {
section: [
{
id: ['type'],
'block-list': ['Other'],
label: [
{ name: 'bug 🐛', keys: ['Bug Report'] },
{ name: 'RFE 🎁', keys: ['Feature Request'] },
],
},
{
id: ['severity'],
'block-list': ['None', 'Other'],
label: [
{ name: 'high', keys: ['High'] },
{ name: 'medium', keys: ['Medium'] },
{ 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
37 changes: 35 additions & 2 deletions test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ describe('Test Config class', () => {
{
"section": [
{
"block-list": [],
"block-list": [
"Other",
],
"id": [
"type",
],
Expand All @@ -157,7 +159,10 @@ describe('Test Config class', () => {
],
},
{
"block-list": [],
"block-list": [
"None",
"Other",
],
"id": [
"severity",
],
Expand All @@ -182,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
2 changes: 1 addition & 1 deletion test/unit/issue-form.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const dropdownForm = {
title: 'Test issue',
body: 'Test body',
severity: 'High',
type: 'Bug Report, Feature Request, other, none',
type: 'Bug Report, Feature Request, Other, none',
checkList: ['one', 'two', 'three'],
};
11 changes: 8 additions & 3 deletions test/unit/issue-form.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,21 @@ describe('Test IssueForm class', () => {
]
`);

expect(issueForm.listKeywords('type', ['other', 'none']))
expect(issueForm.listKeywords('type', ['other', 'none', 'Other']))
.toMatchInlineSnapshot(`
[
"Bug Report",
"Feature Request",
]
`);

// 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();
});
});
11 changes: 10 additions & 1 deletion test/unit/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Test Labeler class', () => {

beforeEach(() => {
vi.stubEnv('INPUT_SECTION', 'type');
vi.stubEnv('INPUT_BLOCK-LIST', 'other\nnone');
vi.stubEnv('INPUT_BLOCK-LIST', 'other\nnone\nOther');

labeler = new Labeler(
new IssueForm(dropdownForm),
Expand All @@ -43,6 +43,7 @@ describe('Test Labeler class', () => {
[
"other",
"none",
"Other",
]
`);

Expand Down Expand Up @@ -151,6 +152,8 @@ describe('Test Labeler class', () => {
"bug 🐛",
"RFE 🎁",
"high",
"type: two",
"type: three",
]
`);
});
Expand All @@ -162,6 +165,10 @@ describe('Test Labeler class', () => {
expect(labeler.outputPolicy).toMatchInlineSnapshot(`
{
"section": {
"checkList": [
"type: two",
"type: three",
],
"severity": [
"high",
],
Expand All @@ -178,6 +185,8 @@ describe('Test Labeler class', () => {
"bug 🐛",
"RFE 🎁",
"high",
"type: two",
"type: three",
]
`);
});
Expand Down