From 5fc2fbe78ab983ae3445d3787f2883a34e78d647 Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Sun, 9 Jun 2024 15:24:35 -0400 Subject: [PATCH] Update jscpd.yml --- .github/workflows/jscpd.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/jscpd.yml b/.github/workflows/jscpd.yml index f54c35c56b7..2aa7fa635b2 100644 --- a/.github/workflows/jscpd.yml +++ b/.github/workflows/jscpd.yml @@ -86,3 +86,25 @@ jobs: with: name: filtered-jscpd-report path: ./filtered-jscpd-report.json + + - name: Post GitHub comment + if: env.filtered_report_exists == 'true' + uses: actions/github-script@v6 + with: + script: | + 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"; + filteredReport.forEach(duplication => { + const firstFile = duplication.firstFile.name; + const secondFile = duplication.secondFile.name; + const lines = duplication.lines; + comment += `- \`${firstFile}\` has ${lines} duplicated lines with \`${secondFile}\`\n`; + }); + comment += "\nReducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Keep up the great work! 🚀"; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: comment + });