feat(agent-task/capi): add GetPullRequestDatabaseID method
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
d80b25fbf2
commit
f57114accc
1 changed files with 29 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cli/cli/v2/api"
|
||||
"github.com/shurcooL/githubv4"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
|
|
@ -378,6 +379,34 @@ func (c *CAPIClient) hydrateSessionPullRequestsAndUsers(sessions []session) ([]*
|
|||
return newSessions, nil
|
||||
}
|
||||
|
||||
// GetPullRequestDatabaseID retrieves the database ID of a pull request given its number in a repository.
|
||||
func (c *CAPIClient) GetPullRequestDatabaseID(ctx context.Context, hostname string, owner string, repo string, number int) (int64, error) {
|
||||
var resp struct {
|
||||
Repository struct {
|
||||
PullRequest struct {
|
||||
FullDatabaseID string `graphql:"fullDatabaseId"`
|
||||
} `graphql:"pullRequest(number: $number)"`
|
||||
} `graphql:"repository(owner: $owner, name: $repo)"`
|
||||
}
|
||||
|
||||
variables := map[string]interface{}{
|
||||
"owner": githubv4.String(owner),
|
||||
"repo": githubv4.String(repo),
|
||||
"number": githubv4.Int(number),
|
||||
}
|
||||
|
||||
apiClient := api.NewClientFromHTTP(c.httpClient)
|
||||
if err := apiClient.Query(hostname, "GetPullRequestFullDatabaseID", &resp, variables); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
databaseID, err := strconv.ParseInt(resp.Repository.PullRequest.FullDatabaseID, 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return databaseID, nil
|
||||
}
|
||||
|
||||
// generatePullRequestNodeID converts an int64 databaseID and repoID to a GraphQL Node ID format
|
||||
// with the "PR_" prefix for pull requests
|
||||
func generatePullRequestNodeID(repoID, pullRequestID int64) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue