-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: get repos from graphql context: codecov/engineering-team#971 Adds function to get repositories from Github's GraphQL api. It uses node_id to get the specified node from gh. This can be found in the INSTALLATION webhook that we will process. Along with it there will be the databaseId (service_id). Adding the `expected_owner` entry because when processing an installation webhook we do know what the expected owner is. Fetching the owner would require another request, but can be done (again by node_id) The idea is to use this function when syncing repos if we know what the repos covered by an installation are. * add owner lookup and pagination There's been question if the nodes query has pagination. So we don't trip up unecessarilly I decided to implement simple pagination ourselves. I made page_size 100 as github docs indicate that that's the max number of records you can get at once from endpoints that use `first` or `last` pagination. 100 repos is a lot of repos. I was also not sure if _all_ repos will actually belong to the same owner. Just in case I decided to add owner lookup as well. Notice it does 1 extra request per unique owner that we encounter. We can use this info to upsert owners if needed.
- Loading branch information
1 parent
1afb5ad
commit d887db5
Showing
4 changed files
with
435 additions
and
3 deletions.
There are no files selected for viewing
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
81 changes: 81 additions & 0 deletions
81
...ration/cassetes/test_github/TestGithubTestCase/test_get_repos_from_nodeids_generator.yaml
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,81 @@ | ||
interactions: | ||
- request: | ||
body: '{"query": "\nquery GetReposFromNodeIds($node_ids: [ID!]!) {\n nodes(ids: | ||
$node_ids) {\n __typename \n ... on Repository {\n # | ||
databaseId == service_id\n databaseId\n name\n primaryLanguage | ||
{\n name\n }\n isPrivate\n defaultBranchRef | ||
{\n name\n }\n owner {\n # | ||
This ID is actually the node_id, not the ownerid\n id\n login\n }\n }\n }\n}\n", | ||
"variables": {"node_ids": ["R_kgDOHrbKcg", "R_kgDOLEJx2g"]}}' | ||
headers: | ||
accept: | ||
- application/json | ||
accept-encoding: | ||
- gzip, deflate | ||
connection: | ||
- keep-alive | ||
content-length: | ||
- '613' | ||
content-type: | ||
- application/json | ||
host: | ||
- api.github.com | ||
user-agent: | ||
- Default | ||
method: POST | ||
uri: https://api.github.com/graphql | ||
response: | ||
content: '{"data":{"nodes":[{"__typename":"Repository","databaseId":515295858,"name":"example-python","primaryLanguage":{"name":"Shell"},"isPrivate":false,"defaultBranchRef":{"name":"master"},"owner":{"id":"U_kgDOBZOfKw","login":"codecove2e"}},{"__typename":"Repository","databaseId":742552026,"name":"test-no-languages","primaryLanguage":null,"isPrivate":false,"defaultBranchRef":null,"owner":{"id":"U_kgDOBZOfKw","login":"codecove2e"}}]}}' | ||
headers: | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Access-Control-Expose-Headers: | ||
- ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, | ||
X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, | ||
X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, | ||
X-GitHub-Request-Id, Deprecation, Sunset | ||
Content-Encoding: | ||
- gzip | ||
Content-Security-Policy: | ||
- default-src 'none' | ||
Content-Type: | ||
- application/json; charset=utf-8 | ||
Date: | ||
- Tue, 06 Feb 2024 13:21:07 GMT | ||
Referrer-Policy: | ||
- origin-when-cross-origin, strict-origin-when-cross-origin | ||
Server: | ||
- GitHub.com | ||
Strict-Transport-Security: | ||
- max-age=31536000; includeSubdomains; preload | ||
Transfer-Encoding: | ||
- chunked | ||
Vary: | ||
- Accept-Encoding, Accept, X-Requested-With | ||
X-Accepted-OAuth-Scopes: | ||
- repo | ||
X-Content-Type-Options: | ||
- nosniff | ||
X-Frame-Options: | ||
- deny | ||
X-GitHub-Media-Type: | ||
- github.v4 | ||
X-GitHub-Request-Id: | ||
- C11E:116D76:8B8D4:94D71:65C23242 | ||
X-OAuth-Scopes: | ||
- repo | ||
X-RateLimit-Limit: | ||
- '5000' | ||
X-RateLimit-Remaining: | ||
- '4997' | ||
X-RateLimit-Reset: | ||
- '1707227531' | ||
X-RateLimit-Resource: | ||
- graphql | ||
X-RateLimit-Used: | ||
- '3' | ||
X-XSS-Protection: | ||
- '0' | ||
http_version: HTTP/1.1 | ||
status_code: 200 | ||
version: 1 |
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
Oops, something went wrong.