From 154820ccbb81d52d5b5780d11f72706a44067947 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 19 Dec 2023 05:52:40 -0800 Subject: [PATCH] Automate add CSAT survey comment upon issue closure. PiperOrigin-RevId: 592209150 --- .github/workflows/csat.yaml | 21 ++++++++ .github/workflows/scripts/constant.js | 14 +++++ .github/workflows/scripts/csat.js | 33 ++++++++++++ .github/workflows/scripts/stale_csat.js | 53 +++++++++++++++++++ .github/workflows/stale-issues-pr.yml | 9 +++- .../opensource_only}/pull_workflow.js | 0 .../opensource_only}/pull_workflow.yaml | 0 7 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/csat.yaml create mode 100644 .github/workflows/scripts/constant.js create mode 100644 .github/workflows/scripts/csat.js create mode 100644 .github/workflows/scripts/stale_csat.js rename {.github/workflows/scripts => tf_keras/opensource_only}/pull_workflow.js (100%) rename {.github/workflows => tf_keras/opensource_only}/pull_workflow.yaml (100%) diff --git a/.github/workflows/csat.yaml b/.github/workflows/csat.yaml new file mode 100644 index 000000000..64b682b42 --- /dev/null +++ b/.github/workflows/csat.yaml @@ -0,0 +1,21 @@ +name: 'CSAT survey' +on: + issues: + types: + - closed + +permissions: + contents: read + issues: write + pull-requests: write + +jobs: + welcome: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/github-script@v6 + with: + script: | + const script = require('./\.github/workflows/scripts/csat.js') + script({github, context}) \ No newline at end of file diff --git a/.github/workflows/scripts/constant.js b/.github/workflows/scripts/constant.js new file mode 100644 index 000000000..114d31c01 --- /dev/null +++ b/.github/workflows/scripts/constant.js @@ -0,0 +1,14 @@ +let CONSTANT_VALUES = { + MODULE: { + CSAT: { + YES:'Yes', + NO:'No', + BASE_URL: 'https://docs.google.com/forms/d/e/1FAIpQLSdHag0RVFS7UXzZkKcsFCKOcX8raCupKK9RHSlYxp5U8lSJbQ/viewform?', + SATISFACTION_PARAM: 'entry.492125872=', + ISSUEID_PARAM: '&entry.243948740=', + MSG: 'Are you satisfied with the resolution of your issue?', + CSAT_LABELS: ['type:bug', 'type:build/install', 'type:support', 'type:others', 'type:docs-bug', 'type:performance'] + } + } +}; +module.exports = CONSTANT_VALUES; \ No newline at end of file diff --git a/.github/workflows/scripts/csat.js b/.github/workflows/scripts/csat.js new file mode 100644 index 000000000..c3a8f1ea6 --- /dev/null +++ b/.github/workflows/scripts/csat.js @@ -0,0 +1,33 @@ + +const CONSTANT_VALUES = require('./constant'); +/* +Invoked from staleCSAT.js and CSAT.yaml file to +post survey link in closed issue. +*/ +module.exports = async ({ github, context }) => { + const issue = context.payload.issue.html_url; + let base_url = 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 (CONSTANT_VALUES.MODULE.CSAT.CSAT_LABELS.includes(label.name)) { + 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 + }); + return + } + } + } diff --git a/.github/workflows/scripts/stale_csat.js b/.github/workflows/scripts/stale_csat.js new file mode 100644 index 000000000..5d8fb7023 --- /dev/null +++ b/.github/workflows/scripts/stale_csat.js @@ -0,0 +1,53 @@ + +const csat = require('./csat.js'); +const CONSTANT = require("./constant.js"); +/* +When stale bot closes the issue this function will +invoke and post CSAT link on the issue. +This function will fetch all the issues closed within 20 minutes and +post the survey link if survey link is not posted already. +*/ + +module.exports = async ({ github, context }) => { + + let date = new Date(); + let totalMilliSeconds = date.getTime(); + let minutes = 10; + let millisecondsToSubtract = minutes * 60 * 1000; + let closeTime = totalMilliSeconds-millisecondsToSubtract; + let newDate = new Date(closeTime); + let ISOCloseTime = newDate.toISOString(); + // Fetch all the issue closed with in 10 mins. + let closeTimeIssues = await github.rest.issues.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + state:"closed", + labels:"stale", + since:ISOCloseTime + }); + let ISSUESLIST = closeTimeIssues.data; + console.log(`Fetching all the closed within ${minutes} minutes.`) + console.log(ISSUESLIST) + for(let i=0;i This issue was closed because it has been inactive for more than 1 year. - repo-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v3 + - uses: actions/github-script@v6 + with: + script: | + const script = require('./\.github/workflows/scripts/issue-pr-closed.js') + script({github, context}) + \ No newline at end of file diff --git a/.github/workflows/scripts/pull_workflow.js b/tf_keras/opensource_only/pull_workflow.js similarity index 100% rename from .github/workflows/scripts/pull_workflow.js rename to tf_keras/opensource_only/pull_workflow.js diff --git a/.github/workflows/pull_workflow.yaml b/tf_keras/opensource_only/pull_workflow.yaml similarity index 100% rename from .github/workflows/pull_workflow.yaml rename to tf_keras/opensource_only/pull_workflow.yaml