Skip to content

Commit

Permalink
feat: add easy issue search to list cmd
Browse files Browse the repository at this point in the history
Adds the ability to provide an optional positional arg to search for text in issues.

It functions the same as searching via the search bar in the Jira web UI and is appended to any raw JQL query provided in the "-q" flag.
  • Loading branch information
wbh1 committed Aug 27, 2024
1 parent e418cc4 commit 223991d
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions internal/cmd/issue/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const (
You can combine different flags to create a unique query. For instance,
# Issues that are of high priority, is in progress, was created this month, and has given labels
jira issue list -yHigh -s"In Progress" --created month -lbackend -l"high prio"
$ jira issue list -yHigh -s"In Progress" --created month -lbackend -l"high prio"
You can also add an optional search query as a positional argument, which functions the same
as entering a search query into the Jira UI's search box.
Issues are displayed in an interactive list view by default. You can use a --plain flag
to display output in a plain text mode. A --no-headers flag will hide the table headers
Expand All @@ -34,6 +37,9 @@ $ jira issue list --paginate 20
# Get 50 items starting from 10
$ jira issue list --paginate 10:50
# Search for issues containing specific text
$ jira issue list "Feature Request"
# List issues in a plain table view without headers
$ jira issue list --plain --no-headers
Expand All @@ -56,21 +62,22 @@ $ jira issue list -q"project IS NOT EMPTY"`
// NewCmdList is a list command.
func NewCmdList() *cobra.Command {
return &cobra.Command{
Use: "list",
Use: "list [optional text to query]",
Short: "List lists issues in a project",
Long: helpText,
Example: examples,
Aliases: []string{"lists", "ls"},
Aliases: []string{"lists", "ls", "search"},
Args: cobra.RangeArgs(0, 1),
Run: List,
}
}

// List displays a list view.
func List(cmd *cobra.Command, _ []string) {
loadList(cmd)
func List(cmd *cobra.Command, args []string) {
loadList(cmd, args)
}

func loadList(cmd *cobra.Command) {
func loadList(cmd *cobra.Command, args []string) {
server := viper.GetString("server")
project := viper.GetString("project.key")

Expand All @@ -83,6 +90,17 @@ func loadList(cmd *cobra.Command) {
err = cmd.Flags().Set("parent", cmdutil.GetJiraIssueKey(project, pk))
cmdutil.ExitIfError(err)

if len(args) > 0 {
searchQuery := fmt.Sprintf(`text ~ "%s"`, strings.Join(args, " "))

jqlFlag, err := cmd.Flags().GetString("jql")
cmdutil.ExitIfError(err)
if len(jqlFlag) > 0 {
searchQuery = fmt.Sprintf(`%s AND %s`, jqlFlag, searchQuery)
}
cmdutil.ExitIfError(cmd.Flags().Set("jql", searchQuery))
}

issues, total, err := func() ([]*jira.Issue, int, error) {
s := cmdutil.Info("Fetching issues...")
defer s.Stop()
Expand Down Expand Up @@ -128,7 +146,7 @@ func loadList(cmd *cobra.Command) {
Total: total,
Data: issues,
Refresh: func() {
loadList(cmd)
loadList(cmd, args)
},
Display: view.DisplayFormat{
Plain: plain,
Expand Down

0 comments on commit 223991d

Please sign in to comment.