diff --git a/.github/scripts/csat.js b/.github/scripts/csat.js index de99edcae..6fdb959c9 100644 --- a/.github/scripts/csat.js +++ b/.github/scripts/csat.js @@ -15,7 +15,7 @@ You may obtain a copy of the License at const CONSTANT_VALUES = require('./constant'); /** - * Invoked from csat_adkjava.yml file to post survey link + * Invoked from csat.yml file to post survey link * in closed issue. * @param {!Object.} github contains pre defined functions. * context Information about the workflow run. @@ -23,45 +23,35 @@ const CONSTANT_VALUES = require('./constant'); */ module.exports = async ({ github, context }) => { const issue = context.payload.issue.html_url; - const baseUrl = CONSTANT_VALUES.MODULE.CSAT.BASE_URL; - // Loop over all ths label present in issue and check if specific label is - // present for survey link. - for (const label of context.payload.issue.labels) { - if (label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.BUG) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.DOCUMENTATION) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.GOOD_FIRST_ISSUE) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.ENHANCEMENT) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.QUESTION) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.JAVA) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.SAMPLE) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.TESTING) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.CONTRIB) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.DEPENDENCIES) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.DUPLICATE) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.GITHUB) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.NEEDS_UPDATE) || - label.name.includes(CONSTANT_VALUES.GLOBALS.LABELS.READY_TO_PULL)) { - - console.log(`label-${label.name}, posting CSAT survey for issue =${issue}`); - - const yesCsat = ` ${CONSTANT_VALUES.MODULE.CSAT.YES}`; - - const noCsat = ` ${CONSTANT_VALUES.MODULE.CSAT.NO}`; - - const comment = CONSTANT_VALUES.MODULE.CSAT.MSG + '\n' + yesCsat + '\n' + noCsat + '\n'; - let issueNumber = context.issue.number ?? context.payload.issue.number; - - await github.rest.issues.createComment({ - issue_number: issueNumber, - owner: context.repo.owner, - repo: context.repo.repo, - body: comment - }); - } + // Check if any label matches (case-insensitive) the supported CSAT labels. + const supportedLabels = Object.values(CONSTANT_VALUES.GLOBALS.LABELS); + const hasMatchingLabel = context.payload.issue.labels.some(label => { + const name = label.name.toLowerCase(); + return supportedLabels.some(supportedLabel => name.includes(supportedLabel)); + }); + + if (hasMatchingLabel) { + console.log(`Posting CSAT survey for issue =${issue}`); + const baseUrl = CONSTANT_VALUES.MODULE.CSAT.BASE_URL; + + const yesCsat = ` ${CONSTANT_VALUES.MODULE.CSAT.YES}`; + + const noCsat = ` ${CONSTANT_VALUES.MODULE.CSAT.NO}`; + + const comment = CONSTANT_VALUES.MODULE.CSAT.MSG + '\n' + yesCsat + '\n' + + noCsat + '\n'; + const issueNumber = context.issue.number ?? context.payload.issue.number; + + await github.rest.issues.createComment({ + issue_number: issueNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: comment + }); } }; diff --git a/.github/workflows/csat.yml b/.github/workflows/csat.yml index de619c201..92181a459 100644 --- a/.github/workflows/csat.yml +++ b/.github/workflows/csat.yml @@ -7,7 +7,6 @@ on: permissions: contents: read issues: write - pull-requests: write jobs: welcome: @@ -18,4 +17,5 @@ jobs: with: script: | const script = require('./.github/scripts/csat.js') - script({github, context}) \ No newline at end of file + script({github, context}) + \ No newline at end of file