Skip to content

Commit

Permalink
issue list - ability to filter issues by status in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
3ximus committed Feb 25, 2024
1 parent 30c8c88 commit ac24dc7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cmd/issue/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/spf13/viper"
)

// TODO add a default status listing on the config file

var ListCmd = &cobra.Command{
Use: "list",
Short: "List issues",
Expand Down Expand Up @@ -43,12 +41,10 @@ var ListCmd = &cobra.Command{

// convert status based on current settings
var statusConversion = []string{}
statusMap := viper.GetStringMapStringSlice("jira_status")
for _, s := range statuses {
if val, exists := statusMap[s]; exists {
for _, k := range val {
statusConversion = append(statusConversion, k)
}
statusMap, err := util.GetConfig("jira_status", s)
if err == nil {
statusConversion = append(statusConversion, statusMap.Values...)
} else {
statusConversion = append(statusConversion, s)
}
Expand Down Expand Up @@ -78,13 +74,12 @@ var ListCmd = &cobra.Command{
}

func init() {
// filters
ListCmd.Flags().StringP("project", "p", "", `filter issues by project key.
If "all" is given it shows all projects (when a project is detected on current branch and you still want to show all projects)`)
ListCmd.Flags().BoolP("all", "a", false, "filter all issues. (Not assigned or reporting to current user)")
ListCmd.Flags().BoolP("reporter", "r", false, "filter issues reporting to current user")
ListCmd.Flags().StringArrayP("status", "s", []string{}, `filter status type.
possible options: "open", "todo", "inprogress", "testing", "done", "blocked"`)
this option will provide completion for the mappings defined in "jira_status" of your config file`)
ListCmd.RegisterFlagCompletionFunc("status", statusCompletion)

// TODO add way to sort by recent or the ones the user has participated on
Expand All @@ -98,5 +93,10 @@ func init() {
}

func statusCompletion(comd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"open", "todo", "inprogress", "testing", "done", "blocked"}, cobra.ShellCompDirectiveDefault
statusMap := viper.GetStringMapStringSlice("jira_status")
status := make([]string, 0, len(statusMap))
for k:=range statusMap {
status = append(status, k)
}
return status, cobra.ShellCompDirectiveDefault
}
15 changes: 15 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package util

import (
"bb/api"
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -45,6 +46,20 @@ func FormatSwitchConfig(result string, mapping map[string]ResultSwitchConfig) st
return str
}

/* Returns the config switch config */
func GetConfig(configKey string, key string) (ResultSwitchConfig, error) {
mapping := make(map[string]ResultSwitchConfig)
if err := viper.UnmarshalKey(configKey, &mapping); err != nil {
cobra.CheckErr(err)
}
for k, v := range mapping {
if k == key {
return v, nil
}
}
return ResultSwitchConfig{}, errors.New(fmt.Sprintf("Config key not found: '%s'", configKey))
}

func FormatPrState(state api.PrState) string {
prStatusMap := make(map[string]ResultSwitchConfig)
if err := viper.UnmarshalKey("pr_status", &prStatusMap); err != nil {
Expand Down

0 comments on commit ac24dc7

Please sign in to comment.