-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: fetch all repositories for an org
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 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
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 | ||
} |