From 990e4e81f715f02111776c74e93777d9d941ac33 Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Sun, 9 Jun 2024 15:32:17 -0400 Subject: [PATCH] Update jscpd.yml (#11742) * Update jscpd.yml * Update 33acrossBidAdapter.js * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml * Update jscpd.yml --- .github/workflows/jscpd.yml | 59 ++++++++++++++++++++++++++++++++--- modules/33acrossBidAdapter.js | 2 +- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/.github/workflows/jscpd.yml b/.github/workflows/jscpd.yml index e6affdcc16d..3cdd682e740 100644 --- a/.github/workflows/jscpd.yml +++ b/.github/workflows/jscpd.yml @@ -43,10 +43,6 @@ jobs: - name: Get the diff run: git diff origin/master...HEAD --name-only > changed_files.txt - - name: Filter JavaScript files - run: | - grep -E '\.js$' changed_files.txt | grep -v 'spec.js' > js_files.txt || true - - name: List generated files (debug) run: ls -l @@ -56,3 +52,58 @@ jobs: with: name: unfiltered-jscpd-report path: ./jscpd-report.json + + - name: Filter jscpd report for changed files + run: | + if [ ! -f ./jscpd-report.json ]; then + echo "jscpd-report.json not found" + exit 1 + fi + echo "Filtering jscpd report for changed files..." + CHANGED_FILES=$(jq -R -s -c 'split("\n")[:-1]' changed_files.txt) + echo "Changed files: $CHANGED_FILES" + jq --argjson changed_files "$CHANGED_FILES" ' + .duplicates | map(select( + (.firstFile?.name as $fname | $changed_files | any(. == $fname)) or + (.secondFile?.name as $sname | $changed_files | any(. == $sname)) + )) + ' ./jscpd-report.json > filtered-jscpd-report.json + cat filtered-jscpd-report.json + + - name: Check if filtered jscpd report exists + id: check_filtered_report + run: | + if [ -s ./filtered-jscpd-report.json ]; then + echo "filtered_report_exists=true" >> $GITHUB_ENV + else + echo "filtered_report_exists=false" >> $GITHUB_ENV + fi + + - name: Upload filtered jscpd report + if: env.filtered_report_exists == 'true' + uses: actions/upload-artifact@v4 + 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 + }); diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index d8a32d75afc..1eab05ba47f 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -15,7 +15,7 @@ import { import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {isSlotMatchingAdUnitCode} from '../libraries/gptUtils/gptUtils.js'; -// **************************** UTILS *************************** // +// **************************** UTILS ************************** // const BIDDER_CODE = '33across'; const BIDDER_ALIASES = ['33across_mgni']; const END_POINT = 'https://ssc.33across.com/api/v1/hb';