@@ -3,7 +3,6 @@ package command
33import (
44 "fmt"
55 "io"
6- "net/url"
76 "strconv"
87 "strings"
98 "time"
@@ -122,57 +121,6 @@ var issueReopenCmd = &cobra.Command{
122121 RunE : issueReopen ,
123122}
124123
125- type filterOptions struct {
126- entity string
127- state string
128- assignee string
129- labels []string
130- author string
131- baseBranch string
132- mention string
133- milestone string
134- }
135-
136- func listURLWithQuery (listURL string , options filterOptions ) (string , error ) {
137- u , err := url .Parse (listURL )
138- if err != nil {
139- return "" , err
140- }
141- query := fmt .Sprintf ("is:%s " , options .entity )
142- if options .state != "all" {
143- query += fmt .Sprintf ("is:%s " , options .state )
144- }
145- if options .assignee != "" {
146- query += fmt .Sprintf ("assignee:%s " , options .assignee )
147- }
148- for _ , label := range options .labels {
149- query += fmt .Sprintf ("label:%s " , quoteValueForQuery (label ))
150- }
151- if options .author != "" {
152- query += fmt .Sprintf ("author:%s " , options .author )
153- }
154- if options .baseBranch != "" {
155- query += fmt .Sprintf ("base:%s " , options .baseBranch )
156- }
157- if options .mention != "" {
158- query += fmt .Sprintf ("mentions:%s " , options .mention )
159- }
160- if options .milestone != "" {
161- query += fmt .Sprintf ("milestone:%s " , quoteValueForQuery (options .milestone ))
162- }
163- q := u .Query ()
164- q .Set ("q" , strings .TrimSuffix (query , " " ))
165- u .RawQuery = q .Encode ()
166- return u .String (), nil
167- }
168-
169- func quoteValueForQuery (v string ) string {
170- if strings .ContainsAny (v , " \" \t \r \n " ) {
171- return fmt .Sprintf ("%q" , v )
172- }
173- return v
174- }
175-
176124func issueList (cmd * cobra.Command , args []string ) error {
177125 ctx := contextForCommand (cmd )
178126 apiClient , err := apiClientForContext (ctx )
@@ -230,14 +178,14 @@ func issueList(cmd *cobra.Command, args []string) error {
230178
231179 if web {
232180 issueListURL := ghrepo .GenerateRepoURL (baseRepo , "issues" )
233- openURL , err := listURLWithQuery (issueListURL , filterOptions {
234- entity : "issue" ,
235- state : state ,
236- assignee : assignee ,
237- labels : labels ,
238- author : author ,
239- mention : mention ,
240- milestone : milestone ,
181+ openURL , err := shared . ListURLWithQuery (issueListURL , shared. FilterOptions {
182+ Entity : "issue" ,
183+ State : state ,
184+ Assignee : assignee ,
185+ Labels : labels ,
186+ Author : author ,
187+ Mention : mention ,
188+ Milestone : milestone ,
241189 })
242190 if err != nil {
243191 return err
@@ -259,7 +207,7 @@ func issueList(cmd *cobra.Command, args []string) error {
259207 }
260208 })
261209
262- title := listHeader (ghrepo .FullName (baseRepo ), "issue" , len (listResult .Issues ), listResult .TotalCount , hasFilters )
210+ title := shared . ListHeader (ghrepo .FullName (baseRepo ), "issue" , len (listResult .Issues ), listResult .TotalCount , hasFilters )
263211 if connectedToTerminal (cmd ) {
264212 fmt .Fprintf (colorableErr (cmd ), "\n %s\n \n " , title )
265213 }
@@ -362,25 +310,6 @@ func issueStateTitleWithColor(state string) string {
362310 return colorFunc (strings .Title (strings .ToLower (state )))
363311}
364312
365- func listHeader (repoName string , itemName string , matchCount int , totalMatchCount int , hasFilters bool ) string {
366- if totalMatchCount == 0 {
367- if hasFilters {
368- return fmt .Sprintf ("No %ss match your search in %s" , itemName , repoName )
369- }
370- return fmt .Sprintf ("There are no open %ss in %s" , itemName , repoName )
371- }
372-
373- if hasFilters {
374- matchVerb := "match"
375- if totalMatchCount == 1 {
376- matchVerb = "matches"
377- }
378- return fmt .Sprintf ("Showing %d of %s in %s that %s your search" , matchCount , utils .Pluralize (totalMatchCount , itemName ), repoName , matchVerb )
379- }
380-
381- return fmt .Sprintf ("Showing %d of %s in %s" , matchCount , utils .Pluralize (totalMatchCount , fmt .Sprintf ("open %s" , itemName )), repoName )
382- }
383-
384313func printRawIssuePreview (out io.Writer , issue * api.Issue ) error {
385314 assignees := issueAssigneeList (* issue )
386315 labels := issueLabelList (* issue )
@@ -619,7 +548,8 @@ func issueCreate(cmd *cobra.Command, args []string) error {
619548}
620549
621550func printIssues (w io.Writer , prefix string , totalCount int , issues []api.Issue ) {
622- table := utils .NewTablePrinter (w )
551+ // TODO: accept io streams via argument
552+ table := utils .NewTablePrinter (defaultStreams )
623553 for _ , issue := range issues {
624554 issueNum := strconv .Itoa (issue .Number )
625555 if table .IsTTY () {
0 commit comments