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

feat: get repos from graphql #120

Merged
merged 2 commits into from
Feb 8, 2024
Merged

Conversation

giovanni-guidini
Copy link
Contributor

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.

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.
Copy link

codecov-public-qa bot commented Feb 6, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (7b98010) 89.52% compared to head (767c9c1) 89.55%.
Report is 2 commits behind head on main.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #120      +/-   ##
==========================================
+ Coverage   89.52%   89.55%   +0.03%     
==========================================
  Files         115      115              
  Lines        9392     9434      +42     
  Branches     1499     1506       +7     
==========================================
+ Hits         8408     8449      +41     
  Misses        781      781              
- Partials      203      204       +1     
Flag Coverage Δ
python3.10 88.77% <97.56%> (+0.05%) ⬆️
python3.11 88.77% <97.56%> (+0.05%) ⬆️
python3.12 88.77% <97.56%> (+0.05%) ⬆️
python3.8 88.85% <97.56%> (+0.05%) ⬆️
python3.9 89.11% <97.56%> (+0.05%) ⬆️
rust 90.20% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
shared/torngit/github.py 91.89% <97.56%> (+0.36%) ⬆️

... and 2 files with indirect coverage changes

Impacted file tree graph

@codecov-staging
Copy link

codecov-staging bot commented Feb 6, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Files Patch % Lines
shared/torngit/github.py 97.56% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Feb 6, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (7b98010) 89.52% compared to head (767c9c1) 89.55%.
Report is 2 commits behind head on main.

Files Patch % Lines
shared/torngit/github.py 97.56% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #120      +/-   ##
==========================================
+ Coverage   89.52%   89.55%   +0.03%     
==========================================
  Files         115      115              
  Lines        9392     9434      +42     
  Branches     1499     1506       +7     
==========================================
+ Hits         8408     8449      +41     
  Misses        781      781              
- Partials      203      204       +1     
Flag Coverage Δ
python3.10 88.77% <97.56%> (+0.05%) ⬆️
python3.11 88.77% <97.56%> (+0.05%) ⬆️
python3.12 88.77% <97.56%> (+0.05%) ⬆️
python3.8 88.85% <97.56%> (+0.05%) ⬆️
python3.9 89.11% <97.56%> (+0.05%) ⬆️
rust 90.20% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (7b98010) 91.54% compared to head (767c9c1) 91.60%.
Report is 2 commits behind head on main.

Files Patch % Lines
shared/torngit/github.py 97.56% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #120      +/-   ##
==========================================
+ Coverage   91.54%   91.60%   +0.05%     
==========================================
  Files         122      122              
  Lines        9413     9490      +77     
  Branches     1613     1621       +8     
==========================================
+ Hits         8617     8693      +76     
  Misses        781      781              
- Partials       15       16       +1     
Flag Coverage Δ
python3.10 88.77% <97.56%> (+0.05%) ⬆️
python3.11 88.77% <97.56%> (+0.05%) ⬆️
python3.12 88.77% <97.56%> (+0.05%) ⬆️
python3.8 88.85% <97.56%> (+0.05%) ⬆️
python3.9 89.11% <97.56%> (+0.05%) ⬆️
rust 90.20% <ø> (ø)
smart-labels 91.78% <97.56%> (+0.48%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -47,11 +50,46 @@
}
}
}
"""
""",
REPOS_FROM_NODEIDS="""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does github let you fetch the whole list without pagination or will it paginate for you with some default page size?

codecov/engineering-team#139 has an example of pagination with github's graphql api if we need to add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good question that I probably should have put in the PR description.
I spent quite some time trying to get pagination in this query. From the docs it indicates you can specify a first, last and get pageInfo cursors.

But from the explorer docs the nodes query doesn't include the inputs for first and last (I tried, didn't work) AND the Repostory object doesn't include pageInfo as a possible field to query. For that reason I don't think there's pagination? At least I couldn't find a way to paginate the request.

Screenshot 2024-02-07 at 09 08 46

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update: I decided to implement simple pagination from our side just in case.

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.
Copy link
Contributor

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code change looks good to me, would be nice not to need an extra query if we can work that owner info into the first one

Comment on lines +69 to +73
owner {
# This ID is actually the node_id, not the ownerid
id
login
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a separate query for getting owner information or could we include databaseId here?

Copy link
Contributor Author

@giovanni-guidini giovanni-guidini Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have included if it was possible, but that is not a User or Organization object. It's some other node that only include those 2 pieces of information.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIP

@giovanni-guidini giovanni-guidini merged commit d887db5 into main Feb 8, 2024
26 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/get_repos_from_graphql branch February 8, 2024 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants