forked from mozilla-releng/shipit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure /github/branches endpoint returns all branches
This endoint currently only fetches up to 100 branches from Github as this is the maximum number of objects you can get from a single query to the GraphQL endpoint. But `mozilla-vpn-client` has well over 100 branches, and the `release` branches were being excluded from the query. Fix this by using pagination until all branches have been returned. Issue: mozilla-releng#1392
- Loading branch information
Showing
5 changed files
with
114 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pprint import pprint | ||
|
||
import pytest | ||
from flask import Flask | ||
|
||
from shipit_api.admin import github | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def setup(monkeypatch, mocker): | ||
app = Flask(__name__) | ||
app.config["GITHUB_TOKEN"] = "token" | ||
with app.app_context(): | ||
monkeypatch.setattr(github, "current_app", app) | ||
mocker.patch("shipit_api.admin.github._require_auth", return_value=None) | ||
yield | ||
|
||
|
||
def test_list_github_branches(responses): | ||
rsp1 = responses.post( | ||
"https://api.github.com/graphql", | ||
json={ | ||
"data": { | ||
"repository": { | ||
"refs": { | ||
"nodes": [{"name": "foo", "target": {"committedDate": "1"}}, {"name": "bar", "target": {"committedDate": "2"}}], | ||
"pageInfo": {"hasNextPage": True, "endCursor": "abc"}, | ||
} | ||
} | ||
} | ||
}, | ||
) | ||
rsp2 = responses.post( | ||
"https://api.github.com/graphql", | ||
json={ | ||
"data": { | ||
"repository": { | ||
"refs": { | ||
"nodes": [{"name": "baz", "target": {"committedDate": "3"}}], | ||
"pageInfo": {"hasNextPage": False, "endCursor": "def"}, | ||
} | ||
} | ||
} | ||
}, | ||
) | ||
repos = github.list_github_branches("org", "repo", limit=2) | ||
assert b"after" not in rsp1.calls[0].request.body | ||
assert b'after: \\"abc\\",' in rsp2.calls[0].request.body | ||
|
||
print("Dumping for copy/paste:") | ||
pprint(repos) | ||
assert repos == [{"committer_date": "1", "name": "foo"}, {"committer_date": "2", "name": "bar"}, {"committer_date": "3", "name": "baz"}] |