From b4dee8131ede050816f1ac873f891ec508a25298 Mon Sep 17 00:00:00 2001 From: eximus Date: Fri, 1 Mar 2024 14:09:37 -0500 Subject: [PATCH] issue list - filter by issue type --- README.md | 2 ++ api/jira-api.go | 17 +++++++++++++++-- cmd/issue/list.go | 30 ++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9a1ab45..e0861e3 100644 --- a/README.md +++ b/README.md @@ -79,5 +79,7 @@ bb help [COMMAND] ## TODO +- issue list - add way to sort by recent or the ones the user has participated on +- issue log - is broken, and doesn't use current branch as issue key - View/Edit issue checklist diff --git a/api/jira-api.go b/api/jira-api.go index aa3e1c5..aa4d2d8 100644 --- a/api/jira-api.go +++ b/api/jira-api.go @@ -99,7 +99,7 @@ func GetIssue(key string) <-chan JiraIssue { return channel } -func GetIssueList(nResults int, all bool, reporter bool, project string, statuses []string, searchTerm string, prioritySort bool) <-chan JiraIssue { +func GetIssueList(nResults int, all bool, reporter bool, project string, statuses []string, types []string, searchTerm string, prioritySort bool) <-chan JiraIssue { channel := make(chan JiraIssue) go func() { defer close(channel) @@ -130,7 +130,6 @@ func GetIssueList(nResults int, all bool, reporter bool, project string, statuse query += "(" for i, s := range statuses { if i == 0 { - // TODO improve this and use a configurable viper settings to map status query += fmt.Sprintf("status=\"%s\"", url.QueryEscape(s)) } else { query += fmt.Sprintf("+OR+status=\"%s\"", url.QueryEscape(s)) @@ -138,6 +137,20 @@ func GetIssueList(nResults int, all bool, reporter bool, project string, statuse } query += ")" } + if len(types) > 0 { + if query != "" { + query += "+AND+" + } + query += "(" + for i, s := range types { + if i == 0 { + query += fmt.Sprintf("type=\"%s\"", url.QueryEscape(s)) + } else { + query += fmt.Sprintf("+OR+type=\"%s\"", url.QueryEscape(s)) + } + } + query += ")" + } if prioritySort { query += "+order+by+priority+desc,status+asc" } else { diff --git a/cmd/issue/list.go b/cmd/issue/list.go index 9eec7c9..e508756 100644 --- a/cmd/issue/list.go +++ b/cmd/issue/list.go @@ -18,7 +18,7 @@ var ListCmd = &cobra.Command{ Given an argument it will filter tickets from that project. Otherwise it will try to derive the project name from the branch name. If all is given then project filtering is not applied `, - Args: cobra.MaximumNArgs(1), + Args: cobra.MaximumNArgs(1), Example: "list DP --search ", Run: func(cmd *cobra.Command, args []string) { nResults, _ := cmd.Flags().GetInt("number-results") @@ -26,6 +26,7 @@ var ListCmd = &cobra.Command{ all, _ := cmd.Flags().GetBool("all") search, _ := cmd.Flags().GetString("search") statuses, _ := cmd.Flags().GetStringArray("status") + iTypes, _ := cmd.Flags().GetStringArray("type") priority, _ := cmd.Flags().GetBool("priority") showUsers, _ := cmd.Flags().GetBool("users") showTime, _ := cmd.Flags().GetBool("time") @@ -58,7 +59,18 @@ var ListCmd = &cobra.Command{ } } - for issue := range api.GetIssueList(nResults, all, reporter, project, statusConversion, search, priority) { + // convert type based on current settings + var typeConversion = []string{} + for _, s := range iTypes { + typesMap, err := util.GetConfig("jira_type", s) + if err == nil { + typeConversion = append(typeConversion, typesMap.Values...) + } else { + typeConversion = append(typeConversion, s) + } + } + + for issue := range api.GetIssueList(nResults, all, reporter, project, statusConversion, typeConversion, search, priority) { timeSpent := "-" if issue.Fields.TimeTracking.TimeSpent != " " { timeSpent = issue.Fields.TimeTracking.TimeSpent @@ -87,10 +99,11 @@ func init() { ListCmd.Flags().StringArrayP("status", "s", []string{}, `filter status type. this option will provide completion for the mappings defined in "jira_status" of your config file`) ListCmd.RegisterFlagCompletionFunc("status", statusCompletion) + ListCmd.Flags().StringArray("type", []string{}, `filter issue type. + this option will provide completion for the mappings defined in "jira_type" of your config file`) + ListCmd.RegisterFlagCompletionFunc("type", typeCompletion) ListCmd.Flags().String("search", "", "filter issues by keyword") - // TODO add way to sort by recent or the ones the user has participated on - // display ListCmd.Flags().BoolP("users", "u", false, "show users") ListCmd.Flags().BoolP("time", "t", false, "show time information") @@ -107,3 +120,12 @@ func statusCompletion(comd *cobra.Command, args []string, toComplete string) ([] } return status, cobra.ShellCompDirectiveDefault } + +func typeCompletion(comd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + issueTypeMap := viper.GetStringMapStringSlice("jira_type") + issueType := make([]string, 0, len(issueTypeMap)) + for k := range issueTypeMap { + issueType = append(issueType, k) + } + return issueType, cobra.ShellCompDirectiveDefault +}