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

fallback to assuming repo is covered #406

Closed
wants to merge 2 commits into from

Conversation

giovanni-guidini
Copy link
Contributor

I suspect that we might have a little bug in some situations when syncing repos using integration.

Let's assume that suspicion is true and we might have repos not properly sinced in the installation.
These changes aim to not break the app in a specific scenario:

  • Org installs Codecov App (not selecting all repos)
  • Org admin logs in and sets up a new repo
  • For some reason we fail to sync the repo and the installation list of repos. Maybe we missed a webhook? Would be the only possibility really... but maybe the admin logging in would actually make the repo appear in the DB, even missing the webhook.
  • App is still broken cause the ORG never logged in, and the repo is not marked as "covered" by the installation

The changes here would fix that scenario by ignoring the repo when selecting the token to communicate with GH.
Ideally we fix the sync process and remove this fix, of course.

Notice that if the owner HAS a token or bot than we use that instead.

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.

I suspect that we might have a little bug in some situations when syncing repos using integration.

Let's assume that suspicion is true and we might have repos not properly sinced in the installation.
These changes aim to not break the app in a specific scenario:
- Org installs Codecov App (not selecting all repos)
- Org admin logs in and sets up a new repo
- For some reason we fail to sync the repo and the installation list of repos. Maybe we missed a webhook? Would be the only possibility really... but maybe the admin logging in would actually make the repo appear in the DB, even missing the webhook.
- App is still broken cause the ORG never logged in, and the repo is not marked as "covered" by the installation

The changes here would fix that scenario by ignoring the repo when selecting the token to communicate with GH.
Ideally we fix the sync process and remove this fix, of course.

Notice that if the owner HAS a token or bot than we use that instead.
Copy link

sentry-io bot commented Apr 23, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: services/repository.py

Function Unhandled Issue
get_repo_provider_service TypeError: cannot unpack non-iterable NoneType object app.tasks.sync_repo_languages.SyncLang...
Event Count: 9.6k
get_repo_provider_service TypeError: cannot unpack non-iterable NoneType object app.tasks.upload.U...
Event Count: 2.2k
get_repo_provider_service TypeError: cannot unpack non-iterable NoneType object app.tasks.pulls...
Event Count: 188
get_repo_provider_service TypeError: cannot unpack non-iterable NoneType object app.tasks.compute_comparison.ComputeCompa...
Event Count: 17
get_repo_provider_service TypeError: cannot unpack non-iterable NoneType object app.tasks.notify.N...
Event Count: 10

Did you find this useful? React with a 👍 or 👎

@codecov-notifications
Copy link

codecov-notifications bot commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found ☺️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #406   +/-   ##
=======================================
  Coverage   97.49%   97.49%           
=======================================
  Files         395      395           
  Lines       33370    33393   +23     
=======================================
+ Hits        32533    32556   +23     
  Misses        837      837           
Flag Coverage Δ
integration 97.49% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.49% <100.00%> (+<0.01%) ⬆️
unit 97.49% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 94.86% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.54% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/bots.py 100.00% <ø> (ø)
services/repository.py 96.33% <100.00%> (+0.13%) ⬆️
services/tests/test_repository_service.py 99.77% <100.00%> (+<0.01%) ⬆️

@codecov-qa
Copy link

codecov-qa bot commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.49%. Comparing base (6a3c3b6) to head (ca24891).

❗ Current head ca24891 differs from pull request most recent head 15dde01. Consider uploading reports for the commit 15dde01 to get more accurate results

✅ All tests successful. No failed tests found ☺️

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #406   +/-   ##
=======================================
  Coverage   97.49%   97.49%           
=======================================
  Files         395      395           
  Lines       33370    33395   +25     
=======================================
+ Hits        32533    32558   +25     
  Misses        837      837           
Flag Coverage Δ
integration 97.49% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.49% <100.00%> (+<0.01%) ⬆️
unit 97.49% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 94.86% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.54% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/repository.py 96.36% <100.00%> (+0.17%) ⬆️
services/tests/test_repository_service.py 99.77% <100.00%> (+<0.01%) ⬆️

