Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove merge queue from query is feature is disabled #370

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading
Loading