Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add easy issue search to list cmd #769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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