Copy link

codecov-public-qa bot commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.49%. Comparing base (6a3c3b6) to head (ca24891).

❗ Current head ca24891 differs from pull request most recent head 15dde01. Consider uploading reports for the commit 15dde01 to get more accurate results

✅ All tests successful. No failed tests found ☺️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #406   +/-   ##
=======================================
  Coverage   97.49%   97.49%           
=======================================
  Files         395      395           
  Lines       33370    33395   +25     
=======================================
+ Hits        32533    32558   +25     
  Misses        837      837           
Flag Coverage Δ
integration 97.49% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.49% <100.00%> (+<0.01%) ⬆️
unit 97.49% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 94.86% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.54% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/repository.py 96.36% <100.00%> (+0.17%) ⬆️
services/tests/test_repository_service.py 99.77% <100.00%> (+<0.01%) ⬆️

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.51%. Comparing base (6a3c3b6) to head (15dde01).

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

✅ All tests successful. No failed tests found ☺️

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #406   +/-   ##
=======================================
  Coverage   97.51%   97.51%           
=======================================
  Files         426      426           
  Lines       34070    34093   +23     
=======================================
+ Hits        33223    33246   +23     
  Misses        847      847           
Flag Coverage Δ
integration 97.49% <100.00%> (+<0.01%) ⬆️
latest-uploader-overall 97.49% <100.00%> (+<0.01%) ⬆️
unit 97.49% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
NonTestCode 94.88% <100.00%> (+<0.01%) ⬆️
OutsideTasks 97.54% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
services/bots.py Critical 100.00% <ø> (ø)
services/repository.py Critical 96.33% <100.00%> (+0.13%) ⬆️
services/tests/test_repository_service.py 99.77% <100.00%> (+<0.01%) ⬆️
Related Entrypoints
run/app.tasks.commit_update.CommitUpdate
run/app.tasks.pulls.Sync
run/app.tasks.notify.Notify
run/app.tasks.upload.Upload
run/app.tasks.compute_comparison.ComputeComparison
run/app.tasks.upload.UploadProcessor
run/app.tasks.status.SetError
run/app.tasks.upload.PreProcessUpload
run/app.tasks.ai_pr_review.AiPrReview
run/app.tasks.sync_repo_languages.SyncLanguages
run/app.tasks.bundle_analysis.BundleAnalysisNotify

joseph-sentry
joseph-sentry previously approved these changes Apr 23, 2024
Copy link
Contributor

@joseph-sentry joseph-sentry left a comment

Choose a reason for hiding this comment

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

just one comment that you can fix, the change looks good, the logic is starting to get a little complicated so it may make sense to move some things into their own functions and document the idea behind how we're handling errors using comments later

ignore_installation=False,
installation_name=installation_name_to_use,
)
print("INSTALLATION INFO (no repo)", installation_info_without_considering_repo)
Copy link
Contributor

Choose a reason for hiding this comment

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

the content in these print statements can still remain, but they should probably be log.info

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, I forgot to remove those :E

repository, installation_info
)
except RepositoryWithoutValidBotError:
# GitHub exclusive bit -- START
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check owner.service?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not a problem if we don't check cause it would just raise the exception again, but yeah, makes sense to do that as save a few operations... and have a clearer distinction of logic in the code.

fallback_installations=(
installation_info.get("fallback_installations")
if installation_info
else None
Copy link
Contributor

Choose a reason for hiding this comment

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

So is to have a fallback option, the gh app we think doesn't have that repo selected correct?

If there is a fallback, and it indeed doesn't have the repo in that fallback, would it eventually error out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a lint change. It's not directly related to the change here.

We only have fallback installations if the user in question has multiple configured apps (dedicated cloud). In this case you would have installations that cover the repo (more than 1 actually) and not raise RepoBotNotConfigured.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see that makes sense, okok ty

@giovanni-guidini
Copy link
Contributor Author

Now that the sync_repos bug is fixed and we ran the backfill task for gh apps this seems unecessary

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

4 participants