Skip to content

Commit 507b089

Browse files
HweinstockkaranA-aws
authored andcommitted
ci(jscpd): improve output format aws#6373
## Problem The output format of clones found in `jscpd` can be difficult to parse. As an example, see https://github.com/aws/aws-toolkit-vscode/actions/runs/12778633640/job/35621822359?pr=6370. Additionally, it mentions file names and line numbers, but doesn't provide a way to get to those files. ## Solution - reduce friction by linking directly to the duplicates
1 parent 4b87932 commit 507b089

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

.github/workflows/filterDuplicates.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* the program exits with an error and logs the filtered report to console.
55
*
66
* Usage:
7-
* node filterDuplicates.js run [path_to_git_diff] [path_to_jscpd_report]
7+
* node filterDuplicates.js run [path_to_git_diff] [path_to_jscpd_report] [commit_hash] [repo_name]
88
*
99
* Tests:
1010
* node filterDuplicates.js test
@@ -84,25 +84,40 @@ function filterDuplicates(report, changes) {
8484
return duplicates
8585
}
8686

87+
function formatDuplicates(duplicates, commitHash, repoName) {
88+
const baseUrl = `https://github.com/${repoName}`
89+
return duplicates.map((dupe) => {
90+
return {
91+
first: formUrl(dupe.firstFile, commitHash),
92+
second: formUrl(dupe.secondFile, commitHash),
93+
numberOfLines: dupe.lines,
94+
}
95+
})
96+
function formUrl(file, commitHash) {
97+
return `${baseUrl}/blob/${commitHash}/${file.name}#L${file.start}-L${file.end}`
98+
}
99+
}
100+
87101
async function run() {
88102
const rawDiffPath = process.argv[3]
89103
const jscpdReportPath = process.argv[4]
104+
const commitHash = process.argv[5]
105+
const repoName = process.argv[6]
90106
const changes = await parseDiff(rawDiffPath)
91107
const jscpdReport = JSON.parse(await fs.readFile(jscpdReportPath, 'utf8'))
92108
const filteredDuplicates = filterDuplicates(jscpdReport, changes)
93109

94110
console.log('%s files changes', changes.size)
95111
console.log('%s duplicates found', filteredDuplicates.length)
96112
if (filteredDuplicates.length > 0) {
97-
console.log(filteredDuplicates)
113+
console.log(formatDuplicates(filteredDuplicates, commitHash, repoName))
98114
process.exit(1)
99115
}
100116
}
101117

102118
/**
103119
* Mini-test Suite
104120
*/
105-
console.log(__dirname)
106121
const testDiffFile = path.resolve(__dirname, 'test/test_diff.txt')
107122
let testCounter = 0
108123
function assertEqual(actual, expected) {

.github/workflows/node.js.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ jobs:
101101
path: ./jscpd-report.json
102102

103103
- name: Check for Duplicates
104-
run: node "$GITHUB_WORKSPACE/.github/workflows/filterDuplicates.js" run diff_output.txt jscpd-report.json
104+
env:
105+
COMMIT_HASH: ${{ github.sha}}
106+
REPO_NAME: ${{ github.repository }}
107+
run: node "$GITHUB_WORKSPACE/.github/workflows/filterDuplicates.js" run diff_output.txt jscpd-report.json $COMMIT_HASH $REPO_NAME
105108

106109
macos:
107110
needs: lint-commits

0 commit comments

Comments
 (0)