MCPcopy Create free account
hub / github.com/ejoffe/spr / fetchRequiredChecksStatus

Method fetchRequiredChecksStatus

github/githubclient/client.go:663–771  ·  view source on GitHub ↗

fetchRequiredChecksStatus makes a single batched GraphQL query to fetch individual check contexts for all given pull requests. It evaluates only the checks listed in config.Repo.RequiredChecks and returns a map from PR number to the computed status.

(ctx context.Context, pullRequests []*github.PullRequest)

Source from the content-addressed store, hash-verified

661// the checks listed in config.Repo.RequiredChecks and returns a map from
662// PR number to the computed status.
663func (c *client) fetchRequiredChecksStatus(ctx context.Context, pullRequests []*github.PullRequest) map[int]github.CheckStatus {
664 if len(pullRequests) == 0 {
665 return nil
666 }
667
668 if c.config.User.LogGitHubCalls {
669 fmt.Printf("> github fetch required check status\n")
670 }
671
672 // Build a single GraphQL query with one aliased field per PR.
673 var queryBuilder strings.Builder
674 queryBuilder.WriteString("query {")
675 for _, pr := range pullRequests {
676 fmt.Fprintf(&queryBuilder, `
677 pr_%d: node(id: %q) {
678 ... on PullRequest {
679 number
680 commits(last: 1) {
681 nodes {
682 commit {
683 statusCheckRollup {
684 contexts(first: 100) {
685 nodes {
686 __typename
687 ... on CheckRun {
688 name
689 conclusion
690 status
691 }
692 ... on StatusContext {
693 context
694 state
695 }
696 }
697 }
698 }
699 }
700 }
701 }
702 }
703 }`, pr.Number, pr.ID)
704 }
705 queryBuilder.WriteString("\n}")
706
707 reqBody, err := json.Marshal(graphqlRequest{
708 Query: queryBuilder.String(),
709 })
710 if err != nil {
711 log.Warn().Err(err).Msg("failed to marshal required checks query")
712 return nil
713 }
714
715 httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.graphqlEndpoint, bytes.NewReader(reqBody))
716 if err != nil {
717 log.Warn().Err(err).Msg("failed to create required checks request")
718 return nil
719 }
720 httpReq.Header.Set("Content-Type", "application/json; charset=utf-8")

Callers 1

GetInfoMethod · 0.95

Calls 3

CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected