Skip to content

Commit

Permalink
address comments from PR #62
Browse files Browse the repository at this point in the history
  • Loading branch information
jspiro authored and mszostok committed Jan 21, 2021
1 parent 9224144 commit 204640e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions internal/check/valid_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,20 @@ func (v *ValidOwner) validateTeam(ctx context.Context, name string) *validateErr
}

// repo contains the permissions for the team slug given
// TODO(mszostok): Switch to GraphQL API, see:
// https://github.com/mszostok/codeowners-validator/pull/62#discussion_r561273525
repo, _, err := v.ghClient.Teams.IsTeamRepoBySlug(ctx, v.orgName, team, org, v.orgRepoName)
if err != nil { // TODO(mszostok): implement retry?
switch err := err.(type) {
case *github.ErrorResponse:
if err.Response.StatusCode == http.StatusUnauthorized {
return newValidateError("Team permissions information for %q/%q could not be queried. Requires GitHub authorization.", org, v.orgRepoName)
return newValidateError(
"Team permissions information for %q/%q could not be queried. Requires GitHub authorization.",
org, v.orgRepoName)
} else if err.Response.StatusCode == http.StatusNotFound {
return newValidateError("Team %q does not have permissions associated with the repository %q.", team, v.orgRepoName)
return newValidateError(
"Team %q does not have permissions associated with the repository %q.",
team, v.orgRepoName)
} else {
return newValidateError("HTTP error occurred while calling GitHub: %v", err)
}
Expand All @@ -215,29 +221,30 @@ func (v *ValidOwner) validateTeam(ctx context.Context, name string) *validateErr
}

teamHasWritePermission := func() bool {
for k, v := range *repo.Permissions {
if v == false {
for k, v := range repo.GetPermissions() {
if !v {
continue
}

switch k {
case
"admin",
"maintain",
"push",
"triage":
"push":
return true
case
"pull":
continue
"pull",
"triage":
}
}

return false
}

if !teamHasWritePermission() {
return newValidateError("Team %q cannot review PRs on %q.", team, v.orgRepoName)
return newValidateError(
"Team %q cannot review PRs on %q as neither it nor any parent team does not have write permissions.",
team, v.orgRepoName)
}

return nil
Expand Down

0 comments on commit 204640e

Please sign in to comment.