diff --git a/.github/workflows/post-gh-rca.yml b/.github/workflows/post-gh-rca.yml index 96283513..1cfeb750 100644 --- a/.github/workflows/post-gh-rca.yml +++ b/.github/workflows/post-gh-rca.yml @@ -24,15 +24,28 @@ on: required: true type: string issue-labels: + description: JSON-stringified array of labels that should trigger the RCA prompt required: true - type: string # JSON stringified array + type: string + entry-issue: + description: The entry ID for the issue field in the Google Form + required: true + type: string + entry-regression: + description: The entry ID for the regression field in the Google Form + required: true + type: string + entry-team: + description: The entry ID for the team field in the Google Form + required: true + type: string jobs: post-rca-form: + name: Post Google Form link and log results on issue close runs-on: ubuntu-latest - steps: - - name: Post Google Form link and log results on issue close + - name: Post RCA Form Link uses: actions/github-script@v7 env: GOOGLE_FORM_BASE_URL: ${{ inputs.google-form-base-url }} @@ -40,20 +53,29 @@ jobs: OWNER_NAME: ${{ inputs.repo-owner }} REPO_NAME: ${{ inputs.repo-name }} ISSUE_NUMBER: ${{ inputs.issue-number }} + ENTRY_ISSUE: ${{ inputs.entry-issue }} + ENTRY_REGRESSION: ${{ inputs.entry-regression }} + ENTRY_TEAM: ${{ inputs.entry-team }} 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 { + GOOGLE_FORM_BASE_URL: baseUrl, + ENTRY_ISSUE, + ENTRY_REGRESSION, + ENTRY_TEAM, + OWNER_NAME: owner, + REPO_NAME: repo, + ISSUE_NUMBER: issueNumStr, + } = process.env; + const issue_number = parseInt(issueNumStr, 10); 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, + owner, + repo, issue_number: issue_number, }); @@ -66,22 +88,36 @@ jobs: return; } - const assignees = issue.assignees.map(user => `@${user.login}`).join(', '); - const formUrl = `${googleFormBaseUrl}${issue_number}`; - const message = ` - Hi ${assignees}, + // if it's a sev1-high or sev0-high, lets grab team and regression labels, if there's any + // if there's none, an empty value will be sent, which is what we want + const teamLabels = issue.labels + .map(l => l.name) + .filter(n => n.startsWith('team-')); + + const regressionLabels = issue.labels + .map(l => l.name) + .filter(n => n.startsWith('regression-')); - This issue has been closed. Please complete this RCA form: - ${formUrl} + const formUrl = new URL(baseUrl); + formUrl.searchParams.set(ENTRY_ISSUE, issue_number); + formUrl.searchParams.set( + ENTRY_REGRESSION, + regressionLabels.length ? regressionLabels.join(',') : '' + ); + formUrl.searchParams.set( + ENTRY_TEAM, + teamLabels.length ? teamLabels.join(',') : '' + ); - - `; + const assignees = issue.assignees.map(u=>`@${u.login}`).join(', '); + const body = `Hi ${assignees}, + + This issue has been closed. Please complete this RCA form: + ${formUrl.toString()} + + `; - // Post the comment on the closed issue await github.rest.issues.createComment({ - owner: owner_name, - repo: repo_name, - issue_number: issue_number, - body: message, + owner, repo, issue_number, body }); console.log(`✅ Comment posted on issue #${issue_number}`);