HasContentsReadAccess returns true if the permissions allow reading the repository contents. This is equivalent to PermissionsParser.HasContentsReadAccess but operates directly on the parsed Permissions struct to avoid redundant YAML parsing when CachedPermissions is available.
()
| 30 | // This is equivalent to PermissionsParser.HasContentsReadAccess but operates directly on the |
| 31 | // parsed Permissions struct to avoid redundant YAML parsing when CachedPermissions is available. |
| 32 | func (p *Permissions) HasContentsReadAccess() bool { |
| 33 | if p == nil { |
| 34 | return false |
| 35 | } |
| 36 | |
| 37 | if p.shorthand != "" { |
| 38 | switch p.shorthand { |
| 39 | case "read-all", "write-all": |
| 40 | return true |
| 41 | // "none" shorthand denies all access; any other unexpected value is also denied. |
| 42 | default: |
| 43 | return false |
| 44 | } |
| 45 | } |
| 46 | // all: write implies write-level access on every scope, which includes read access. |
| 47 | if p.hasAll && (p.allLevel == PermissionRead || p.allLevel == PermissionWrite) { |
| 48 | if contentsLevel, exists := p.permissions[PermissionContents]; exists { |
| 49 | return contentsLevel == PermissionRead || contentsLevel == PermissionWrite |
| 50 | } |
| 51 | return true |
| 52 | } |
| 53 | if contentsLevel, exists := p.permissions[PermissionContents]; exists { |
| 54 | return contentsLevel == PermissionRead || contentsLevel == PermissionWrite |
| 55 | } |
| 56 | return false |
| 57 | } |
| 58 | |
| 59 | // hasCopilotRequestsWritePermission returns true when workflow permissions include |
| 60 | // copilot-requests: write. This controls whether engines should use ${{ github.token }} |
no outgoing calls