@@ -82,37 +82,12 @@ func listRepositories(ctx context.Context, client api.Client, params reposListOp
8282
8383 errors := api .NewGraphQlErrors (result .Errors )
8484 if len (repos ) > 0 {
85- return filterRepositoriesWithErrors ( repos , errors ) , errors , nil
85+ return repos , errors , nil
8686 }
8787
8888 return nil , nil , errors
8989}
9090
91- func filterRepositoriesWithErrors (repos []Repository , errors api.GraphQlErrors ) []Repository {
92- if len (errors ) == 0 || len (repos ) == 0 {
93- return repos
94- }
95-
96- skip := make (map [int ]struct {}, len (errors ))
97- for _ , graphQLError := range errors {
98- index , ok := gqlRepositoryErrorIndex (graphQLError )
99- if ! ok || index >= len (repos ) {
100- continue
101- }
102- skip [index ] = struct {}{}
103- }
104-
105- filtered := make ([]Repository , 0 , len (repos ))
106- for i , repo := range repos {
107- if _ , ok := skip [i ]; ok {
108- continue
109- }
110- filtered = append (filtered , repo )
111- }
112-
113- return filtered
114- }
115-
11691func gqlErrorPathString (pathSegment any ) (string , bool ) {
11792 value , ok := pathSegment .(string )
11893 return value , ok
@@ -130,22 +105,52 @@ func gqlErrorIndex(pathSegment any) (int, bool) {
130105 }
131106}
132107
133- func gqlRepositoryErrorIndex (graphQLError * api.GraphQlError ) ( int , bool ) {
108+ func gqlWarningPath (graphQLError * api.GraphQlError ) string {
134109 path , err := graphQLError .Path ()
135- if err != nil || len (path ) < 3 {
136- return 0 , false
110+ if err != nil || len (path ) == 0 {
111+ return ""
137112 }
138113
139- pathRoot , ok := gqlErrorPathString (path [0 ])
140- if ! ok || pathRoot != "repositories" {
141- return 0 , false
114+ var b strings.Builder
115+ for _ , pathSegment := range path {
116+ if segment , ok := gqlErrorPathString (pathSegment ); ok {
117+ if b .Len () > 0 {
118+ b .WriteByte ('.' )
119+ }
120+ b .WriteString (segment )
121+ continue
122+ }
123+
124+ if index , ok := gqlErrorIndex (pathSegment ); ok {
125+ fmt .Fprintf (& b , "[%d]" , index )
126+ }
142127 }
143- pathCollection , ok := gqlErrorPathString (path [1 ])
144- if ! ok || pathCollection != "nodes" {
145- return 0 , false
128+
129+ return b .String ()
130+ }
131+
132+ func gqlWarningMessage (graphQLError * api.GraphQlError ) string {
133+ message , err := graphQLError .Message ()
134+ if err != nil || message == "" {
135+ return graphQLError .Error ()
146136 }
137+ return message
138+ }
147139
148- return gqlErrorIndex (path [2 ])
140+ func formatRepositoryListWarnings (warnings api.GraphQlErrors ) string {
141+ var b strings.Builder
142+ fmt .Fprintf (& b , "warnings: %d errors during listing\n " , len (warnings ))
143+ for _ , warning := range warnings {
144+ path := gqlWarningPath (warning )
145+ message := gqlWarningMessage (warning )
146+ if path != "" {
147+ fmt .Fprintf (& b , "%s - %s\n " , path , message )
148+ } else {
149+ fmt .Fprintf (& b , "%s\n " , message )
150+ }
151+ fmt .Fprintf (& b , "%s\n " , warning .Error ())
152+ }
153+ return b .String ()
149154}
150155
151156func init () {
@@ -241,10 +246,7 @@ Examples:
241246 }
242247 if len (warnings ) > 0 {
243248 if * verbose {
244- fmt .Fprintf (flagSet .Output (), "warning: %d errors during listing:\n " , len (warnings ))
245- for _ , warning := range warnings {
246- fmt .Fprintln (flagSet .Output (), warning .Error ())
247- }
249+ fmt .Fprint (flagSet .Output (), formatRepositoryListWarnings (warnings ))
248250 } else {
249251 fmt .Fprintf (flagSet .Output (), "warning: %d errors during listing; rerun with -v to inspect them\n " , len (warnings ))
250252 }
0 commit comments