Skip to content

Commit

Permalink
Merge pull request #4 from csdev/filter-orgs
Browse files Browse the repository at this point in the history
feat: select repos by organization
  • Loading branch information
csdev committed May 1, 2023
2 parents 5df240c + a6ea4d9 commit e4596d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/ezghsa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func main() {
closed bool

ownerRepoNames []string
org string
)

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

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

flag.CommandLine.SortFlags = false

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

fmt.Fprintf(os.Stderr, usage, os.Args[0], os.Args[0])
fmt.Fprintf(os.Stderr, usage, os.Args[0], os.Args[0], os.Args[0])
flag.PrintDefaults()
}

Expand All @@ -113,6 +116,12 @@ func main() {
return
}

if flag.CommandLine.Changed("repo") && flag.CommandLine.Changed("org") {
fmt.Fprintln(os.Stderr, "--repo and --org are mutually exclusive flags")
flag.Usage()
os.Exit(1)
}

if flag.NArg() > 0 {
flag.Usage()
os.Exit(1)
Expand All @@ -127,6 +136,12 @@ func main() {
if err != nil {
log.Fatalf("error getting repositories: %v", err)
}
} else if org != "" {
var err error
repos, err = app.GetOrgRepos(org)
if err != nil {
log.Fatalf("error getting repositories for the organization %s: %v", org, err)
}
} else {
var err error
repos, err = app.GetMyRepos()
Expand Down
8 changes: 8 additions & 0 deletions internal/ezghsa/ezghsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ func (app *App) GetRepos(ownerRepoNames []string) ([]*github.Repository, error)
return repos, nil
}

func (app *App) GetOrgRepos(org string) ([]*github.Repository, error) {
opts := &github.RepositoryListByOrgOptions{
Type: "all",
}
repos, _, err := app.client.Repositories.ListByOrg(context.Background(), org, opts)
return repos, err
}

func (app *App) CheckAlertsEnabled(ownerName string, repoName string) (bool, error) {
isEnabled, _, err := app.client.Repositories.GetVulnerabilityAlerts(
context.Background(), ownerName, repoName)
Expand Down

0 comments on commit e4596d1

Please sign in to comment.