MCPcopy Create free account
hub / github.com/github/gh-aw / loadPullRequestIntentData

Function loadPullRequestIntentData

pkg/cli/outcome_eval.go:464–535  ·  view source on GitHub ↗
(report OutcomeReport, repo string)

Source from the content-addressed store, hash-verified

462}
463
464func loadPullRequestIntentData(report OutcomeReport, repo string) (intent.PullRequestData, error) {
465 prNumber := report.ObjectNumber
466 ownerRepo, _ := repoutil.NormalizeRepoForAPI(repo)
467 owner, name, found := strings.Cut(ownerRepo, "/")
468 if !found || owner == "" || name == "" {
469 return intent.PullRequestData{}, fmt.Errorf("invalid repo for root tracing: %s", repo)
470 }
471
472 query := fmt.Sprintf(`query {
473 repository(owner: "%s", name: "%s") {
474 pullRequest(number: %d) {
475 id
476 closingIssuesReferences(first: 10) {
477 nodes {
478 id
479 number
480 url
481 labels(first: 20) {
482 nodes { name }
483 }
484 }
485 }
486 }
487 }
488 }`,
489 escapeGraphQLString(owner),
490 escapeGraphQLString(name),
491 prNumber,
492 )
493
494 result, err := objectiveMappingGHAPIGraphQL(query, repo)
495 if err != nil {
496 return intent.PullRequestData{}, err
497 }
498 data, _ := result["data"].(map[string]any)
499 repository, _ := data["repository"].(map[string]any)
500 pullRequest, _ := repository["pullRequest"].(map[string]any)
501 prData := intent.PullRequestData{URL: report.ObjectURL}
502 if nodeID, ok := pullRequest["id"].(string); ok {
503 prData.NodeID = nodeID
504 }
505 closingRefs, _ := pullRequest["closingIssuesReferences"].(map[string]any)
506 nodes, _ := closingRefs["nodes"].([]any)
507 if len(nodes) == 0 {
508 labels, labelErr := objectiveMappingGHAPIGetArray(fmt.Sprintf("issues/%d/labels", report.ObjectNumber), repo)
509 if labelErr != nil {
510 return intent.PullRequestData{}, labelErr
511 }
512 prData.Labels = labelsToStringsFromMaps(labels)
513 return prData, nil
514 }
515
516 prData.ClosingIssues = make([]intent.RootReference, 0, len(nodes))
517 for _, node := range nodes {
518 rootNode, _ := node.(map[string]any)
519 root := intent.RootReference{Type: "issue"}
520 if nodeID, ok := rootNode["id"].(string); ok {
521 root.NodeID = nodeID

Callers 1

resolvePullRequestIntentFunction · 0.85

Calls 5

NormalizeRepoForAPIFunction · 0.92
escapeGraphQLStringFunction · 0.85
labelsToStringsFromMapsFunction · 0.85
labelsToStringsFromNodesFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected