Skip to content

Commit

Permalink
improve duplicate checker
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Jun 13, 2024
1 parent ab23840 commit 5da6456
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/jscpd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Check for Duplicated Code

on:
on:
pull_request_target:
branches:
- master
Expand Down Expand Up @@ -100,11 +100,14 @@ jobs:
const fs = require('fs');
const filteredReport = JSON.parse(fs.readFileSync('filtered-jscpd-report.json', 'utf8'));
let comment = "Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:\n\n";
function link(dup) {
return `https://github.com/${{ github.event.repo.name }}/blob/${{ github.event.pull_request.head.sha }}/${dup.name}#L${dup.start}-L${dup.end}`
}
filteredReport.forEach(duplication => {
const firstFile = duplication.firstFile.name;
const secondFile = duplication.secondFile.name;
const firstFile = duplication.firstFile;
const secondFile = duplication.secondFile;
const lines = duplication.lines;
comment += `- \`${firstFile}\` has ${lines} duplicated lines with \`${secondFile}\`\n`;
comment += `- [\`${firstFile.name}\`](${link(firstFile)) has ${lines} duplicated lines with [\`${secondFile.name}\`](${link(secondFile)})\n`;
});
comment += "\nReducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. Keep up the great work! 🚀";
github.rest.issues.createComment({
Expand Down

0 comments on commit 5da6456

Please sign in to comment.