Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peribolos skip team repo if permissions invalid #14677

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion prow/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2613,7 +2613,11 @@ func (c *client) ListTeamRepos(id int) ([]Repo, error) {
return &[]Repo{}
},
func(obj interface{}) {
repos = append(repos, *(obj.(*[]Repo))...)
for _, repo := range *obj.(*[]Repo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece of logic needs a code comment explaining why we are doing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review, and sorry I missed this bit that was pending me. I could not reopen the PR, so I will create a new one.

if LevelFromPermissions(repo.Permissions) != None {
repos = append(repos, repo)
}
}
},
)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions prow/github/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1970,3 +1970,27 @@ func TestCombinedStatus(t *testing.T) {
t.Errorf("Wrong review IDs: %v", combined.Statuses)
}
}

func TestListTeamRepos(t *testing.T) {
ts := simpleTestServer(t, "/teams/1/repos",
[]Repo{
{
Name: "repo-bar",
Permissions: RepoPermissions{Pull: true},
},
{
Name: "repo-invalid-permission-level",
},
},
)
defer ts.Close()
c := getClient(ts.URL)
repos, err := c.ListTeamRepos(1)
if err != nil {
t.Errorf("Didn't expect error: %v", err)
} else if len(repos) != 1 {
t.Errorf("Expected one repo, found %d: %v", len(repos), repos)
} else if repos[0].Name != "repo-bar" {
t.Errorf("Wrong repos: %v", repos)
}
}