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

Method LoadSearchResults

pkg/cmd/status/status.go:419–531  ·  view source on GitHub ↗

Populate .AssignedPRs, .AssignedIssues, .ReviewRequests

()

Source from the content-addressed store, hash-verified

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

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