diff --git a/pkg/cli/cmd.go b/pkg/cli/cmd.go index 338b7d6..58a2bb3 100644 --- a/pkg/cli/cmd.go +++ b/pkg/cli/cmd.go @@ -30,7 +30,7 @@ func NewRootCommand() *cobra.Command { } func NewListCommand() *cobra.Command { - return &cobra.Command{ + listCmd := &cobra.Command{ Use: "list", Short: "list partecipants", Args: UserRepoArg(), @@ -41,12 +41,14 @@ func NewListCommand() *cobra.Command { user, repo := userRepo[0], userRepo[1] client := github.NewClient(nil) - allIssues, err := raffle.GetAllIssues(client, user, repo) + + labels, _ := cmd.Flags().GetStringSlice("label") + issues, err := raffle.GetIssues(client, user, repo, labels) if err != nil { return err } - users := raffle.GetUsersFromIssues(allIssues) + users := raffle.GetUsersFromIssues(issues) sort.Strings(users) fmt.Printf("There are %d partecipants:\n", len(users)) @@ -58,10 +60,14 @@ func NewListCommand() *cobra.Command { return nil }, } + + listCmd.Flags().StringSlice("label", []string{}, "labels") + + return listCmd } func NewRunCommand() *cobra.Command { - return &cobra.Command{ + runCmd := &cobra.Command{ Use: "run", Short: "run raffle", Args: UserRepoArg(), @@ -72,12 +78,14 @@ func NewRunCommand() *cobra.Command { user, repo := userRepo[0], userRepo[1] client := github.NewClient(nil) - allIssues, err := raffle.GetAllIssues(client, user, repo) + + labels, _ := cmd.Flags().GetStringSlice("label") + issues, err := raffle.GetIssues(client, user, repo, labels) if err != nil { return err } - users := raffle.GetUsersFromIssues(allIssues) + users := raffle.GetUsersFromIssues(issues) rand.Seed(time.Now().UnixNano()) rand.Shuffle(len(users), func(i, j int) { @@ -87,6 +95,10 @@ func NewRunCommand() *cobra.Command { return nil }, } + + runCmd.Flags().StringSlice("label", []string{}, "labels") + + return runCmd } func UserRepoArg() cobra.PositionalArgs { diff --git a/pkg/raffle/raffle.go b/pkg/raffle/raffle.go index 1a1ca96..ce5c49d 100644 --- a/pkg/raffle/raffle.go +++ b/pkg/raffle/raffle.go @@ -6,9 +6,10 @@ import ( "github.com/google/go-github/v45/github" ) -func GetAllIssues(client *github.Client, user, repo string) ([]*github.Issue, error) { +func GetIssues(client *github.Client, user, repo string, labels []string) ([]*github.Issue, error) { opt := &github.IssueListByRepoOptions{ ListOptions: github.ListOptions{PerPage: 50}, + Labels: labels, } var allIssues []*github.Issue