Skip to content

Commit 6462b0d

Browse files
authored
feat: Add easy issue search to list cmd (#769)
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.
1 parent 833172c commit 6462b0d

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

internal/cmd/issue/list/list.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ const (
2020
You can combine different flags to create a unique query. For instance,
2121
2222
# Issues that are of high priority, is in progress, was created this month, and has given labels
23-
jira issue list -yHigh -s"In Progress" --created month -lbackend -l"high prio"
23+
$ jira issue list -yHigh -s"In Progress" --created month -lbackend -l"high prio"
24+
25+
You can also add an optional search query as a positional argument, which functions the same
26+
as entering a search query into the Jira UI's search box.
2427
2528
Issues are displayed in an interactive list view by default. You can use a --plain flag
2629
to display output in a plain text mode. A --no-headers flag will hide the table headers
@@ -34,6 +37,9 @@ $ jira issue list --paginate 20
3437
# Get 50 items starting from 10
3538
$ jira issue list --paginate 10:50
3639
40+
# Search for issues containing specific text
41+
$ jira issue list "Feature Request"
42+
3743
# List issues in a plain table view without headers
3844
$ jira issue list --plain --no-headers
3945
@@ -56,21 +62,22 @@ $ jira issue list -q"project IS NOT EMPTY"`
5662
// NewCmdList is a list command.
5763
func NewCmdList() *cobra.Command {
5864
return &cobra.Command{
59-
Use: "list",
65+
Use: "list [optional text to query]",
6066
Short: "List lists issues in a project",
6167
Long: helpText,
6268
Example: examples,
63-
Aliases: []string{"lists", "ls"},
69+
Aliases: []string{"lists", "ls", "search"},
70+
Args: cobra.RangeArgs(0, 1),
6471
Run: List,
6572
}
6673
}
6774

6875
// List displays a list view.
69-
func List(cmd *cobra.Command, _ []string) {
70-
loadList(cmd)
76+
func List(cmd *cobra.Command, args []string) {
77+
loadList(cmd, args)
7178
}
7279

73-
func loadList(cmd *cobra.Command) {
80+
func loadList(cmd *cobra.Command, args []string) {
7481
server := viper.GetString("server")
7582
project := viper.GetString("project.key")
7683

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

93+
if len(args) > 0 {
94+
searchQuery := fmt.Sprintf(`text ~ "%s"`, strings.Join(args, " "))
95+
96+
jqlFlag, err := cmd.Flags().GetString("jql")
97+
cmdutil.ExitIfError(err)
98+
if len(jqlFlag) > 0 {
99+
searchQuery = fmt.Sprintf(`%s AND %s`, jqlFlag, searchQuery)
100+
}
101+
cmdutil.ExitIfError(cmd.Flags().Set("jql", searchQuery))
102+
}
103+
86104
issues, total, err := func() ([]*jira.Issue, int, error) {
87105
s := cmdutil.Info("Fetching issues...")
88106
defer s.Stop()
@@ -128,7 +146,7 @@ func loadList(cmd *cobra.Command) {
128146
Total: total,
129147
Data: issues,
130148
Refresh: func() {
131-
loadList(cmd)
149+
loadList(cmd, args)
132150
},
133151
Display: view.DisplayFormat{
134152
Plain: plain,

0 commit comments

Comments
 (0)