MCPcopy
hub / github.com/cli/cli / LoadSearchResults

Method LoadSearchResults

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

Callers 1

statusRunFunction · 0.95

Calls 6

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

Tested by

no test coverage detected