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

Better task extraction #43

Merged
merged 5 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 9 additions & 19 deletions services/bots/src/github-webhook/utils/text_parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { WebhookContext } from '../github-webhook.model';

interface IntegrationDocumentationLink {
link: string;
integration: string;
Expand Down Expand Up @@ -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?(?<checked>\w| |)\s?\] (?<description>.*)/.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;
Expand Down
6 changes: 4 additions & 2 deletions tests/services/bots/github-webhook/handlers/label_bot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ 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] Bugfix (non-breaking change which fixes an issue)' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep the test for [x] too

'\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',
base: { ref: 'master' },
};
await handler.handle(mockContext);
Expand Down