diff --git a/github/githubclient/client.go b/github/githubclient/client.go index a3f0be6..5389b83 100644 --- a/github/githubclient/client.go +++ b/github/githubclient/client.go @@ -15,6 +15,7 @@ import ( "github.com/ejoffe/spr/config" "github.com/ejoffe/spr/git" "github.com/ejoffe/spr/github" + "github.com/ejoffe/spr/github/githubclient/fezzik_types" "github.com/ejoffe/spr/github/githubclient/gen/genclient" "github.com/rs/zerolog/log" "golang.org/x/oauth2" @@ -177,15 +178,32 @@ func (c *client) GetInfo(ctx context.Context, gitcmd git.GitInterface) *github.G if c.config.User.LogGitHubCalls { fmt.Printf("> github fetch pull requests\n") } - resp, err := c.api.PullRequests(ctx, - c.config.Repo.GitHubRepoOwner, - c.config.Repo.GitHubRepoName) - check(err) + + var pullRequestConnection fezzik_types.PullRequestConnection + var loginName string + var repoID string + if c.config.Repo.MergeQueue { + resp, err := c.api.PullRequestsWithMergeQueue(ctx, + c.config.Repo.GitHubRepoOwner, + c.config.Repo.GitHubRepoName) + check(err) + pullRequestConnection = resp.Viewer.PullRequests + loginName = resp.Viewer.Login + repoID = resp.Repository.Id + } else { + resp, err := c.api.PullRequests(ctx, + c.config.Repo.GitHubRepoOwner, + c.config.Repo.GitHubRepoName) + check(err) + pullRequestConnection = resp.Viewer.PullRequests + loginName = resp.Viewer.Login + repoID = resp.Repository.Id + } targetBranch := c.config.Repo.GitHubBranch localCommitStack := git.GetLocalCommitStack(c.config, gitcmd) - pullRequests := matchPullRequestStack(c.config.Repo, targetBranch, localCommitStack, resp.Viewer.PullRequests) + pullRequests := matchPullRequestStack(c.config.Repo, targetBranch, localCommitStack, pullRequestConnection) for _, pr := range pullRequests { if pr.Ready(c.config) { pr.MergeStatus.Stacked = true @@ -195,8 +213,8 @@ func (c *client) GetInfo(ctx context.Context, gitcmd git.GitInterface) *github.G } info := &github.GitHubInfo{ - UserName: resp.Viewer.Login, - RepositoryID: resp.Repository.Id, + UserName: loginName, + RepositoryID: repoID, LocalBranch: git.GetLocalBranchName(gitcmd), PullRequests: pullRequests, } @@ -209,7 +227,7 @@ func matchPullRequestStack( repoConfig *config.RepoConfig, targetBranch string, localCommitStack []git.Commit, - allPullRequests genclient.PullRequestsViewerPullRequests) []*github.PullRequest { + allPullRequests fezzik_types.PullRequestConnection) []*github.PullRequest { if len(localCommitStack) == 0 || allPullRequests.Nodes == nil { return []*github.PullRequest{} diff --git a/github/githubclient/client_test.go b/github/githubclient/client_test.go index c606e14..5511683 100644 --- a/github/githubclient/client_test.go +++ b/github/githubclient/client_test.go @@ -7,7 +7,7 @@ import ( "github.com/ejoffe/spr/config" "github.com/ejoffe/spr/git" "github.com/ejoffe/spr/github" - "github.com/ejoffe/spr/github/githubclient/gen/genclient" + "github.com/ejoffe/spr/github/githubclient/fezzik_types" "github.com/stretchr/testify/require" ) @@ -15,7 +15,7 @@ func TestMatchPullRequestStack(t *testing.T) { tests := []struct { name string commits []git.Commit - prs genclient.PullRequestsViewerPullRequests + prs fezzik_types.PullRequestConnection expect []*github.PullRequest }{ { @@ -25,20 +25,20 @@ func TestMatchPullRequestStack(t *testing.T) { {CommitID: "00000002"}, {CommitID: "00000003"}, }, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "2", HeadRefName: "spr/master/00000002", BaseRefName: "master", - MergeQueueEntry: &genclient.PullRequestsViewerPullRequestsNodesMergeQueueEntry{Id: "020"}, - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + MergeQueueEntry: &fezzik_types.PullRequestsViewerPullRequestsNodesMergeQueueEntry{Id: "020"}, + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1", MessageBody: "commit-id:1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1", MessageBody: "commit-id:1"}, }, { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2", MessageBody: "commit-id:2"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2", MessageBody: "commit-id:2"}, }, }, }, @@ -74,20 +74,20 @@ func TestMatchPullRequestStack(t *testing.T) { {CommitID: "00000003"}, {CommitID: "00000004"}, }, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "2", HeadRefName: "spr/master/00000002", BaseRefName: "master", - MergeQueueEntry: &genclient.PullRequestsViewerPullRequestsNodesMergeQueueEntry{Id: "020"}, - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + MergeQueueEntry: &fezzik_types.PullRequestsViewerPullRequestsNodesMergeQueueEntry{Id: "020"}, + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1", MessageBody: "commit-id:1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1", MessageBody: "commit-id:1"}, }, { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2", MessageBody: "commit-id:2"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2", MessageBody: "commit-id:2"}, }, }, }, @@ -96,10 +96,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "3", HeadRefName: "spr/master/00000003", BaseRefName: "spr/master/00000002", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3", MessageBody: "commit-id:3"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3", MessageBody: "commit-id:3"}, }, }, }, @@ -146,13 +146,13 @@ func TestMatchPullRequestStack(t *testing.T) { { name: "Empty", commits: []git.Commit{}, - prs: genclient.PullRequestsViewerPullRequests{}, + prs: fezzik_types.PullRequestConnection{}, expect: []*github.PullRequest{}, }, { name: "FirstCommit", commits: []git.Commit{{CommitID: "00000001"}}, - prs: genclient.PullRequestsViewerPullRequests{}, + prs: fezzik_types.PullRequestConnection{}, expect: []*github.PullRequest{}, }, { @@ -161,16 +161,16 @@ func TestMatchPullRequestStack(t *testing.T) { {CommitID: "00000001"}, {CommitID: "00000002"}, }, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "1", HeadRefName: "spr/master/00000001", BaseRefName: "master", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, }, }, }, @@ -199,16 +199,16 @@ func TestMatchPullRequestStack(t *testing.T) { {CommitID: "00000002"}, {CommitID: "00000003"}, }, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "1", HeadRefName: "spr/master/00000001", BaseRefName: "master", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, }, }, }, @@ -217,10 +217,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "2", HeadRefName: "spr/master/00000002", BaseRefName: "spr/master/00000001", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, }, }, }, @@ -257,16 +257,16 @@ func TestMatchPullRequestStack(t *testing.T) { { name: "RemoveOnlyCommit", commits: []git.Commit{}, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "1", HeadRefName: "spr/master/00000001", BaseRefName: "master", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, }, }, }, @@ -281,16 +281,16 @@ func TestMatchPullRequestStack(t *testing.T) { {CommitID: "00000001"}, {CommitID: "00000002"}, }, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "1", HeadRefName: "spr/master/00000001", BaseRefName: "master", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, }, }, }, @@ -299,10 +299,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "3", HeadRefName: "spr/master/00000003", BaseRefName: "spr/master/00000002", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, }, }, }, @@ -311,10 +311,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "2", HeadRefName: "spr/master/00000002", BaseRefName: "spr/master/00000001", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, }, }, }, @@ -354,16 +354,16 @@ func TestMatchPullRequestStack(t *testing.T) { {CommitID: "00000001"}, {CommitID: "00000003"}, }, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "1", HeadRefName: "spr/master/00000001", BaseRefName: "master", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, }, }, }, @@ -372,10 +372,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "2", HeadRefName: "spr/master/00000002", BaseRefName: "spr/master/00000001", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, }, }, }, @@ -384,10 +384,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "3", HeadRefName: "spr/master/00000003", BaseRefName: "spr/master/00000002", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3"}, }, }, }, @@ -439,16 +439,16 @@ func TestMatchPullRequestStack(t *testing.T) { {CommitID: "00000002"}, {CommitID: "00000003"}, }, - prs: genclient.PullRequestsViewerPullRequests{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodes{ + prs: fezzik_types.PullRequestConnection{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodes{ { Id: "1", HeadRefName: "spr/master/00000001", BaseRefName: "master", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"}, }, }, }, @@ -457,10 +457,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "2", HeadRefName: "spr/master/00000002", BaseRefName: "spr/master/00000001", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"}, }, }, }, @@ -469,10 +469,10 @@ func TestMatchPullRequestStack(t *testing.T) { Id: "3", HeadRefName: "spr/master/00000003", BaseRefName: "spr/master/00000002", - Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{ - Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{ + Commits: fezzik_types.PullRequestsViewerPullRequestsNodesCommits{ + Nodes: &fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodes{ { - genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3"}, + fezzik_types.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3"}, }, }, }, diff --git a/github/githubclient/fezzik.yaml b/github/githubclient/fezzik.yaml index 902083d..28e77c9 100644 --- a/github/githubclient/fezzik.yaml +++ b/github/githubclient/fezzik.yaml @@ -4,6 +4,8 @@ operations: - queries.graphql package_name: genclient package_dir: gen +autobind: + - github.com/ejoffe/spr/github/githubclient/fezzik_types scalar_type_map: ID: string GitObjectID: string diff --git a/github/githubclient/fezzik_types/fezzik_types.go b/github/githubclient/fezzik_types/fezzik_types.go new file mode 100644 index 0000000..0b21c06 --- /dev/null +++ b/github/githubclient/fezzik_types/fezzik_types.go @@ -0,0 +1,72 @@ +package fezzik_types + +type MergeableState string + +const ( + MergeableState_CONFLICTING MergeableState = "CONFLICTING" + MergeableState_MERGEABLE MergeableState = "MERGEABLE" + MergeableState_UNKNOWN MergeableState = "UNKNOWN" +) + +type PullRequestReviewDecision string + +const ( + PullRequestReviewDecision_APPROVED PullRequestReviewDecision = "APPROVED" + PullRequestReviewDecision_CHANGES_REQUESTED PullRequestReviewDecision = "CHANGES_REQUESTED" + PullRequestReviewDecision_REVIEW_REQUIRED PullRequestReviewDecision = "REVIEW_REQUIRED" +) + +type StatusState string + +const ( + StatusState_ERROR StatusState = "ERROR" + StatusState_EXPECTED StatusState = "EXPECTED" + StatusState_FAILURE StatusState = "FAILURE" + StatusState_PENDING StatusState = "PENDING" + StatusState_SUCCESS StatusState = "SUCCESS" +) + +type PullRequestConnection struct { + Nodes *PullRequestsViewerPullRequestsNodes +} + +type PullRequestsViewerPullRequestsNodes []*struct { + Id string + Number int + Title string + Body string + BaseRefName string + HeadRefName string + Mergeable MergeableState + ReviewDecision *PullRequestReviewDecision + Repository PullRequestsViewerPullRequestsNodesRepository + MergeQueueEntry *PullRequestsViewerPullRequestsNodesMergeQueueEntry + Commits PullRequestsViewerPullRequestsNodesCommits +} + +type PullRequestsViewerPullRequestsNodesRepository struct { + Id string +} + +type PullRequestsViewerPullRequestsNodesMergeQueueEntry struct { + Id string +} + +type PullRequestsViewerPullRequestsNodesCommits struct { + Nodes *PullRequestsViewerPullRequestsNodesCommitsNodes +} + +type PullRequestsViewerPullRequestsNodesCommitsNodes []*struct { + Commit PullRequestsViewerPullRequestsNodesCommitsNodesCommit +} + +type PullRequestsViewerPullRequestsNodesCommitsNodesCommit struct { + Oid string + MessageHeadline string + MessageBody string + StatusCheckRollup *PullRequestsViewerPullRequestsNodesCommitsNodesCommitStatusCheckRollup +} + +type PullRequestsViewerPullRequestsNodesCommitsNodesCommitStatusCheckRollup struct { + State StatusState +} diff --git a/github/githubclient/gen/genclient/client.go b/github/githubclient/gen/genclient/client.go index 85cba00..c43e842 100644 --- a/github/githubclient/gen/genclient/client.go +++ b/github/githubclient/gen/genclient/client.go @@ -16,60 +16,66 @@ type Client interface { repoName string, ) (*PullRequestsResponse, error) - // AssignableUsers from github/githubclient/queries.graphql:43 + // PullRequestsWithMergeQueue from github/githubclient/queries.graphql:40 + PullRequestsWithMergeQueue(ctx context.Context, + repoOwner string, + repoName string, + ) (*PullRequestsWithMergeQueueResponse, error) + + // AssignableUsers from github/githubclient/queries.graphql:82 AssignableUsers(ctx context.Context, repoOwner string, repoName string, endCursor *string, ) (*AssignableUsersResponse, error) - // CreatePullRequest from github/githubclient/queries.graphql:63 + // CreatePullRequest from github/githubclient/queries.graphql:102 CreatePullRequest(ctx context.Context, input CreatePullRequestInput, ) (*CreatePullRequestResponse, error) - // UpdatePullRequest from github/githubclient/queries.graphql:76 + // UpdatePullRequest from github/githubclient/queries.graphql:115 UpdatePullRequest(ctx context.Context, input UpdatePullRequestInput, ) (*UpdatePullRequestResponse, error) - // AddReviewers from github/githubclient/queries.graphql:88 + // AddReviewers from github/githubclient/queries.graphql:127 AddReviewers(ctx context.Context, input RequestReviewsInput, ) (*AddReviewersResponse, error) - // CommentPullRequest from github/githubclient/queries.graphql:100 + // CommentPullRequest from github/githubclient/queries.graphql:139 CommentPullRequest(ctx context.Context, input AddCommentInput, ) (*CommentPullRequestResponse, error) - // MergePullRequest from github/githubclient/queries.graphql:110 + // MergePullRequest from github/githubclient/queries.graphql:149 MergePullRequest(ctx context.Context, input MergePullRequestInput, ) (*MergePullRequestResponse, error) - // AutoMergePullRequest from github/githubclient/queries.graphql:122 + // AutoMergePullRequest from github/githubclient/queries.graphql:161 AutoMergePullRequest(ctx context.Context, input EnablePullRequestAutoMergeInput, ) (*AutoMergePullRequestResponse, error) - // ClosePullRequest from github/githubclient/queries.graphql:134 + // ClosePullRequest from github/githubclient/queries.graphql:173 ClosePullRequest(ctx context.Context, input ClosePullRequestInput, ) (*ClosePullRequestResponse, error) - // StarCheck from github/githubclient/queries.graphql:146 + // StarCheck from github/githubclient/queries.graphql:185 StarCheck(ctx context.Context, after *string, ) (*StarCheckResponse, error) - // StarGetRepo from github/githubclient/queries.graphql:162 + // StarGetRepo from github/githubclient/queries.graphql:201 StarGetRepo(ctx context.Context, owner string, name string, ) (*StarGetRepoResponse, error) - // StarAdd from github/githubclient/queries.graphql:171 + // StarAdd from github/githubclient/queries.graphql:210 StarAdd(ctx context.Context, input AddStarInput, ) (*StarAddResponse, error) diff --git a/github/githubclient/gen/genclient/inputs.go b/github/githubclient/gen/genclient/inputs.go index 05c2a2f..70c6521 100644 --- a/github/githubclient/gen/genclient/inputs.go +++ b/github/githubclient/gen/genclient/inputs.go @@ -621,14 +621,6 @@ const ( MergeStateStatus_UNSTABLE MergeStateStatus = "UNSTABLE" ) -type MergeableState string - -const ( - MergeableState_CONFLICTING MergeableState = "CONFLICTING" - MergeableState_MERGEABLE MergeableState = "MERGEABLE" - MergeableState_UNKNOWN MergeableState = "UNKNOWN" -) - type MigrationSourceType string const ( @@ -1116,14 +1108,6 @@ const ( PullRequestReviewCommentState_SUBMITTED PullRequestReviewCommentState = "SUBMITTED" ) -type PullRequestReviewDecision string - -const ( - PullRequestReviewDecision_APPROVED PullRequestReviewDecision = "APPROVED" - PullRequestReviewDecision_CHANGES_REQUESTED PullRequestReviewDecision = "CHANGES_REQUESTED" - PullRequestReviewDecision_REVIEW_REQUIRED PullRequestReviewDecision = "REVIEW_REQUIRED" -) - type PullRequestReviewEvent string const ( @@ -1964,16 +1948,6 @@ const ( StarOrderField_STARRED_AT StarOrderField = "STARRED_AT" ) -type StatusState string - -const ( - StatusState_ERROR StatusState = "ERROR" - StatusState_EXPECTED StatusState = "EXPECTED" - StatusState_FAILURE StatusState = "FAILURE" - StatusState_PENDING StatusState = "PENDING" - StatusState_SUCCESS StatusState = "SUCCESS" -) - type SubscriptionState string const ( diff --git a/github/githubclient/gen/genclient/operations.go b/github/githubclient/gen/genclient/operations.go index 41a329e..1f5312e 100644 --- a/github/githubclient/gen/genclient/operations.go +++ b/github/githubclient/gen/genclient/operations.go @@ -5,77 +5,122 @@ package genclient import ( "context" + "github.com/ejoffe/spr/github/githubclient/fezzik_types" "github.com/inigolabs/fezzik/client" ) type PullRequestsViewer struct { Login string - PullRequests PullRequestsViewerPullRequests + PullRequests fezzik_types.PullRequestConnection } -type PullRequestsViewerPullRequests struct { - Nodes *PullRequestsViewerPullRequestsNodes +type PullRequestsRepository struct { + Id string } -type PullRequestsViewerPullRequestsNodes []*struct { - Id string - Number int - Title string - Body string - BaseRefName string - HeadRefName string - Mergeable MergeableState - ReviewDecision *PullRequestReviewDecision - Repository PullRequestsViewerPullRequestsNodesRepository - MergeQueueEntry *PullRequestsViewerPullRequestsNodesMergeQueueEntry - Commits PullRequestsViewerPullRequestsNodesCommits +// PullRequestsResponse response type for PullRequests +type PullRequestsResponse struct { + Viewer PullRequestsViewer + Repository *PullRequestsRepository } -type PullRequestsViewerPullRequestsNodesRepository struct { - Id string -} +// PullRequests from github/githubclient/queries.graphql:1 +func (c *gqlclient) PullRequests(ctx context.Context, + repoOwner string, + repoName string, +) (*PullRequestsResponse, error) { -type PullRequestsViewerPullRequestsNodesMergeQueueEntry struct { - Id string + var pullRequestsOperation string = ` + query PullRequests ($repo_owner: String!, $repo_name: String!) { + viewer { + login + pullRequests(first: 100, states: [OPEN]) { + nodes { + id + number + title + body + baseRefName + headRefName + mergeable + reviewDecision + repository { + id + } + commits(first: 100) { + nodes { + commit { + oid + messageHeadline + messageBody + statusCheckRollup { + state + } + } + } + } + } + } + } + repository(owner: $repo_owner, name: $repo_name) { + id + } } +` -type PullRequestsViewerPullRequestsNodesCommits struct { - Nodes *PullRequestsViewerPullRequestsNodesCommitsNodes -} + gqlreq := &client.GQLRequest{ + OperationName: "PullRequests", + Query: pullRequestsOperation, + Variables: map[string]interface{}{ + "repo_owner": repoOwner, + "repo_name": repoName, + }, + } -type PullRequestsViewerPullRequestsNodesCommitsNodes []*struct { - Commit PullRequestsViewerPullRequestsNodesCommitsNodesCommit -} + resp := &client.GQLResponse{ + Data: &PullRequestsResponse{}, + } + + err := c.gql.Query(ctx, gqlreq, resp) + if err != nil { + return nil, err + } -type PullRequestsViewerPullRequestsNodesCommitsNodesCommit struct { - Oid string - MessageHeadline string - MessageBody string - StatusCheckRollup *PullRequestsViewerPullRequestsNodesCommitsNodesCommitStatusCheckRollup + var data *PullRequestsResponse + if resp.Data != nil { + data = resp.Data.(*PullRequestsResponse) + } + + if resp.Errors == nil { + return data, nil + } + + return data, resp.Errors } -type PullRequestsViewerPullRequestsNodesCommitsNodesCommitStatusCheckRollup struct { - State StatusState +type PullRequestsWithMergeQueueViewer struct { + Login string + PullRequests fezzik_types.PullRequestConnection } -type PullRequestsRepository struct { +type PullRequestsWithMergeQueueRepository struct { Id string } -// PullRequestsResponse response type for PullRequests -type PullRequestsResponse struct { - Viewer PullRequestsViewer - Repository *PullRequestsRepository +// PullRequestsWithMergeQueueResponse response type for PullRequestsWithMergeQueue +type PullRequestsWithMergeQueueResponse struct { + Viewer PullRequestsWithMergeQueueViewer + Repository *PullRequestsWithMergeQueueRepository } -// PullRequests from github/githubclient/queries.graphql:1 -func (c *gqlclient) PullRequests(ctx context.Context, +// PullRequestsWithMergeQueue from github/githubclient/queries.graphql:40 +func (c *gqlclient) PullRequestsWithMergeQueue(ctx context.Context, repoOwner string, repoName string, -) (*PullRequestsResponse, error) { +) (*PullRequestsWithMergeQueueResponse, error) { - var pullRequestsOperation string = ` - query PullRequests ($repo_owner: String!, $repo_name: String!) { + var pullRequestsWithMergeQueueOperation string = ` + query PullRequestsWithMergeQueue ($repo_owner: String!, $repo_name: String!) { viewer { login pullRequests(first: 100, states: [OPEN]) { @@ -116,8 +161,8 @@ func (c *gqlclient) PullRequests(ctx context.Context, ` gqlreq := &client.GQLRequest{ - OperationName: "PullRequests", - Query: pullRequestsOperation, + OperationName: "PullRequestsWithMergeQueue", + Query: pullRequestsWithMergeQueueOperation, Variables: map[string]interface{}{ "repo_owner": repoOwner, "repo_name": repoName, @@ -125,7 +170,7 @@ func (c *gqlclient) PullRequests(ctx context.Context, } resp := &client.GQLResponse{ - Data: &PullRequestsResponse{}, + Data: &PullRequestsWithMergeQueueResponse{}, } err := c.gql.Query(ctx, gqlreq, resp) @@ -133,9 +178,9 @@ func (c *gqlclient) PullRequests(ctx context.Context, return nil, err } - var data *PullRequestsResponse + var data *PullRequestsWithMergeQueueResponse if resp.Data != nil { - data = resp.Data.(*PullRequestsResponse) + data = resp.Data.(*PullRequestsWithMergeQueueResponse) } if resp.Errors == nil { @@ -170,7 +215,7 @@ type AssignableUsersResponse struct { Repository *AssignableUsersRepository } -// AssignableUsers from github/githubclient/queries.graphql:43 +// AssignableUsers from github/githubclient/queries.graphql:82 func (c *gqlclient) AssignableUsers(ctx context.Context, repoOwner string, repoName string, @@ -240,7 +285,7 @@ type CreatePullRequestResponse struct { CreatePullRequest *CreatePullRequestCreatePullRequest } -// CreatePullRequest from github/githubclient/queries.graphql:63 +// CreatePullRequest from github/githubclient/queries.graphql:102 func (c *gqlclient) CreatePullRequest(ctx context.Context, input CreatePullRequestInput, ) (*CreatePullRequestResponse, error) { @@ -298,7 +343,7 @@ type UpdatePullRequestResponse struct { UpdatePullRequest *UpdatePullRequestUpdatePullRequest } -// UpdatePullRequest from github/githubclient/queries.graphql:76 +// UpdatePullRequest from github/githubclient/queries.graphql:115 func (c *gqlclient) UpdatePullRequest(ctx context.Context, input UpdatePullRequestInput, ) (*UpdatePullRequestResponse, error) { @@ -355,7 +400,7 @@ type AddReviewersResponse struct { RequestReviews *AddReviewersRequestReviews } -// AddReviewers from github/githubclient/queries.graphql:88 +// AddReviewers from github/githubclient/queries.graphql:127 func (c *gqlclient) AddReviewers(ctx context.Context, input RequestReviewsInput, ) (*AddReviewersResponse, error) { @@ -408,7 +453,7 @@ type CommentPullRequestResponse struct { AddComment *CommentPullRequestAddComment } -// CommentPullRequest from github/githubclient/queries.graphql:100 +// CommentPullRequest from github/githubclient/queries.graphql:139 func (c *gqlclient) CommentPullRequest(ctx context.Context, input AddCommentInput, ) (*CommentPullRequestResponse, error) { @@ -463,7 +508,7 @@ type MergePullRequestResponse struct { MergePullRequest *MergePullRequestMergePullRequest } -// MergePullRequest from github/githubclient/queries.graphql:110 +// MergePullRequest from github/githubclient/queries.graphql:149 func (c *gqlclient) MergePullRequest(ctx context.Context, input MergePullRequestInput, ) (*MergePullRequestResponse, error) { @@ -520,7 +565,7 @@ type AutoMergePullRequestResponse struct { EnablePullRequestAutoMerge *AutoMergePullRequestEnablePullRequestAutoMerge } -// AutoMergePullRequest from github/githubclient/queries.graphql:122 +// AutoMergePullRequest from github/githubclient/queries.graphql:161 func (c *gqlclient) AutoMergePullRequest(ctx context.Context, input EnablePullRequestAutoMergeInput, ) (*AutoMergePullRequestResponse, error) { @@ -577,7 +622,7 @@ type ClosePullRequestResponse struct { ClosePullRequest *ClosePullRequestClosePullRequest } -// ClosePullRequest from github/githubclient/queries.graphql:134 +// ClosePullRequest from github/githubclient/queries.graphql:173 func (c *gqlclient) ClosePullRequest(ctx context.Context, input ClosePullRequestInput, ) (*ClosePullRequestResponse, error) { @@ -644,7 +689,7 @@ type StarCheckResponse struct { Viewer StarCheckViewer } -// StarCheck from github/githubclient/queries.graphql:146 +// StarCheck from github/githubclient/queries.graphql:185 func (c *gqlclient) StarCheck(ctx context.Context, after *string, ) (*StarCheckResponse, error) { @@ -703,7 +748,7 @@ type StarGetRepoResponse struct { Repository *StarGetRepoRepository } -// StarGetRepo from github/githubclient/queries.graphql:162 +// StarGetRepo from github/githubclient/queries.graphql:201 func (c *gqlclient) StarGetRepo(ctx context.Context, owner string, name string, @@ -756,7 +801,7 @@ type StarAddResponse struct { AddStar *StarAddAddStar } -// StarAdd from github/githubclient/queries.graphql:171 +// StarAdd from github/githubclient/queries.graphql:210 func (c *gqlclient) StarAdd(ctx context.Context, input AddStarInput, ) (*StarAddResponse, error) { diff --git a/github/githubclient/queries.graphql b/github/githubclient/queries.graphql index 067480e..bc529d7 100644 --- a/github/githubclient/queries.graphql +++ b/github/githubclient/queries.graphql @@ -1,6 +1,45 @@ query PullRequests( $repo_owner: String!, $repo_name: String!, +){ + viewer { + login + pullRequests(first:100, states:[OPEN]) { + nodes { + id + number + title + body + baseRefName + headRefName + mergeable + reviewDecision + repository { + id + } + commits(first:100) { + nodes { + commit { + oid + messageHeadline + messageBody + statusCheckRollup { + state + } + } + } + } + } + } + } + repository(owner:$repo_owner, name:$repo_name) { + id + } +} + +query PullRequestsWithMergeQueue( + $repo_owner: String!, + $repo_name: String!, ){ viewer { login diff --git a/go.mod b/go.mod index c002778..6af373d 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/ejoffe/profiletimer v0.1.0 github.com/ejoffe/rake v0.2.7 github.com/google/uuid v1.3.0 - github.com/inigolabs/fezzik v0.4.9 + github.com/inigolabs/fezzik v0.4.10 github.com/jessevdk/go-flags v1.5.0 github.com/rs/zerolog v1.26.1 github.com/stretchr/testify v1.7.1 diff --git a/go.sum b/go.sum index 7d0d5e6..b48a1ef 100644 --- a/go.sum +++ b/go.sum @@ -312,8 +312,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/inigolabs/fezzik v0.4.9 h1:60MiOii7N0JXrvTA0mk2g37qDmxM3roFo/wt4ateEAk= -github.com/inigolabs/fezzik v0.4.9/go.mod h1:vCsZurxUwhjursURZPF8xxofoOFzpVVJaqiNOUO9I80= +github.com/inigolabs/fezzik v0.4.10 h1:iV6KflmW5UVMVtqYgE8arGGfAaU88NQvM7mDoCC9zD0= +github.com/inigolabs/fezzik v0.4.10/go.mod h1:vCsZurxUwhjursURZPF8xxofoOFzpVVJaqiNOUO9I80= github.com/jensneuse/abstractlogger v0.0.4/go.mod h1:6WuamOHuykJk8zED/R0LNiLhWR6C7FIAo43ocUEB3mo= github.com/jensneuse/byte-template v0.0.0-20200214152254-4f3cf06e5c68/go.mod h1:0D5r/VSW6D/o65rKLL9xk7sZxL2+oku2HvFPYeIMFr4= github.com/jensneuse/diffview v1.0.0 h1:4b6FQJ7y3295JUHU3tRko6euyEboL825ZsXeZZM47Z4=