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: use GithubAppInstallation in api #347

Merged
merged 5 commits into from
Jan 24, 2024

Conversation

giovanni-guidini
Copy link
Contributor

@giovanni-guidini giovanni-guidini commented Jan 18, 2024

Uses the gh app installation WITHOUT compromising
the old usage (of owner.integration_id).
Deprecated paths are marked so.

These changes don't backfill old data, but start using
the new model with webhooks.

the sample data from tests (the keys) are taken from
github docs
and some amount of empirical data.

depends on: #346

this is PR 2 of 2

@giovanni-guidini giovanni-guidini force-pushed the gio/multi-apps/api-usage branch 2 times, most recently from 0cb80ca to 643a512 Compare January 18, 2024 19:44
Base automatically changed from gio/multi-apps/model to main January 19, 2024 00:05
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

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

Comparison is base (c55a1f4) 95.71% compared to head (25e438a) 95.74%.

Changes have been made to critical files, which contain lines commonly executed in production. Learn more

Files Patch % Lines
services/repo_providers.py 92.30% 1 Missing ⚠️
utils/github.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #347     +/-   ##
=======================================
+ Coverage   95.71   95.74   +0.03     
=======================================
  Files        740     740             
  Lines      16720   16847    +127     
=======================================
+ Hits       16002   16129    +127     
  Misses       718     718             
Flag Coverage Δ
unit 96.06% <96.82%> (+<0.01%) ⬆️
unit-latest-uploader 96.06% <96.82%> (+<0.01%) ⬆️

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.

@giovanni-guidini giovanni-guidini force-pushed the gio/multi-apps/api-usage branch 2 times, most recently from cbf7ebe to 7ec5900 Compare January 19, 2024 00:58
@codecov-staging
Copy link

codecov-staging bot commented Jan 19, 2024

Codecov Report

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

Files Patch % Lines
services/repo_providers.py 92.30% 1 Missing ⚠️
utils/github.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Jan 19, 2024

Codecov Report

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

Comparison is base (fd02145) 96.05% compared to head (bf40467) 96.06%.

Files Patch % Lines
services/repo_providers.py 92.30% 1 Missing ⚠️
utils/github.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #347   +/-   ##
=======================================
  Coverage   96.05%   96.06%           
=======================================
  Files         628      628           
  Lines       16307    16357   +50     
=======================================
+ Hits        15664    15713   +49     
- Misses        643      644    +1     
Flag Coverage Δ
unit 96.06% <96.82%> (+<0.01%) ⬆️
unit-latest-uploader 96.06% <96.82%> (+<0.01%) ⬆️

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-public-qa bot commented Jan 19, 2024

Codecov Report

Merging #347 (bf40467) into main (fd02145) will increase coverage by 0.00%.
The diff coverage is 96.82%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #347   +/-   ##
=======================================
  Coverage   96.05%   96.06%           
=======================================
  Files         628      628           
  Lines       16307    16357   +50     
=======================================
+ Hits        15664    15713   +49     
- Misses        643      644    +1     
Flag Coverage Δ
unit 96.06% <96.82%> (+<0.01%) ⬆️
unit-latest-uploader 96.06% <96.82%> (+<0.01%) ⬆️

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

Files Coverage Δ
upload/helpers.py 94.25% <100.00%> (+0.22%) ⬆️
webhook_handlers/views/github.py 98.99% <100.00%> (+0.11%) ⬆️
services/repo_providers.py 96.49% <92.30%> (-1.43%) ⬇️
utils/github.py 80.00% <50.00%> (ø)

Impacted file tree graph

Uses the gh app installation WITHOUT compromising
the old usage (of `owner.integration_id`).
Deprecated paths are marked so.

These changes don't backfill old data, but start using
the new model with webhooks.

the sample data from tests (the keys) are taken from
[github docs](https://docs.github.com/en/webhooks/webhook-events-and-payloads#installation)
and some amount of empirical data.

depends on: #346
Copy link
Contributor

@adrian-codecov adrian-codecov left a comment

Choose a reason for hiding this comment

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

Some minor comments, otherwise lgtm

@@ -315,20 +322,45 @@ def determine_upload_pr_to_use(upload_params):
return upload_params.get("pr")


def ghapp_installation_id_to_use(repository: Repository) -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm debating if it makes sense to keep this fn here or if it makes sense to add it to the GithubAppInstallation as a method there, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this code should live as a method of GithubAppInstallation.

I think there's enough logic not related to GithubAppInstallation to leave it as is.
Plus in the future we might use this function to house logic to pick one GithubAppInstallation out of many that a user might have.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense to me! Tyty

utils/github.py Show resolved Hide resolved
webhook_handlers/views/github.py Show resolved Hide resolved
Considers ghapp installations when deciding if a torngit adapter
is for a repo with integration or not.

If a ghapp installation exist then repo is considered to be using
integration if it's covered by the installation.
Otherwise previous behavior is used.

The test `test_get_adapter_sets_token_to_bot_when_user_not_authenticated`
includes `owner` as `None` when calling `RepoProviderService.get_adapter` so I'm assuming
that can happen, and changing the typehint in the function.

Other functions that were typehinted with `Owner` instead of `Optional[Owner]` are also
changed.
@giovanni-guidini giovanni-guidini merged commit 86178ba into main Jan 24, 2024
20 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/multi-apps/api-usage branch January 24, 2024 13:01
giovanni-guidini added a commit that referenced this pull request Jan 24, 2024
This reverts commit 86178ba.

This commit caused auth issues with `/graphql` endpoint in which
users were not authenticated and couldn't see source code.

Revertign for now while we figure out the exact issue and fix it.
giovanni-guidini added a commit that referenced this pull request Jan 24, 2024
This reverts commit 86178ba.

This commit caused auth issues with `/graphql` endpoint in which
users were not authenticated and couldn't see source code.

Revertign for now while we figure out the exact issue and fix it.
giovanni-guidini added a commit that referenced this pull request Jan 25, 2024
giovanni-guidini added a commit that referenced this pull request Jan 30, 2024
* Revert "Revert "feat: use GithubAppInstallation in api (#347)" (#355)"

This reverts commit 226f73d.

* fix: logged in users can't see coverage bug

This bug caused a little incident in Codecov.

The actual issue is that we can't make DB queries syncronously from an
async context.

When getting the file content we have to get an adapter,
and that - since the GithubAppInstallation work - required a query to
the database to get the default GithubAppInstallation for an `owner`.
That was the actual error that caused the incident.

Error surfacing was terrible in that endpoint so I changed the `info` log
from an `exception` one so we can have a stacktrace.

To actually fix the error I actually created an async version of `get_adapter`.
I scanned the code, but it seems that this instance is the only place where we
actually use this.

* fix tests

Tests for the interactor (which is async) are now marked as `async`.

I believe that marking them with `@async_to_sync` instead of `pytest.mark.async`
may have hidden the bug that we faced about running the DB query in the async context.
Not tested this theory tho.

* add more unit tests to async paths
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.

None yet

2 participants