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

Method GetPullRequestDatabaseID

pkg/cmd/agent-task/capi/sessions.go:511–544  ·  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

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

Callers 1

Calls 4

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

Tested by 1