diff --git a/services/bots/src/github-webhook/utils/text_parser.ts b/services/bots/src/github-webhook/utils/text_parser.ts index 4949b87..3d042c2 100644 --- a/services/bots/src/github-webhook/utils/text_parser.ts +++ b/services/bots/src/github-webhook/utils/text_parser.ts @@ -1,5 +1,3 @@ -import { WebhookContext } from '../github-webhook.model'; - interface IntegrationDocumentationLink { link: string; integration: string; @@ -33,23 +31,15 @@ export const extractIntegrationDocumentationLinks = ( return results; }; -export const extractTasks = (body: string) => { - const matchAll = /- \[( |)(x|X| |)(| )\] /; - const matchChecked = /- \[( |)(x|X)(| )\] /; - const tasks: Task[] = []; - - body.split('\n').forEach((line: string) => { - if (!line.trim().startsWith('- [')) { - return; - } - - const lineSplit = line.split(matchAll); - const checked: boolean = matchChecked.test(line); - const description: string = lineSplit[lineSplit.length - 1].trim().replace(/\\r/g, ''); - tasks.push({ checked, description }); - }); - return tasks; -}; +export const extractTasks = (body: string): Task[] => + body + .split('\n') + .map((line) => /^-\s?\[\s?(?\w| |)\s?\] (?.*)/.exec(line.trim())?.groups) + .filter((groups) => groups !== undefined) + .map((groups) => ({ + checked: Boolean(groups.checked), + description: groups.description, + })); export const extractDocumentationSectionsLinks = (body: string): string[] => { const re = /https:\/\/(www.|rc.|next.|)home-assistant.io\/(.*)\//g; diff --git a/tests/services/bots/github-webhook/handlers/label_bot.spec.ts b/tests/services/bots/github-webhook/handlers/label_bot.spec.ts index 0e00389..23b2b84 100644 --- a/tests/services/bots/github-webhook/handlers/label_bot.spec.ts +++ b/tests/services/bots/github-webhook/handlers/label_bot.spec.ts @@ -73,14 +73,20 @@ describe('LabelBot', () => { ]; mockContext.payload.pull_request = { body: - '\n- [x] Bugfix (non-breaking change which fixes an issue)' + - '\n- [x] Breaking change (fix/feature causing existing functionality to break)', + '\n- [x] Deprecation (breaking change to happen in the future)' + + '\n- [ x] Bugfix (non-breaking change which fixes an issue)' + + '\n- [X ] Breaking change (fix/feature causing existing functionality to break)' + + '\n- [ ] Code quality improvements to existing code or addition of tests' + + '\n- [ ] Dependency upgrade' + + '\n- [C] New integration (thank you!)', base: { ref: 'master' }, }; await handler.handle(mockContext); assert.deepStrictEqual(mockContext.scheduledlabels, [ 'core', 'bugfix', + 'new-integration', + 'deprecation', 'breaking-change', 'merging-to-master', ]);