Skip to content

Commit

Permalink
Remove merge queue from query is feature is disabled
Browse files Browse the repository at this point in the history
fixes #356

commit-id:0219e1da
  • Loading branch information
ejoffe committed Dec 7, 2023
1 parent ca55507 commit f1139b3
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 179 deletions.
34 changes: 26 additions & 8 deletions github/githubclient/client.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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,
}
Expand All @@ -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{}
Expand Down
144 changes: 72 additions & 72 deletions github/githubclient/client_test.go
Expand Up @@ -7,15 +7,15 @@ 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"
)

func TestMatchPullRequestStack(t *testing.T) {
tests := []struct {
name string
commits []git.Commit
prs genclient.PullRequestsViewerPullRequests
prs fezzik_types.PullRequestConnection
expect []*github.PullRequest
}{
{
Expand All @@ -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"},
},
},
},
Expand Down Expand Up @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand Down Expand Up @@ -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{},
},
{
Expand All @@ -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"},
},
},
},
Expand Down Expand Up @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand Down Expand Up @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand Down Expand Up @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand Down Expand Up @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand All @@ -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"},
},
},
},
Expand Down

0 comments on commit f1139b3

Please sign in to comment.