()
| 765 | } |
| 766 | |
| 767 | async function assertPermissions() { |
| 768 | const { actor, repo } = useContext() |
| 769 | |
| 770 | console.log(`Asserting permissions for user ${actor}...`) |
| 771 | |
| 772 | if (useEnvGithubToken()) { |
| 773 | console.log(" skipped (using github token)") |
| 774 | return |
| 775 | } |
| 776 | |
| 777 | let permission |
| 778 | try { |
| 779 | const response = await octoRest.repos.getCollaboratorPermissionLevel({ |
| 780 | owner: repo.owner, |
| 781 | repo: repo.repo, |
| 782 | username: actor, |
| 783 | }) |
| 784 | |
| 785 | permission = response.data.permission |
| 786 | console.log(` permission: ${permission}`) |
| 787 | } catch (error) { |
| 788 | console.error(`Failed to check permissions: ${error}`) |
| 789 | throw new Error(`Failed to check permissions for user ${actor}: ${error}`, { cause: error }) |
| 790 | } |
| 791 | |
| 792 | if (!["admin", "write"].includes(permission)) throw new Error(`User ${actor} does not have write permissions`) |
| 793 | } |
| 794 | |
| 795 | async function updateComment(body: string) { |
| 796 | if (!commentId) return |
no test coverage detected