|
4 | 4 | * the program exits with an error and logs the filtered report to console.
|
5 | 5 | *
|
6 | 6 | * 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] |
8 | 8 | *
|
9 | 9 | * Tests:
|
10 | 10 | * node filterDuplicates.js test
|
@@ -84,25 +84,40 @@ function filterDuplicates(report, changes) {
|
84 | 84 | return duplicates
|
85 | 85 | }
|
86 | 86 |
|
| 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 | + |
87 | 101 | async function run() {
|
88 | 102 | const rawDiffPath = process.argv[3]
|
89 | 103 | const jscpdReportPath = process.argv[4]
|
| 104 | + const commitHash = process.argv[5] |
| 105 | + const repoName = process.argv[6] |
90 | 106 | const changes = await parseDiff(rawDiffPath)
|
91 | 107 | const jscpdReport = JSON.parse(await fs.readFile(jscpdReportPath, 'utf8'))
|
92 | 108 | const filteredDuplicates = filterDuplicates(jscpdReport, changes)
|
93 | 109 |
|
94 | 110 | console.log('%s files changes', changes.size)
|
95 | 111 | console.log('%s duplicates found', filteredDuplicates.length)
|
96 | 112 | if (filteredDuplicates.length > 0) {
|
97 |
| - console.log(filteredDuplicates) |
| 113 | + console.log(formatDuplicates(filteredDuplicates, commitHash, repoName)) |
98 | 114 | process.exit(1)
|
99 | 115 | }
|
100 | 116 | }
|
101 | 117 |
|
102 | 118 | /**
|
103 | 119 | * Mini-test Suite
|
104 | 120 | */
|
105 |
| -console.log(__dirname) |
106 | 121 | const testDiffFile = path.resolve(__dirname, 'test/test_diff.txt')
|
107 | 122 | let testCounter = 0
|
108 | 123 | function assertEqual(actual, expected) {
|
|
0 commit comments