MCPcopy Index your code
hub / github.com/cli/cli / GetPullRequestDatabaseID

Method GetPullRequestDatabaseID

pkg/cmd/agent-task/capi/sessions.go:505–538  ·  view source on GitHub ↗

GetPullRequestDatabaseID retrieves the database ID and URL of a pull request given its number in a repository.

(ctx context.Context, hostname string, owner string, repo string, number int)

Source from the content-addressed store, hash-verified

503
504// GetPullRequestDatabaseID retrieves the database ID and URL of a pull request given its number in a repository.
505func (c *CAPIClient) GetPullRequestDatabaseID(ctx context.Context, hostname string, owner string, repo string, number int) (int64, string, error) {
506 // TODO: better int handling so we don't need to do bounds checks
507 // to both ensure a panic is impossible and that we do not trigger
508 // CodeQL alerts.
509 if number <= 0 || number > math.MaxInt32 {
510 return 0, "", fmt.Errorf("pull request number %d out of bounds", number)
511 }
512
513 var resp struct {
514 Repository struct {
515 PullRequest struct {
516 FullDatabaseID string `graphql:"fullDatabaseId"`
517 URL string `graphql:"url"`
518 } `graphql:"pullRequest(number: $number)"`
519 } `graphql:"repository(owner: $owner, name: $repo)"`
520 }
521
522 variables := map[string]interface{}{
523 "owner": githubv4.String(owner),
524 "repo": githubv4.String(repo),
525 "number": githubv4.Int(number),
526 }
527
528 apiClient := api.NewClientFromHTTP(c.httpClient)
529 if err := apiClient.Query(hostname, "GetPullRequestFullDatabaseID", &resp, variables); err != nil {
530 return 0, "", err
531 }
532
533 databaseID, err := strconv.ParseInt(resp.Repository.PullRequest.FullDatabaseID, 10, 64)
534 if err != nil {
535 return 0, "", err
536 }
537 return databaseID, resp.Repository.PullRequest.URL, nil
538}
539
540// generatePullRequestNodeID converts an int64 databaseID and repoID to a GraphQL Node ID format
541// with the "PR_" prefix for pull requests

Callers 1

Calls 4

NewClientFromHTTPFunction · 0.92
ErrorfMethod · 0.65
QueryMethod · 0.65
StringMethod · 0.45

Tested by 1