todo,todo-backend: tweak todo item model and table

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-03-10 01:26:41 +01:00
parent 74543b6688
commit 240ab2d520
4 changed files with 60 additions and 36 deletions
@@ -30,7 +30,7 @@ import { Config } from '@backstage/config';
type TodoParser = (ctx: {
content: string;
path: string;
}) => (TodoItem & { line: number })[];
}) => { text: string; author?: string; lineNumber: number }[];
type Options = {
logger: Logger;
@@ -52,7 +52,7 @@ const defaultTodoParser: TodoParser = ({ content, path }) => {
return comments.map(comment => ({
text: comment.text,
author: comment.ref,
line: comment.line,
lineNumber: comment.line,
}));
} catch /* ignore unsupported extensions */ {
return [];
@@ -119,18 +119,14 @@ export class TodoScmReader implements TodoReader {
base: url,
});
let editUrl: string | undefined = this.integrations.resolveEditUrl(
viewUrl,
);
if (editUrl === viewUrl) {
editUrl = undefined;
}
todos.push(
...items.map(item => ({
...item,
editUrl,
viewUrl: item.line ? `${viewUrl}#L${item.line}` : viewUrl,
...items.map(({ lineNumber, text, author }) => ({
text,
author,
lineNumber,
repoFilePath: file.path,
viewUrl:
lineNumber === undefined ? viewUrl : `${viewUrl}#L${lineNumber}`,
})),
);
} catch (error) {
@@ -15,10 +15,20 @@
*/
export type TodoItem = {
/** The contents of the TODO comment */
text: string;
/** References author, if any */
author?: string;
/** URL used to view the file */
viewUrl?: string;
editUrl?: string;
/** The line number of the file that the TODO occurs at */
lineNumber?: number;
/** The path of the file containing the TODO within the repo */
repoFilePath?: string;
};
export type ReadTodosOptions = {