Skip to content

Commit

Permalink
fix: support large repos by fetching only user's pull requests
Browse files Browse the repository at this point in the history
Previously, all pull requests for the current repo were queried, with a
limit of 100. This means spr would not function for any repos with over
100 open pull requests, which is fairly common for larger repos. Instead,
query for only the current user's pull requests.
  • Loading branch information
Julian Delerme authored and ejoffe committed Jul 5, 2023
1 parent f876089 commit 4a7e077
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 81 deletions.
4 changes: 2 additions & 2 deletions github/githubclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (c *client) GetInfo(ctx context.Context, gitcmd git.GitInterface) *github.G
targetBranch := c.config.Internal.GitHubBranch
localCommitStack := git.GetLocalCommitStack(c.config, gitcmd)

pullRequests := matchPullRequestStack(c.config.Repo, targetBranch, localCommitStack, resp.Repository.PullRequests)
pullRequests := matchPullRequestStack(c.config.Repo, targetBranch, localCommitStack, resp.Viewer.PullRequests)
for _, pr := range pullRequests {
if pr.Ready(c.config) {
pr.MergeStatus.Stacked = true
Expand All @@ -209,7 +209,7 @@ func matchPullRequestStack(
repoConfig *config.RepoConfig,
targetBranch string,
localCommitStack []git.Commit,
allPullRequests genclient.PullRequestsRepositoryPullRequests) []*github.PullRequest {
allPullRequests genclient.PullRequestsViewerPullRequests) []*github.PullRequest {

if len(localCommitStack) == 0 || allPullRequests.Nodes == nil {
return []*github.PullRequest{}
Expand Down
108 changes: 54 additions & 54 deletions github/githubclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ func TestMatchPullRequestStack(t *testing.T) {
tests := []struct {
name string
commits []git.Commit
prs genclient.PullRequestsRepositoryPullRequests
prs genclient.PullRequestsViewerPullRequests
expect []*github.PullRequest
}{
{
name: "Empty",
commits: []git.Commit{},
prs: genclient.PullRequestsRepositoryPullRequests{},
prs: genclient.PullRequestsViewerPullRequests{},
expect: []*github.PullRequest{},
},
{
name: "FirstCommit",
commits: []git.Commit{{CommitID: "00000001"}},
prs: genclient.PullRequestsRepositoryPullRequests{},
prs: genclient.PullRequestsViewerPullRequests{},
expect: []*github.PullRequest{},
},
{
Expand All @@ -36,16 +36,16 @@ func TestMatchPullRequestStack(t *testing.T) {
{CommitID: "00000001"},
{CommitID: "00000002"},
},
prs: genclient.PullRequestsRepositoryPullRequests{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodes{
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "1",
HeadRefName: "spr/master/00000001",
BaseRefName: "master",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "1"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"},
},
},
},
Expand Down Expand Up @@ -74,16 +74,16 @@ func TestMatchPullRequestStack(t *testing.T) {
{CommitID: "00000002"},
{CommitID: "00000003"},
},
prs: genclient.PullRequestsRepositoryPullRequests{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodes{
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "1",
HeadRefName: "spr/master/00000001",
BaseRefName: "master",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "1"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"},
},
},
},
Expand All @@ -92,10 +92,10 @@ func TestMatchPullRequestStack(t *testing.T) {
Id: "2",
HeadRefName: "spr/master/00000002",
BaseRefName: "spr/master/00000001",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "2"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"},
},
},
},
Expand Down Expand Up @@ -132,16 +132,16 @@ func TestMatchPullRequestStack(t *testing.T) {
{
name: "RemoveOnlyCommit",
commits: []git.Commit{},
prs: genclient.PullRequestsRepositoryPullRequests{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodes{
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "1",
HeadRefName: "spr/master/00000001",
BaseRefName: "master",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "1"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"},
},
},
},
Expand All @@ -156,16 +156,16 @@ func TestMatchPullRequestStack(t *testing.T) {
{CommitID: "00000001"},
{CommitID: "00000002"},
},
prs: genclient.PullRequestsRepositoryPullRequests{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodes{
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "1",
HeadRefName: "spr/master/00000001",
BaseRefName: "master",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "1"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"},
},
},
},
Expand All @@ -174,10 +174,10 @@ func TestMatchPullRequestStack(t *testing.T) {
Id: "3",
HeadRefName: "spr/master/00000003",
BaseRefName: "spr/master/00000002",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "2"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"},
},
},
},
Expand All @@ -186,10 +186,10 @@ func TestMatchPullRequestStack(t *testing.T) {
Id: "2",
HeadRefName: "spr/master/00000002",
BaseRefName: "spr/master/00000001",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "2"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"},
},
},
},
Expand Down Expand Up @@ -229,16 +229,16 @@ func TestMatchPullRequestStack(t *testing.T) {
{CommitID: "00000001"},
{CommitID: "00000003"},
},
prs: genclient.PullRequestsRepositoryPullRequests{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodes{
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "1",
HeadRefName: "spr/master/00000001",
BaseRefName: "master",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "1"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"},
},
},
},
Expand All @@ -247,10 +247,10 @@ func TestMatchPullRequestStack(t *testing.T) {
Id: "2",
HeadRefName: "spr/master/00000002",
BaseRefName: "spr/master/00000001",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "2"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"},
},
},
},
Expand All @@ -259,10 +259,10 @@ func TestMatchPullRequestStack(t *testing.T) {
Id: "3",
HeadRefName: "spr/master/00000003",
BaseRefName: "spr/master/00000002",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "3"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3"},
},
},
},
Expand Down Expand Up @@ -314,16 +314,16 @@ func TestMatchPullRequestStack(t *testing.T) {
{CommitID: "00000002"},
{CommitID: "00000003"},
},
prs: genclient.PullRequestsRepositoryPullRequests{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodes{
prs: genclient.PullRequestsViewerPullRequests{
Nodes: &genclient.PullRequestsViewerPullRequestsNodes{
{
Id: "1",
HeadRefName: "spr/master/00000001",
BaseRefName: "master",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "1"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "1"},
},
},
},
Expand All @@ -332,10 +332,10 @@ func TestMatchPullRequestStack(t *testing.T) {
Id: "2",
HeadRefName: "spr/master/00000002",
BaseRefName: "spr/master/00000001",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "2"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "2"},
},
},
},
Expand All @@ -344,10 +344,10 @@ func TestMatchPullRequestStack(t *testing.T) {
Id: "3",
HeadRefName: "spr/master/00000003",
BaseRefName: "spr/master/00000002",
Commits: genclient.PullRequestsRepositoryPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodes{
Commits: genclient.PullRequestsViewerPullRequestsNodesCommits{
Nodes: &genclient.PullRequestsViewerPullRequestsNodesCommitsNodes{
{
genclient.PullRequestsRepositoryPullRequestsNodesCommitsNodesCommit{Oid: "3"},
genclient.PullRequestsViewerPullRequestsNodesCommitsNodesCommit{Oid: "3"},
},
},
},
Expand Down
44 changes: 22 additions & 22 deletions github/githubclient/gen/genclient/operations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions github/githubclient/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ query PullRequests(
){
viewer {
login
}
repository(owner:$repo_owner, name:$repo_name) {
id
pullRequests(first:100, states:[OPEN]) {
nodes {
id
Expand Down Expand Up @@ -35,6 +32,9 @@ query PullRequests(
}
}
}
repository(owner:$repo_owner, name:$repo_name) {
id
}
}

query AssignableUsers(
Expand Down

0 comments on commit 4a7e077

Please sign in to comment.