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 GithubAppInstalltion in the worker #239

Merged
merged 1 commit into from
Feb 1, 2024

Conversation

giovanni-guidini
Copy link
Contributor

depends on: #236

context: codecov/engineering-team#970

usage of the GithubAppInstallation model through the worker.
It still respects and doesn't affect deprecated usages of
owner.integration_id and repo.using_integration, but if a
ghapp exists for the owner it takes precedence over the legacy fields.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Copy link

codecov bot commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (451d112) 98.06% compared to head (a2016bc) 98.07%.

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

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   98.06%   98.07%   +0.01%     
==========================================
  Files         406      406              
  Lines       31545    31714     +169     
==========================================
+ Hits        30936    31105     +169     
  Misses        609      609              
Flag Coverage Δ
integration 98.10% <100.00%> (+0.01%) ⬆️
latest-uploader-overall 98.10% <100.00%> (+0.01%) ⬆️
unit 98.10% <100.00%> (+0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.09% <100.00%> (+0.01%) ⬆️
OutsideTasks 97.93% <100.00%> (+0.01%) ⬆️
Files Coverage Δ
services/bots.py 100.00% <100.00%> (ø)
services/notification/__init__.py 97.60% <100.00%> (+0.18%) ⬆️
.../notification/notifiers/mixins/message/__init__.py 100.00% <ø> (ø)
.../notification/notifiers/tests/unit/test_comment.py 100.00% <100.00%> (ø)
...tification/tests/unit/test_notification_service.py 100.00% <100.00%> (ø)
services/repository.py Critical 96.17% <100.00%> (+0.15%) ⬆️
services/tests/test_bots.py 100.00% <100.00%> (ø)
services/tests/test_repository_service.py 99.76% <100.00%> (+<0.01%) ⬆️
tasks/notify.py Critical 98.41% <100.00%> (+0.03%) ⬆️
tasks/tests/unit/test_upload_task.py 99.50% <100.00%> (+0.01%) ⬆️
... and 1 more
Related Entrypoints
run/app.tasks.pulls.Sync
run/app.tasks.notify.Notify
run/app.tasks.upload.Upload
run/app.tasks.sync_repo_languages.SyncLanguages
run/app.tasks.upload.UploadProcessor
run/app.tasks.compute_comparison.ComputeComparison
run/app.tasks.upload.PreProcessUpload
run/app.tasks.status.SetError
run/app.tasks.commit_update.CommitUpdate
run/app.tasks.sync_repos.SyncRepos
run/app.tasks.sync_teams.SyncTeams

@codecov-staging
Copy link

codecov-staging bot commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   98.09%   98.10%   +0.01%     
==========================================
  Files         375      375              
  Lines       30844    31013     +169     
==========================================
+ Hits        30256    30425     +169     
  Misses        588      588              
Flag Coverage Δ
integration 98.10% <100.00%> (+0.01%) ⬆️
latest-uploader-overall 98.10% <100.00%> (+0.01%) ⬆️
unit 98.10% <100.00%> (+0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.18% <100.00%> (+0.01%) ⬆️
OutsideTasks 97.93% <100.00%> (+0.01%) ⬆️
Files Coverage Δ
services/bots.py 100.00% <100.00%> (ø)
services/notification/__init__.py 97.58% <100.00%> (+0.18%) ⬆️
.../notification/notifiers/mixins/message/__init__.py 100.00% <ø> (ø)
.../notification/notifiers/tests/unit/test_comment.py 100.00% <100.00%> (ø)
...tification/tests/unit/test_notification_service.py 100.00% <100.00%> (ø)
services/repository.py 96.17% <100.00%> (+0.15%) ⬆️
services/tests/test_bots.py 100.00% <100.00%> (ø)
services/tests/test_repository_service.py 99.76% <100.00%> (+<0.01%) ⬆️
tasks/notify.py 98.41% <100.00%> (+0.03%) ⬆️
tasks/tests/unit/test_upload_task.py 99.50% <100.00%> (+0.01%) ⬆️
... and 1 more

@codecov-qa
Copy link

codecov-qa bot commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (451d112) 98.09% compared to head (a2016bc) 98.10%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   98.09%   98.10%   +0.01%     
==========================================
  Files         375      375              
  Lines       30844    31013     +169     
==========================================
+ Hits        30256    30425     +169     
  Misses        588      588              
Flag Coverage Δ
integration 98.10% <100.00%> (+0.01%) ⬆️
latest-uploader-overall 98.10% <100.00%> (+0.01%) ⬆️
unit 98.10% <100.00%> (+0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.18% <100.00%> (+0.01%) ⬆️
OutsideTasks 97.93% <100.00%> (+0.01%) ⬆️
Files Coverage Δ
services/bots.py 100.00% <100.00%> (ø)
services/notification/__init__.py 97.58% <100.00%> (+0.18%) ⬆️
.../notification/notifiers/mixins/message/__init__.py 100.00% <ø> (ø)
.../notification/notifiers/tests/unit/test_comment.py 100.00% <100.00%> (ø)
...tification/tests/unit/test_notification_service.py 100.00% <100.00%> (ø)
services/repository.py 96.17% <100.00%> (+0.15%) ⬆️
services/tests/test_bots.py 100.00% <100.00%> (ø)
services/tests/test_repository_service.py 99.76% <100.00%> (+<0.01%) ⬆️
tasks/notify.py 98.41% <100.00%> (+0.03%) ⬆️
tasks/tests/unit/test_upload_task.py 99.50% <100.00%> (+0.01%) ⬆️
... and 1 more

Copy link

codecov-public-qa bot commented Jan 26, 2024

Codecov Report

Merging #239 (a2016bc) into main (451d112) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #239      +/-   ##
==========================================
+ Coverage   98.09%   98.10%   +0.01%     
==========================================
  Files         375      375              
  Lines       30844    31013     +169     
==========================================
+ Hits        30256    30425     +169     
  Misses        588      588              
Flag Coverage Δ
integration 98.10% <100.00%> (+0.01%) ⬆️
latest-uploader-overall 98.10% <100.00%> (+0.01%) ⬆️
unit 98.10% <100.00%> (+0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 96.18% <100.00%> (+0.01%) ⬆️
OutsideTasks 97.93% <100.00%> (+0.01%) ⬆️
Files Coverage Δ
services/bots.py 100.00% <100.00%> (ø)
services/notification/__init__.py 97.58% <100.00%> (+0.18%) ⬆️
.../notification/notifiers/mixins/message/__init__.py 100.00% <ø> (ø)
.../notification/notifiers/tests/unit/test_comment.py 100.00% <100.00%> (ø)
...tification/tests/unit/test_notification_service.py 100.00% <100.00%> (ø)
services/repository.py 96.17% <100.00%> (+0.15%) ⬆️
services/tests/test_bots.py 100.00% <100.00%> (ø)
services/tests/test_repository_service.py 99.76% <100.00%> (+<0.01%) ⬆️
tasks/notify.py 98.41% <100.00%> (+0.03%) ⬆️
tasks/tests/unit/test_upload_task.py 99.50% <100.00%> (+0.01%) ⬆️
... and 1 more

@@ -179,7 +180,24 @@ async def run_async_within_lock(
"Not sending notifications yet because we are waiting for CI to finish",
extra=dict(repoid=commit.repoid, commit=commit.commitid),
)
if commit.repository.using_integration or commit.repository.hookid:
ghapp_default_installations = list(
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this affects the notify task for coverage uploads. Would it be tough to add the GH App integration for the bundle analysis notifier?

async def notify(self) -> bool:

Copy link
Contributor

Choose a reason for hiding this comment

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

(If unfamiliar, BA uses a different notifier cause the normal notifier relied too much on coverage data being present, hence Scott opted to do a separate notifier wrapper class)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When making these changes I looked for references of .using_integration. There was no such ref in the bundle analysis notifier.

I guess it was decided that that task doesn't need to check this for the timeout on the retry. Personally I think that this implementation here is a bit "too much", but was respecting the logic that's in place.

# Getting owner installation - not tied to any particular repo
return app_installation.installation_id
# DEPRECATED FLOW - begin
if owner.integration_id and deprecated_using_integration:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this code run? How do customers with their integration id tied to their owner start using the new GH App class? Would that be "auto-populated" after syncing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the code can run if there's no GithubAppInstallation object for a given owner.

The GH App objects are populated by the API when we receive the installation webhook.
I don't think there are plans for backfilling this info, so it would only be filled for an existing user if they make changes to their installation.

# DEPRECATED FLOW - end
return None


def get_repo_appropriate_bot_token(repo: Repository) -> Tuple[Dict, Optional[Owner]]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Echoing same thoughts as the other PR, is there a way to test this locally/staging?

)
# filter is an Iterator, so we need to scan matches
# in practice we only consider the 1st one
for app_installation in default_app_installation_filter:
Copy link
Contributor

Choose a reason for hiding this comment

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

will this always contain one or zero installations? or is there a possibility of there being multiple?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently there will always be 0 or 1 installations I believe. That comes from Github when the user installs the codecov gh app to their profile. I don't think it's possible for a user in GH to have multiple installations of the same app in their profile.

Assume in the future there are many such installations for some reason.
The idea of installation_name is to identify app's functionalities in such a way that they are interchangeable.
Although we'd probably want to be able to pass a list of names and select one option randomly... but that's for the future and there might be other implementation choices available.

Base automatically changed from gio/multi-apps/model to main January 29, 2024 12:39
depends on: #236

context: codecov/engineering-team#970

usage of the `GithubAppInstallation` model through the worker.
It still respects and doesn't affect deprecated usages of
`owner.integration_id` and `repo.using_integration`, but if a
ghapp exists for the owner it takes precedence over the legacy fields.
@giovanni-guidini giovanni-guidini merged commit c8afa70 into main Feb 1, 2024
31 of 32 checks passed
@giovanni-guidini giovanni-guidini deleted the gio/multi-apps/usage branch February 1, 2024 16:21
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.

3 participants