-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for custom roles * Fix doc * Fix wrong comment
- Loading branch information
1 parent
45dd0fc
commit b7ac9cb
Showing
5 changed files
with
19 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,21 @@ | ||
package github | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/google/go-github/v48/github" | ||
) | ||
|
||
const ( | ||
pullPermission string = "pull" | ||
triagePermission string = "triage" | ||
pushPermission string = "push" | ||
maintainPermission string = "maintain" | ||
adminPermission string = "admin" | ||
writePermission string = "write" | ||
readPermission string = "read" | ||
pullPermission string = "pull" | ||
pushPermission string = "push" | ||
writePermission string = "write" | ||
readPermission string = "read" | ||
) | ||
|
||
func getRepoPermission(p map[string]bool) (string, error) { | ||
|
||
// Permissions are returned in this map format such that if you have a certain level | ||
// of permission, all levels below are also true. For example, if a team has push | ||
// permission, the map will be: {"pull": true, "push": true, "admin": false} | ||
if (p)[adminPermission] { | ||
return adminPermission, nil | ||
} else if (p)[maintainPermission] { | ||
return maintainPermission, nil | ||
} else if (p)[pushPermission] { | ||
return pushPermission, nil | ||
} else if (p)[triagePermission] { | ||
return triagePermission, nil | ||
} else { | ||
if (p)[pullPermission] { | ||
return pullPermission, nil | ||
} | ||
return "", errors.New("at least one permission expected from permissions map") | ||
} | ||
} | ||
|
||
func getInvitationPermission(i *github.RepositoryInvitation) (string, error) { | ||
func getPermission(permission string) string { | ||
// Permissions for some GitHub API routes are expressed as "read", | ||
// "write", and "admin"; in other places, they are expressed as "pull", | ||
// "push", and "admin". | ||
permissions := i.GetPermissions() | ||
if permissions == readPermission { | ||
return pullPermission, nil | ||
} else if permissions == writePermission { | ||
return pushPermission, nil | ||
} else if permissions == adminPermission { | ||
return adminPermission, nil | ||
} else if *i.Permissions == maintainPermission { | ||
return maintainPermission, nil | ||
} else if *i.Permissions == triagePermission { | ||
return triagePermission, nil | ||
if permission == readPermission { | ||
return pullPermission | ||
} else if permission == writePermission { | ||
return pushPermission | ||
} | ||
|
||
return "", fmt.Errorf("unexpected permission value: %v", permissions) | ||
return permission | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters