aboutsummaryrefslogtreecommitdiff
path: root/.github/scripts/process_detekt_output.js
blob: 75974ee43d71c62900a3700ce267acc7dd43623a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const fs = require('fs');
const path = require('path');

const PR_SHA = process.env.PR_SHA;
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;

// Read detekt_output.txt
const detektOutput = fs.readFileSync('detekt_output.txt', 'utf8');

let comment = '### One or more Detekt Failures were detected:\n\n';

const lines = detektOutput.split('\n');
lines.forEach((line) => {
    if (!line.trim()) return; // Skip empty lines

    // Extract file path and line number
    const filePathMatch = line.match(/file=([^,]+)/);
    const lineNumberMatch = line.match(/line=(\d+)/);
    if (!filePathMatch || !lineNumberMatch) return;

    const filePath = filePathMatch[1];
    const lineNumber = lineNumberMatch[1];

    // Remove everything before 'src/' in the file path (if it exists)
    const srcIndex = filePath.indexOf('src/');
    const cleanedFilePath = srcIndex !== -1 ? filePath.substring(srcIndex) : filePath;

    // Extract file name
    const fileName = path.basename(cleanedFilePath);

    // Clean up the line to remove everything between '::' and '::' (inclusive)
    const cleanMessage = line.replace(/::.*?::/g, '');

    // Append to comment
    comment += `- [${fileName}#L${lineNumber}](https://github.com/${GITHUB_REPOSITORY}/blob/${PR_SHA}/${cleanedFilePath}#L${lineNumber}): ${cleanMessage}\n`;
});

// Write comment to file
fs.writeFileSync('detekt_comment.txt', comment);