Skip to content

Commit

Permalink
Add Gitlab code quality reporter (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
okuuva authored Jun 3, 2024
1 parent 82556d2 commit 0b9c1b8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cli/leasot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ program
)
.option('-i, --ignore <patterns>', 'add ignore patterns', list, [])
.option('-I, --inline-files', 'parse possible inline files', false)
.option('-r, --reporter [reporter]', 'use reporter (table|json|xml|markdown|vscode|raw) (default: table)', 'table')
.option(
'-r, --reporter [reporter]',
'use reporter (table|json|xml|markdown|vscode|gitlab|raw) (default: table)',
'table'
)
.option('-S, --skip-unsupported', 'skip unsupported filetypes', false)
.option('-t, --filetype [filetype]', 'force the filetype to parse. Useful for streams (default: .js)')
.option('-T, --tags <tags>', 'add additional comment types to find (alongside todo & fixme)', list, [])
Expand Down
4 changes: 4 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export enum BuiltinReporters {
* @hidden
*/
custom = 'custom',
/**
* Return a Gitlab code quality formatted json string of the todos
*/
gitlab = 'gitlab',
/**
* Return a json string of the todos
*/
Expand Down
27 changes: 27 additions & 0 deletions src/lib/reporters/gitlab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import crypto from 'crypto';

import { ReportItems, TodoComment } from '../../definitions.js';
import { JsonReporterConfig } from './json.js';

export const reporter: ReportItems = (todos: TodoComment[], config: JsonReporterConfig = { spacing: 2 }): string =>
JSON.stringify(
todos.map((todo: TodoComment) => {
return {
description: `${todo.tag} ${todo.text}`,
check_name: 'leasot',
fingerprint: crypto
.createHash('md5')
.update(`${todo.tag}${todo.text}${todo.file}${todo.line}`)
.digest('hex'),
severity: 'info',
location: {
path: todo.file,
lines: {
begin: todo.line,
},
},
};
}),
null,
config.spacing
);

0 comments on commit 0b9c1b8

Please sign in to comment.