| 1154 | } |
| 1155 | |
| 1156 | async function assertPermissions() { |
| 1157 | // Only called for non-schedule events, so actor is defined |
| 1158 | console.log(`Asserting permissions for user ${actor}...`) |
| 1159 | |
| 1160 | let permission |
| 1161 | try { |
| 1162 | const response = await octoRest.repos.getCollaboratorPermissionLevel({ |
| 1163 | owner, |
| 1164 | repo, |
| 1165 | username: actor!, |
| 1166 | }) |
| 1167 | |
| 1168 | permission = response.data.permission |
| 1169 | console.log(` permission: ${permission}`) |
| 1170 | } catch (error) { |
| 1171 | console.error(`Failed to check permissions: ${error}`) |
| 1172 | throw new Error(`Failed to check permissions for user ${actor}: ${error}`, { cause: error }) |
| 1173 | } |
| 1174 | |
| 1175 | if (!["admin", "write"].includes(permission)) throw new Error(`User ${actor} does not have write permissions`) |
| 1176 | } |
| 1177 | |
| 1178 | async function addReaction(commentType?: "issue" | "pr_review") { |
| 1179 | // Only called for non-schedule events, so triggerCommentId is defined |