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