Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 30 additions & 40 deletions .github/scripts/csat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,43 @@ 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.<string,!Object>} github contains pre defined functions.
* context Information about the workflow run.
* @return {null}
*/
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 = `<a href="${baseUrl + CONSTANT_VALUES.MODULE.CSAT.SATISFACTION_PARAM +
CONSTANT_VALUES.MODULE.CSAT.YES +
CONSTANT_VALUES.MODULE.CSAT.ISSUEID_PARAM + encodeURIComponent(issue)}"> ${CONSTANT_VALUES.MODULE.CSAT.YES}</a>`;

const noCsat = `<a href="${baseUrl + CONSTANT_VALUES.MODULE.CSAT.SATISFACTION_PARAM +
CONSTANT_VALUES.MODULE.CSAT.NO +
CONSTANT_VALUES.MODULE.CSAT.ISSUEID_PARAM + encodeURIComponent(issue)}"> ${CONSTANT_VALUES.MODULE.CSAT.NO}</a>`;

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 = `<a href="${baseUrl + CONSTANT_VALUES.MODULE.CSAT.SATISFACTION_PARAM +
CONSTANT_VALUES.MODULE.CSAT.YES +
CONSTANT_VALUES.MODULE.CSAT.ISSUEID_PARAM + encodeURIComponent(issue)}"> ${CONSTANT_VALUES.MODULE.CSAT.YES}</a>`;

const noCsat = `<a href="${baseUrl + CONSTANT_VALUES.MODULE.CSAT.SATISFACTION_PARAM +
CONSTANT_VALUES.MODULE.CSAT.NO +
CONSTANT_VALUES.MODULE.CSAT.ISSUEID_PARAM + encodeURIComponent(issue)}"> ${CONSTANT_VALUES.MODULE.CSAT.NO}</a>`;

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
});
}
};
4 changes: 2 additions & 2 deletions .github/workflows/csat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
permissions:
contents: read
issues: write
pull-requests: write

jobs:
welcome:
Expand All @@ -18,4 +17,5 @@ jobs:
with:
script: |
const script = require('./.github/scripts/csat.js')
script({github, context})
script({github, context})