From 001c803e2b741344b9c7bc29ecf51dc3cceda590 Mon Sep 17 00:00:00 2001 From: Dawid Ciepiela <71898979-sarumaj@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:21:58 +0000 Subject: [PATCH] review and fix index issue --- pkg/commands/command_pr.go | 38 ++++++++++++++-------------- pkg/configfile/configuration_util.go | 8 +++--- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pkg/commands/command_pr.go b/pkg/commands/command_pr.go index a2c68fe..7c05234 100644 --- a/pkg/commands/command_pr.go +++ b/pkg/commands/command_pr.go @@ -22,6 +22,7 @@ var prFlags struct { closedInLast time.Duration closedAfterLast time.Duration customQuery string + searchQuery bool head string state string assignees []string @@ -84,6 +85,7 @@ var prCmd = func() *cobra.Command { flags.DurationVar(&prFlags.closedInLast, "closed-in-last", 0, "Filter pull requests closed in the last time window") flags.DurationVar(&prFlags.closedAfterLast, "closed-after-last", 0, "Filter pull requests closed after the last time window") flags.StringVar(&prFlags.customQuery, "query", "", "Custom query to filter pull requests") + flags.BoolVar(&prFlags.searchQuery, "search", false, "Use search API to filter pull requests") flags.StringVar(&prFlags.head, "head", "", "Filter pull requests by head user or head org in the format \"user:ref-name\" or \"organization:ref-name\"") flags.StringArrayVar(&prFlags.assignees, "assignee", []string{}, "Glob pattern(s) to filter pull request assignees") flags.StringArrayVar(&prFlags.authors, "author", []string{}, "Glob pattern(s) to filter pull request authors") @@ -102,72 +104,70 @@ type pullRequestAction func(*restclient.RESTClient) func(context.Context, string // buildPullSearchQuery builds a search query for pull requests. func buildPullSearchQuery() map[string]string { var fragments []string - var useCustomQuery bool filter := make(map[string]string) if prFlags.base != "" { filter["base"] = prFlags.base - fragments = append(fragments, fmt.Sprintf("base:%s", prFlags.base)) + if prFlags.searchQuery { + fragments = append(fragments, fmt.Sprintf("base:%s", prFlags.base)) + } } if prFlags.head != "" { filter["head"] = prFlags.head - fragments = append(fragments, fmt.Sprintf("head:%s", prFlags.head)) + if prFlags.searchQuery { + fragments = append(fragments, fmt.Sprintf("head:%s", prFlags.head)) + } } - if prFlags.closedInLast > 0 { - useCustomQuery = true + if prFlags.closedInLast > 0 && prFlags.searchQuery { fragments = append(fragments, fmt.Sprintf("closed:>=%s", time.Now().Add(-prFlags.closedInLast).Format("2006-01-02T15:04:05Z"))) } - if prFlags.closedAfterLast > 0 { - useCustomQuery = true + if prFlags.closedAfterLast > 0 && prFlags.searchQuery { fragments = append(fragments, fmt.Sprintf("closed:<=%s", time.Now().Add(-prFlags.closedAfterLast).Format("2006-01-02T15:04:05Z"))) } for _, assignee := range prFlags.assignees { - if util.IsGlobMatch(assignee) { + if !prFlags.searchQuery { continue } - useCustomQuery = true fragments = append(fragments, fmt.Sprintf("assignee:%s", assignee)) } for _, author := range prFlags.authors { - if util.IsGlobMatch(author) { + if !prFlags.searchQuery { continue } - useCustomQuery = true fragments = append(fragments, fmt.Sprintf("author:%s", author)) } for _, label := range prFlags.labels { - if util.IsGlobMatch(label) { + if !prFlags.searchQuery { continue } - useCustomQuery = true fragments = append(fragments, fmt.Sprintf("label:%s", label)) } for _, title := range prFlags.titles { - if util.IsGlobMatch(title) || util.IsRegex(title) { + if !prFlags.searchQuery { continue } - useCustomQuery = true fragments = append(fragments, fmt.Sprintf("%s in:title", title)) } if prFlags.state != "" { filter["state"] = prFlags.state - fragments = append(fragments, fmt.Sprintf("state:%s", prFlags.state)) + if prFlags.searchQuery { + fragments = append(fragments, fmt.Sprintf("state:%s", prFlags.state)) + } } - if prFlags.customQuery != "" { - useCustomQuery = true + if prFlags.searchQuery && prFlags.customQuery != "" { fragments = append(fragments, prFlags.customQuery) } - if useCustomQuery { + if prFlags.searchQuery && len(fragments) > 0 { return map[string]string{"q": strings.Join(fragments, " ")} } diff --git a/pkg/configfile/configuration_util.go b/pkg/configfile/configuration_util.go index 5494a5d..2954958 100644 --- a/pkg/configfile/configuration_util.go +++ b/pkg/configfile/configuration_util.go @@ -82,6 +82,10 @@ func OpenLins(links []string) { c := util.Console() client := browser.New("", c.Stdout(), c.Stderr()) for { + if supererrors.LastErrorWas(terminal.InterruptErr) || len(links) == 0 { + os.Exit(0) + } + choice := supererrors.ExceptFn(supererrors.W( prompt.Select( "Select a link to open:", @@ -90,10 +94,6 @@ func OpenLins(links []string) { ), ), terminal.InterruptErr) - if supererrors.LastErrorWas(terminal.InterruptErr) || choice >= len(links) { - os.Exit(0) - } - supererrors.Except(client.Browse(links[choice])) links = append(links[:choice], links[choice+1:]...)[: len(links)-1 : len(links)-1] }