|
1 | 1 | name: Post RCA Form |
2 | | - |
3 | | -permissions: |
4 | | - issues: write |
5 | | - contents: read |
6 | | - |
7 | | -on: |
8 | | - workflow_call: |
9 | | - inputs: |
10 | | - google-form-base-url: |
11 | | - description: Base URL of the Google Form. |
12 | | - default: 'https://docs.google.com/forms/d/e/1FAIpQLSeLOVVUy7mO1j-5Isb04OAWk3dM0b1NY1R8kf0tiEBs9elcEg/viewform?usp=pp_url' |
13 | | - type: string |
14 | | - repo-owner: |
15 | | - description: The repo owner |
16 | | - required: true |
17 | | - type: string |
18 | | - repo-name: |
19 | | - description: The repo name |
20 | | - required: true |
21 | | - type: string |
22 | | - issue-number: |
23 | | - description: The number of the closed issue |
24 | | - required: true |
25 | | - type: string |
26 | | - issue-labels: |
27 | | - description: JSON-stringified array of labels that should trigger the RCA prompt |
28 | | - required: true |
29 | | - type: string |
30 | | - entry-issue: |
31 | | - description: The entry ID for the issue field in the Google Form |
32 | | - default: 'entry.1417567074' |
33 | | - type: string |
34 | | - entry-regression: |
35 | | - description: The entry ID for the regression field in the Google Form |
36 | | - default: 'entry.1470697156' |
37 | | - type: string |
38 | | - entry-team: |
39 | | - description: The entry ID for the team field in the Google Form |
40 | | - default: 'entry.1198657478' |
41 | | - type: string |
42 | | - entry-repo-name: |
43 | | - description: The entry ID for the repository name field |
44 | | - default: 'entry.1085838323' |
45 | | - type: string |
46 | | - entry-issue-url: |
47 | | - description: The entry ID for the GitHub issue URL field |
48 | | - default: 'entry.516762472' |
49 | | - type: string |
50 | | - |
51 | | -jobs: |
52 | | - post-rca-form: |
53 | | - name: Post Google Form link and log results on issue close |
54 | | - runs-on: ubuntu-latest |
55 | | - steps: |
56 | | - - name: Post RCA Form Link |
57 | | - uses: actions/github-script@v7 |
58 | | - env: |
59 | | - GOOGLE_FORM_BASE_URL: ${{ inputs.google-form-base-url }} |
60 | | - ISSUE_LABELS: ${{ inputs.issue-labels }} |
61 | | - OWNER_NAME: ${{ inputs.repo-owner }} |
62 | | - REPO_NAME: ${{ inputs.repo-name }} |
63 | | - ISSUE_NUMBER: ${{ inputs.issue-number }} |
64 | | - ENTRY_ISSUE: ${{ inputs.entry-issue }} |
65 | | - ENTRY_REGRESSION: ${{ inputs.entry-regression }} |
66 | | - ENTRY_TEAM: ${{ inputs.entry-team }} |
67 | | - ENTRY_REPO_NAME: ${{ inputs.entry-repo-name }} |
68 | | - ENTRY_ISSUE_URL: ${{ inputs.entry-issue-url }} |
69 | | - with: |
70 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
71 | | - script: | |
72 | | - const { |
73 | | - GOOGLE_FORM_BASE_URL: baseUrl, |
74 | | - ENTRY_ISSUE, |
75 | | - ENTRY_REGRESSION, |
76 | | - ENTRY_TEAM, |
77 | | - ENTRY_REPO_NAME, |
78 | | - ENTRY_ISSUE_URL, |
79 | | - OWNER_NAME: owner, |
80 | | - REPO_NAME: repo, |
81 | | - ISSUE_NUMBER: issueNumStr, |
82 | | - } = process.env; |
83 | | -
|
84 | | - const issue_number = parseInt(issueNumStr, 10); |
85 | | - const allowedLabels = JSON.parse(process.env.ISSUE_LABELS); |
86 | | -
|
87 | | - // Fetch issue details to get the assignees |
88 | | - const { data: issue } = await github.rest.issues.get({ |
| 2 | +description: 'Posts a Google Form link for RCA on issues with specific labels.' |
| 3 | + |
| 4 | +inputs: |
| 5 | + google-form-base-url: |
| 6 | + description: Base URL of the Google Form. |
| 7 | + default: 'https://docs.google.com/forms/d/e/1FAIpQLSeLOVVUy7mO1j-5Isb04OAWk3dM0b1NY1R8kf0tiEBs9elcEg/viewform?usp=pp_url' |
| 8 | + repo-owner: |
| 9 | + description: The repo owner |
| 10 | + required: true |
| 11 | + repo-name: |
| 12 | + description: The repo name |
| 13 | + required: true |
| 14 | + issue-number: |
| 15 | + description: The number of the closed issue |
| 16 | + required: true |
| 17 | + issue-labels: |
| 18 | + description: JSON-stringified array of labels that should trigger the RCA prompt |
| 19 | + required: true |
| 20 | + entry-issue: |
| 21 | + description: The entry ID for the issue field in the Google Form |
| 22 | + default: 'entry.1417567074' |
| 23 | + entry-regression: |
| 24 | + description: The entry ID for the regression field in the Google Form |
| 25 | + default: 'entry.1470697156' |
| 26 | + entry-team: |
| 27 | + description: The entry ID for the team field in the Google Form |
| 28 | + default: 'entry.1198657478' |
| 29 | + entry-repo-name: |
| 30 | + description: The entry ID for the repository name field |
| 31 | + default: 'entry.1085838323' |
| 32 | + entry-issue-url: |
| 33 | + description: The entry ID for the GitHub issue URL field |
| 34 | + default: 'entry.516762472' |
| 35 | + github-token: |
| 36 | + description: GitHub token for authentication |
| 37 | + required: true |
| 38 | + |
| 39 | +runs: |
| 40 | + using: composite |
| 41 | + steps: |
| 42 | + - name: Post RCA Form Link |
| 43 | + uses: actions/github-script@v8 |
| 44 | + env: |
| 45 | + GOOGLE_FORM_BASE_URL: ${{ inputs.google-form-base-url }} |
| 46 | + ISSUE_LABELS: ${{ inputs.issue-labels }} |
| 47 | + OWNER_NAME: ${{ inputs.repo-owner }} |
| 48 | + REPO_NAME: ${{ inputs.repo-name }} |
| 49 | + ISSUE_NUMBER: ${{ inputs.issue-number }} |
| 50 | + ENTRY_ISSUE: ${{ inputs.entry-issue }} |
| 51 | + ENTRY_REGRESSION: ${{ inputs.entry-regression }} |
| 52 | + ENTRY_TEAM: ${{ inputs.entry-team }} |
| 53 | + ENTRY_REPO_NAME: ${{ inputs.entry-repo-name }} |
| 54 | + ENTRY_ISSUE_URL: ${{ inputs.entry-issue-url }} |
| 55 | + with: |
| 56 | + github-token: ${{ inputs.github-token }} |
| 57 | + script: | |
| 58 | + const { |
| 59 | + GOOGLE_FORM_BASE_URL: baseUrl, |
| 60 | + ENTRY_ISSUE, |
| 61 | + ENTRY_REGRESSION, |
| 62 | + ENTRY_TEAM, |
| 63 | + ENTRY_REPO_NAME, |
| 64 | + ENTRY_ISSUE_URL, |
| 65 | + OWNER_NAME: owner, |
| 66 | + REPO_NAME: repo, |
| 67 | + ISSUE_NUMBER: issueNumStr, |
| 68 | + } = process.env; |
| 69 | +
|
| 70 | + const issue_number = parseInt(issueNumStr, 10); |
| 71 | + const allowedLabels = JSON.parse(process.env.ISSUE_LABELS); |
| 72 | +
|
| 73 | + // Fetch issue details to get the assignees |
| 74 | + const { data: issue } = await github.rest.issues.get({ |
| 75 | + owner, |
| 76 | + repo, |
| 77 | + issue_number: issue_number, |
| 78 | + }); |
| 79 | +
|
| 80 | + const hasAllowedLabel = issue.labels.some(label => |
| 81 | + allowedLabels.includes(label.name) |
| 82 | + ); |
| 83 | +
|
| 84 | + if (!hasAllowedLabel) { |
| 85 | + console.log(`❌ Issue #${issue_number} skipped — no matching label.`); |
| 86 | + return; |
| 87 | + } |
| 88 | +
|
| 89 | + // if it's a sev1-high or sev0-high, lets grab team and regression labels, if there's any |
| 90 | + // if there's none, an empty value will be sent, which is what we want |
| 91 | + const teamLabels = issue.labels |
| 92 | + .map(l => l.name) |
| 93 | + .filter(n => n.startsWith('team-')); |
| 94 | +
|
| 95 | + const regressionLabels = issue.labels |
| 96 | + .map(l => l.name) |
| 97 | + .filter(n => n.startsWith('regression-')); |
| 98 | +
|
| 99 | + const formUrl = new URL(baseUrl); |
| 100 | + formUrl.searchParams.set(ENTRY_ISSUE, issue_number); |
| 101 | + formUrl.searchParams.set( |
| 102 | + ENTRY_REGRESSION, |
| 103 | + regressionLabels.length ? regressionLabels.join(',') : '' |
| 104 | + ); |
| 105 | + formUrl.searchParams.set( |
| 106 | + ENTRY_TEAM, |
| 107 | + teamLabels.length ? teamLabels.join(',') : '' |
| 108 | + ); |
| 109 | +
|
| 110 | + formUrl.searchParams.set(ENTRY_REPO_NAME, repo); |
| 111 | + formUrl.searchParams.set(ENTRY_ISSUE_URL, `https://github.com/${owner}/${repo}/issues/${issue_number}`); |
| 112 | +
|
| 113 | + const assignees = issue.assignees.map(u=>`@${u.login}`).join(', '); |
| 114 | + const body = `Hi ${assignees}, |
| 115 | +
|
| 116 | + This issue has been closed. Please complete this RCA form: |
| 117 | + ${formUrl.toString()} |
| 118 | +
|
| 119 | + <!-- AUTO-FORM -->`; |
| 120 | +
|
| 121 | + await github.rest.issues.createComment({ |
| 122 | + owner, repo, issue_number, body |
| 123 | + }); |
| 124 | + console.log(`✅ Comment posted on issue #${issue_number}`); |
| 125 | +
|
| 126 | + // Add the RCA-needed label |
| 127 | + try { |
| 128 | + await github.rest.issues.addLabels({ |
89 | 129 | owner, |
90 | 130 | repo, |
91 | 131 | issue_number: issue_number, |
| 132 | + labels: ['RCA-needed'] |
92 | 133 | }); |
93 | | -
|
94 | | - const hasAllowedLabel = issue.labels.some(label => |
95 | | - allowedLabels.includes(label.name) |
96 | | - ); |
97 | | -
|
98 | | - if (!hasAllowedLabel) { |
99 | | - console.log(`❌ Issue #${issue_number} skipped — no matching label.`); |
100 | | - return; |
101 | | - } |
102 | | -
|
103 | | - // if it's a sev1-high or sev0-high, lets grab team and regression labels, if there's any |
104 | | - // if there's none, an empty value will be sent, which is what we want |
105 | | - const teamLabels = issue.labels |
106 | | - .map(l => l.name) |
107 | | - .filter(n => n.startsWith('team-')); |
108 | | -
|
109 | | - const regressionLabels = issue.labels |
110 | | - .map(l => l.name) |
111 | | - .filter(n => n.startsWith('regression-')); |
112 | | -
|
113 | | - const formUrl = new URL(baseUrl); |
114 | | - formUrl.searchParams.set(ENTRY_ISSUE, issue_number); |
115 | | - formUrl.searchParams.set( |
116 | | - ENTRY_REGRESSION, |
117 | | - regressionLabels.length ? regressionLabels.join(',') : '' |
118 | | - ); |
119 | | - formUrl.searchParams.set( |
120 | | - ENTRY_TEAM, |
121 | | - teamLabels.length ? teamLabels.join(',') : '' |
122 | | - ); |
123 | | -
|
124 | | - formUrl.searchParams.set(ENTRY_REPO_NAME, repo); |
125 | | - formUrl.searchParams.set(ENTRY_ISSUE_URL, `https://github.com/${owner}/${repo}/issues/${issue_number}`); |
126 | | -
|
127 | | - const assignees = issue.assignees.map(u=>`@${u.login}`).join(', '); |
128 | | - const body = `Hi ${assignees}, |
129 | | -
|
130 | | - This issue has been closed. Please complete this RCA form: |
131 | | - ${formUrl.toString()} |
132 | | -
|
133 | | - <!-- AUTO-FORM -->`; |
134 | | -
|
135 | | - await github.rest.issues.createComment({ |
136 | | - owner, repo, issue_number, body |
137 | | - }); |
138 | | - console.log(`✅ Comment posted on issue #${issue_number}`); |
139 | | -
|
140 | | - // Add the RCA-needed label |
141 | | - try { |
142 | | - await github.rest.issues.addLabels({ |
143 | | - owner, |
144 | | - repo, |
145 | | - issue_number: issue_number, |
146 | | - labels: ['RCA-needed'] |
147 | | - }); |
148 | | - console.log(`✅ Added 'RCA-needed' label on issue #${issue_number}`); |
149 | | - } catch (error) { |
150 | | - console.log(`⚠️ Could not add label: ${error.message}`); |
151 | | - } |
| 134 | + console.log(`✅ Added 'RCA-needed' label on issue #${issue_number}`); |
| 135 | + } catch (error) { |
| 136 | + console.log(`⚠️ Could not add label: ${error.message}`); |
| 137 | + } |
0 commit comments