Skip to content

Commit

Permalink
Peribolos skip team repo if permissions invalid
Browse files Browse the repository at this point in the history
Peribolos will now skip updating a repo for a team if the
existing permission level for the team on the repo is 'none'.
This is to avoid overwriting any of the team's repos if the existing
permission level cannot be parsed, e.g. with new 'Triage' and 'Maintain'
levels not yet exposed by GitHub API v3.

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
  • Loading branch information
adshmh committed Oct 9, 2019
1 parent efb7475 commit e0656d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 9 additions & 3 deletions prow/cmd/peribolos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,15 @@ func configureTeamRepos(client teamRepoClient, githubTeams map[string]github.Tea

actions := map[string]github.RepoPermissionLevel{}
for wantRepo, wantPermission := range want {
if havePermission, haveRepo := have[wantRepo]; haveRepo && havePermission == wantPermission {
// nothing to do
continue
if havePermission, haveRepo := have[wantRepo]; haveRepo {
if havePermission == github.None {
logrus.Warnf("Cannot parse team %s permission level on repo %s. Skipping update", name, wantRepo)
continue
}
if havePermission == wantPermission {
// nothing to do
continue
}
}
// create or update this permission
actions[wantRepo] = wantPermission
Expand Down
18 changes: 18 additions & 0 deletions prow/cmd/peribolos/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,24 @@ func TestConfigureTeamRepos(t *testing.T) {
}},
expectedErr: true,
},
{
name: "skip updating a team repo if the the existing repo permission level is none",
githubTeams: map[string]github.Team{"team": {ID: 1}},
teamName: "team",
team: org.Team{
Repos: map[string]github.RepoPermissionLevel{
"none": github.Write,
"admin": github.Read,
},
},
existingRepos: map[int][]github.Repo{1: {
{Name: "none", Permissions: github.RepoPermissions{}},
}},
expected: map[int][]github.Repo{1: {
{Name: "none", Permissions: github.RepoPermissions{}},
{Name: "admin", Permissions: github.RepoPermissions{Pull: true}},
}},
},
}

for _, testCase := range testCases {
Expand Down

0 comments on commit e0656d8

Please sign in to comment.