diff --git a/.github/workflows/post-gh-rca.yml b/.github/workflows/post-gh-rca.yml new file mode 100644 index 00000000..96283513 --- /dev/null +++ b/.github/workflows/post-gh-rca.yml @@ -0,0 +1,87 @@ +name: Post RCA Form + +permissions: + issues: write + contents: read + +on: + workflow_call: + inputs: + google-form-base-url: + description: Base URL of the Google Form. + required: true + type: string + repo-owner: + description: The repo owner + required: true + type: string + repo-name: + description: The repo name + required: true + type: string + issue-number: + description: The number of the closed issue + required: true + type: string + issue-labels: + required: true + type: string # JSON stringified array + +jobs: + post-rca-form: + runs-on: ubuntu-latest + + steps: + - name: Post Google Form link and log results on issue close + uses: actions/github-script@v7 + env: + GOOGLE_FORM_BASE_URL: ${{ inputs.google-form-base-url }} + ISSUE_LABELS: ${{ inputs.issue-labels }} + OWNER_NAME: ${{ inputs.repo-owner }} + REPO_NAME: ${{ inputs.repo-name }} + ISSUE_NUMBER: ${{ inputs.issue-number }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const googleFormBaseUrl = process.env.GOOGLE_FORM_BASE_URL; + const owner_name = process.env.OWNER_NAME; + const repo_name = process.env.REPO_NAME; + const issue_number = parseInt(process.env.ISSUE_NUMBER); + + const allowedLabels = JSON.parse(process.env.ISSUE_LABELS); + + // Fetch issue details to get the assignees + const { data: issue } = await github.rest.issues.get({ + owner: owner_name, + repo: repo_name, + issue_number: issue_number, + }); + + const hasAllowedLabel = issue.labels.some(label => + allowedLabels.includes(label.name) + ); + + if (!hasAllowedLabel) { + console.log(`❌ Issue #${issue_number} skipped — no matching label.`); + return; + } + + const assignees = issue.assignees.map(user => `@${user.login}`).join(', '); + const formUrl = `${googleFormBaseUrl}${issue_number}`; + const message = ` + Hi ${assignees}, + + This issue has been closed. Please complete this RCA form: + ${formUrl} + + + `; + + // Post the comment on the closed issue + await github.rest.issues.createComment({ + owner: owner_name, + repo: repo_name, + issue_number: issue_number, + body: message, + }); + console.log(`✅ Comment posted on issue #${issue_number}`);