Skip to content

Commit

Permalink
new: fetch all repositories for an org
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
  • Loading branch information
leodido committed Dec 11, 2020
1 parent 8c037ed commit 8500357
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions repositories.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"

"k8s.io/test-infra/prow/github"
)

// Repository represents the full name of a repo.
type Repository struct {
Org string
Repo string
}

func getRepositories(ghClient github.Client, org string) ([]Repository, error) {
repos := []Repository{}
// Obtain all the repositories in the organization
res, err := ghClient.GetRepos(org, false)
if err != nil {
return nil, fmt.Errorf("Unable to obtain GitHub repositories")
}
for _, v := range res {
// Ignore archived repositories
if v.Archived {
continue
}
// Ignore private repositories
if v.Private {
continue
}
repos = append(repos, Repository{
Org: org,
Repo: v.Name,
})
}
if len(repos) == 0 {
return nil, fmt.Errorf("Empty repository list")
}
return repos, nil
}

0 comments on commit 8500357

Please sign in to comment.