Skip to content

Commit

Permalink
Issue list can be filtered by state
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas committed Dec 29, 2023
1 parent ade7539 commit 43aae4f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/issue/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package issue

import (
"fmt"

"bitbucket.org/gildas_cherruel/bb/cmd/common"
"bitbucket.org/gildas_cherruel/bb/cmd/profile"
"github.com/gildas/go-errors"
"github.com/gildas/go-logger"
Expand All @@ -16,12 +19,15 @@ var listCmd = &cobra.Command{

var listOptions struct {
Repository string
State common.EnumFlag
}

func init() {
Command.AddCommand(listCmd)

listOptions.State = common.EnumFlag{Allowed: []string{"all", "closed", "duplicate", "invalid", "on hold", "new", "open", "resolved", "submitted", "wontfix"}, Value: "all"}
listCmd.Flags().StringVar(&listOptions.Repository, "repository", "", "Repository to list issues from. Defaults to the current repository")
listCmd.Flags().Var(&listOptions.State, "state", "State of the issues to list")
}

func listProcess(cmd *cobra.Command, args []string) (err error) {
Expand All @@ -31,8 +37,13 @@ func listProcess(cmd *cobra.Command, args []string) (err error) {
return errors.ArgumentMissing.With("profile")
}

filter := ""
if listOptions.State.Value != "all" {
filter = fmt.Sprintf(`?q=state="%s"`, listOptions.State.Value)
}

log.Infof("Listing all issues from repository %s with profile %s", listOptions.Repository, profile.Current)
issues, err := profile.GetAll[Issue](cmd.Context(), cmd, profile.Current, "issues")
issues, err := profile.GetAll[Issue](cmd.Context(), cmd, profile.Current, "issues"+filter)
if err != nil {
return err
}
Expand Down

0 comments on commit 43aae4f

Please sign in to comment.