Repository: lindell/multi-gitter
Pull request #325 (2023-02-18 03:33:31)

chore(deps): bump golang.org/x/net from 0.3.0 to 0.7.0
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.3.0 to 0.7.0.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/golang/net/commit/8e2b117aee74f6b86c207a808b0255de45c0a18a"><code>8e2b117</code></a> http2/hpack: avoid quadratic complexity in hpack decoding</li>
<li><a href="https://github.com/golang/net/commit/547e7edf3873d6f3a9c093d3785f9e2289e00746"><code>547e7ed</code></a> http2: avoid referencing ResponseWrite.Write parameter after returning</li>
<li><a href="https://github.com/golang/net/commit/39940adcaaa73e661124cb80fb8dd57ea929dbaf"><code>39940ad</code></a> html: parse comments per HTML spec</li>
<li><a href="https://github.com/golang/net/commit/87ce33ecb484cbb6bcfc8e506ce0330ef72e0847"><code>87ce33e</code></a> go.mod: update golang.org/x dependencies</li>
<li><a href="https://github.com/golang/net/commit/415cb6d518e71d202e2dc2f44c475cbff84eee72"><code>415cb6d</code></a> all: fix some comments</li>
<li><a href="https://github.com/golang/net/commit/7e3c19ca52e202ae203b1914fc00c8e47a4d72fa"><code>7e3c19c</code></a> all: correct typos in comments</li>
<li><a href="https://github.com/golang/net/commit/296f09aa3817abc1ddff7703799bf9babb7bbd16"><code>296f09a</code></a> http2: case insensitive handling for 100-continue</li>
<li><a href="https://github.com/golang/net/commit/f8411da775a685be247bbedcb3ed2c998f895cd2"><code>f8411da</code></a> nettest: fix tests on dragonfly and js/wasm</li>
<li><a href="https://github.com/golang/net/commit/8e0e7d8d38f2b6d21d742845570dde2902d06a1d"><code>8e0e7d8</code></a> go.mod: update golang.org/x dependencies</li>
<li><a href="https://github.com/golang/net/commit/7805fdc37dc2b54b28b9d621030e14dcf1dab67c"><code>7805fdc</code></a> http2: rewrite inbound flow control tracking</li>
<li>Additional commits viewable in <a href="https://github.com/golang/net/compare/v0.3.0...v0.7.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=golang.org/x/net&package-manager=go_modules&previous-version=0.3.0&new-version=0.7.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language

You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/lindell/multi-gitter/network/alerts).

</details>


Patch:
diff --git a/go.mod b/go.mod
index b810529..0469ffa 100644
--- a/go.mod
+++ b/go.mod
@@ -54,7 +54,7 @@ require (
 	github.com/subosito/gotenv v1.4.1 // indirect
 	github.com/xanzy/ssh-agent v0.3.3 // indirect
 	golang.org/x/crypto v0.3.0 // indirect
-	golang.org/x/net v0.6.0 // indirect
+	golang.org/x/net v0.7.0 // indirect
 	golang.org/x/sys v0.5.0 // indirect
 	golang.org/x/text v0.7.0 // indirect
 	golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
diff --git a/go.sum b/go.sum
index 5de0d45..170ecfb 100644
--- a/go.sum
+++ b/go.sum
@@ -352,8 +352,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
 golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
 golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
-golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
-golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
+golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
+golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
diff --git a/internal/scm/github/github.go b/internal/scm/github/github.go
index f9a549a..e890472 100755
--- a/internal/scm/github/github.go
+++ b/internal/scm/github/github.go
@@ -357,6 +357,24 @@ func (g *Github) GetPullRequests(ctx context.Context, branchName string) ([]scm.
 		return nil, err
 	}
 
+	// github limits the amount of data which can be handled by the graphql api
+	// data needs to be chunked into multiple requests
+	batches := chunkSlice(repos, 50)
+	var pullRequests []scm.PullRequest
+
+	for _, repos := range batches {
+		result, err := g.getPullRequests(ctx, branchName, repos)
+		if err != nil {
+			return pullRequests, fmt.Errorf("failed to get pull request batch: %w", err)
+		}
+
+		pullRequests = append(pullRequests, result...)
+	}
+
+	return pullRequests, nil
+}
+
+func (g *Github) getPullRequests(ctx context.Context, branchName string, repos []*github.Repository) ([]scm.PullRequest, error) {
 	// The fragment is all the data needed from every repository
 	const fragment = `fragment repoProperties on Repository {
 		pullRequests(headRefName: $branchName, last: 1) {
@@ -420,7 +438,7 @@ func (g *Github) GetPullRequests(ctx context.Context, branchName string) ([]scm.
 	)
 
 	result := map[string]graphqlRepo{}
-	err = g.makeGraphQLRequest(ctx, query, queryVariables, &result)
+	err := g.makeGraphQLRequest(ctx, query, queryVariables, &result)
 	if err != nil {
 		return nil, err
 	}
@@ -509,7 +527,7 @@ func (g *Github) GetOpenPullRequest(ctx context.Context, repo scm.Repository, br
 		})
 	})
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("failed to get open pull requests: %w", err)
 	}
 	if len(prs) == 0 {
 		return nil, nil
diff --git a/internal/scm/github/graphql.go b/internal/scm/github/graphql.go
index 551e812..5da4ac0 100644
--- a/internal/scm/github/graphql.go
+++ b/internal/scm/github/graphql.go
@@ -21,6 +21,7 @@ func (g *Github) makeGraphQLRequest(ctx context.Context, query string, data inte
 		Query: query,
 		Data:  data,
 	})
+
 	if err != nil {
 		return errors.WithMessage(err, "could not marshal graphql request")
 	}
diff --git a/internal/scm/github/util.go b/internal/scm/github/util.go
index 20a829e..cf26c5f 100644
--- a/internal/scm/github/util.go
+++ b/internal/scm/github/util.go
@@ -35,3 +35,12 @@ func stripSuffixIfExist(str string, suffix string) string {
 	}
 	return str
 }
+
+func chunkSlice[T any](stack []T, chunkSize int) [][]T {
+	var chunks = make([][]T, 0, (len(stack)/chunkSize)+1)
+	for chunkSize < len(stack) {
+		stack, chunks = stack[chunkSize:], append(chunks, stack[0:chunkSize:chunkSize])
+	}
+
+	return append(chunks, stack)
+}


Test patch:
diff --git a/internal/scm/github/util_test.go b/internal/scm/github/util_test.go
new file mode 100644
index 0000000..480d405
--- /dev/null
+++ b/internal/scm/github/util_test.go
@@ -0,0 +1,17 @@
+package github
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func Test_stripSuffixIfExist(t *testing.T) {
+	assert.Equal(t, "string", stripSuffixIfExist("stringSuffix", "Suffix"))
+	assert.Equal(t, "stringSuffix", stripSuffixIfExist("stringSuffix", "NoMatch"))
+}
+
+func Test_chunkSlice(t *testing.T) {
+	assert.Equal(t, [][]int{{0, 1}, {2}}, chunkSlice([]int{0, 1, 2}, 2))
+	assert.Equal(t, [][]int{{0, 1, 2}}, chunkSlice([]int{0, 1, 2}, 4))
+}