Skip to content

Commit e4596d1

Browse files
authored
Merge pull request #4 from csdev/filter-orgs
feat: select repos by organization
2 parents 5df240c + a6ea4d9 commit e4596d1

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

cmd/ezghsa/main.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func main() {
6868
closed bool
6969

7070
ownerRepoNames []string
71+
org string
7172
)
7273

7374
flag.BoolVarP(&help, "help", "h", help, "display this help text")
@@ -85,14 +86,16 @@ func main() {
8586
flag.BoolVar(&closed, "closed", closed, "include closed alerts")
8687

8788
flag.StringSliceVarP(&ownerRepoNames, "repo", "r", ownerRepoNames, "comma-separated list of repos to check, in OWNER/REPO format")
89+
flag.StringVarP(&org, "org", "o", org, "check all repos belonging to the specified organization")
8890

8991
flag.CommandLine.SortFlags = false
9092

9193
flag.Usage = func() {
9294
const usage = "Usage: %s [options]\n" +
93-
" %s [options] --repo OWNER/REPO[,...]\n"
95+
" %s [options] --repo OWNER/REPO[,...]\n" +
96+
" %s [options] --org ORGANIZATION\n\n"
9497

95-
fmt.Fprintf(os.Stderr, usage, os.Args[0], os.Args[0])
98+
fmt.Fprintf(os.Stderr, usage, os.Args[0], os.Args[0], os.Args[0])
9699
flag.PrintDefaults()
97100
}
98101

@@ -113,6 +116,12 @@ func main() {
113116
return
114117
}
115118

119+
if flag.CommandLine.Changed("repo") && flag.CommandLine.Changed("org") {
120+
fmt.Fprintln(os.Stderr, "--repo and --org are mutually exclusive flags")
121+
flag.Usage()
122+
os.Exit(1)
123+
}
124+
116125
if flag.NArg() > 0 {
117126
flag.Usage()
118127
os.Exit(1)
@@ -127,6 +136,12 @@ func main() {
127136
if err != nil {
128137
log.Fatalf("error getting repositories: %v", err)
129138
}
139+
} else if org != "" {
140+
var err error
141+
repos, err = app.GetOrgRepos(org)
142+
if err != nil {
143+
log.Fatalf("error getting repositories for the organization %s: %v", org, err)
144+
}
130145
} else {
131146
var err error
132147
repos, err = app.GetMyRepos()

internal/ezghsa/ezghsa.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ func (app *App) GetRepos(ownerRepoNames []string) ([]*github.Repository, error)
124124
return repos, nil
125125
}
126126

127+
func (app *App) GetOrgRepos(org string) ([]*github.Repository, error) {
128+
opts := &github.RepositoryListByOrgOptions{
129+
Type: "all",
130+
}
131+
repos, _, err := app.client.Repositories.ListByOrg(context.Background(), org, opts)
132+
return repos, err
133+
}
134+
127135
func (app *App) CheckAlertsEnabled(ownerName string, repoName string) (bool, error) {
128136
isEnabled, _, err := app.client.Repositories.GetVulnerabilityAlerts(
129137
context.Background(), ownerName, repoName)

0 commit comments

Comments
 (0)