MCPcopy Create free account
hub / github.com/cli/cli / LoadSearchResults

Method LoadSearchResults

pkg/cmd/status/status.go:415–529  ·  view source on GitHub ↗

Populate .AssignedPRs, .AssignedIssues, .ReviewRequests

()

Source from the content-addressed store, hash-verified

413
414// Populate .AssignedPRs, .AssignedIssues, .ReviewRequests
415func (s *StatusGetter) LoadSearchResults() error {
416 c := api.NewClientFromHTTP(s.Client)
417
418 var searchAssigns strings.Builder
419 searchAssigns.WriteString(`assignee:@me state:open archived:false`)
420 var searchReviews strings.Builder
421 searchReviews.WriteString(`review-requested:@me state:open archived:false`)
422 if s.Org != "" {
423 searchAssigns.WriteString(" org:" + s.Org)
424 searchReviews.WriteString(" org:" + s.Org)
425 }
426 for _, repo := range s.Exclude {
427 searchAssigns.WriteString(" -repo:" + repo)
428 searchReviews.WriteString(" -repo:" + repo)
429 }
430 variables := map[string]any{
431 "searchAssigns": searchAssigns.String(),
432 "searchReviews": searchReviews.String(),
433 }
434
435 var resp struct {
436 Assignments struct {
437 Nodes []*SearchResult
438 }
439 ReviewRequested struct {
440 Nodes []*SearchResult
441 }
442 }
443 err := c.GraphQL(s.hostname(), searchQuery, variables, &resp)
444 if err != nil {
445 var gqlErrResponse api.GraphQLError
446 if errors.As(err, &gqlErrResponse) {
447 gqlErrors := make([]ghAPI.GraphQLErrorItem, 0, len(gqlErrResponse.Errors))
448 // Exclude any FORBIDDEN errors and show status for what we can.
449 for _, gqlErr := range gqlErrResponse.Errors {
450 if gqlErr.Type == "FORBIDDEN" {
451 s.addAuthError(gqlErr.Message, factory.SSOURL())
452 } else {
453 gqlErrors = append(gqlErrors, gqlErr)
454 }
455 }
456 if len(gqlErrors) == 0 {
457 err = nil
458 } else {
459 err = api.GraphQLError{
460 GraphQLError: &ghAPI.GraphQLError{
461 Errors: gqlErrors,
462 },
463 }
464 }
465 }
466 if err != nil {
467 return fmt.Errorf("could not search for assignments: %w", err)
468 }
469 }
470
471 prs := []SearchResult{}
472 issues := []SearchResult{}

Callers 1

statusRunFunction · 0.95

Calls 7

hostnameMethod · 0.95
addAuthErrorMethod · 0.95
SSOURLFunction · 0.92
ResultsTypeAlias · 0.85
GraphQLMethod · 0.80
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected