Skip to content

Commit

Permalink
issue list - filter by issue type
Browse files Browse the repository at this point in the history
  • Loading branch information
3ximus committed Mar 1, 2024
1 parent 98c3421 commit b4dee81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions api/jira-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -130,14 +130,27 @@ 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))
}
}
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 {
Expand Down
30 changes: 26 additions & 4 deletions cmd/issue/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ 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")
reporter, _ := cmd.Flags().GetBool("reporter")
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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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
}

0 comments on commit b4dee81

Please sign in to comment.