(resultPath: string)
| 199 | // ---------- Action dispatch ---------- |
| 200 | |
| 201 | async function runActions(resultPath: string) { |
| 202 | let { prNumber, actions } = JSON.parse( |
| 203 | fs.readFileSync(resultPath, "utf8"), |
| 204 | ) as { prNumber: number; actions: Action[] }; |
| 205 | |
| 206 | if (actions.length === 0) { |
| 207 | console.log("No actions to apply"); |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | for (let action of actions) { |
| 212 | switch (action.type) { |
| 213 | case "upsert-sticky-comment": { |
| 214 | let comments = await getPrComments(prNumber); |
| 215 | let existing = comments.find( |
| 216 | (c) => |
| 217 | c.user?.login === "github-actions[bot]" && |
| 218 | c.body?.includes(action.marker), |
| 219 | ); |
| 220 | if (existing) { |
| 221 | console.log(`Updating sticky comment #${existing.id}`); |
| 222 | await updatePrComment(existing.id, action.body); |
| 223 | } else { |
| 224 | console.log("Creating sticky comment"); |
| 225 | await createPrComment(prNumber, action.body); |
| 226 | } |
| 227 | return; |
| 228 | } |
| 229 | case "create-comment": { |
| 230 | console.log("Creating comment"); |
| 231 | await createPrComment(prNumber, action.body); |
| 232 | return; |
| 233 | } |
| 234 | case "remove-label": { |
| 235 | console.log(`Removing label '${action.label}'`); |
| 236 | await removePrLabel(prNumber, action.label); |
| 237 | return; |
| 238 | } |
| 239 | case "close-pr": { |
| 240 | console.log(`Closing PR ${prNumber}`); |
| 241 | await closePr(prNumber); |
| 242 | return; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // Utils |
| 249 |
no test coverage detected