({
prId,
githubToken,
body,
noDuplicates,
}: CommentOnPRConfig)
| 234 | }; |
| 235 | |
| 236 | export async function commentOnPR({ |
| 237 | prId, |
| 238 | githubToken, |
| 239 | body, |
| 240 | noDuplicates, |
| 241 | }: CommentOnPRConfig) { |
| 242 | const isDuplicate = await isDuplicateComment({ |
| 243 | prId, |
| 244 | githubToken, |
| 245 | body, |
| 246 | }); |
| 247 | if (isDuplicate && noDuplicates) { |
| 248 | return body; |
| 249 | } |
| 250 | const response = await fetchWithRetries( |
| 251 | `https://api.github.com/repos/cloudflare/templates/issues/${prId}/comments`, |
| 252 | { |
| 253 | method: "POST", |
| 254 | headers: { |
| 255 | "Content-Type": "application/json", |
| 256 | Authorization: `Bearer ${githubToken}`, |
| 257 | Connection: "close", |
| 258 | }, |
| 259 | body: JSON.stringify({ |
| 260 | body, |
| 261 | }), |
| 262 | }, |
| 263 | ); |
| 264 | if (!response.ok) { |
| 265 | throw new Error( |
| 266 | `Error response from GitHub (${response.status}): ${await response.text()}`, |
| 267 | ); |
| 268 | } |
| 269 | return body; |
| 270 | } |
| 271 | |
| 272 | export async function isDuplicateComment({ |
| 273 | prId, |
no test coverage detected