checkPermission rejects a permission that cannot upload. It is an allowlist, so an unlisted value is rejected rather than sent.
(viewerPermission string)
| 71 | // checkPermission rejects a permission that cannot upload. It is an allowlist, |
| 72 | // so an unlisted value is rejected rather than sent. |
| 73 | func checkPermission(viewerPermission string) error { |
| 74 | // GraphQL has no viewerPermission for a GitHub App installation, so an |
| 75 | // empty one is left to the endpoint rather than refused. |
| 76 | if viewerPermission == "" { |
| 77 | return nil |
| 78 | } |
| 79 | |
| 80 | if slices.Contains(uploadPermissions, viewerPermission) { |
| 81 | return nil |
| 82 | } |
| 83 | return errors.New("attaching files requires write access to the repository") |
| 84 | } |
| 85 | |
| 86 | // upload sends the file's bytes and returns the asset URL to reference |
| 87 | // from the markdown. |