Skip to content

Add Codecov User Resolution #90411

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

Merged
merged 1 commit into from
Apr 28, 2025

Conversation

michelletran-codecov
Copy link
Contributor

Codecov needs to map the Sentry user onto a GitHub identity to be able to link them to the associated Codecov user. This returns the external_id (GitHub id) and the auth_token to be encrypted and used for requests to Codecov.

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. and is gonna need some rights from me in order to utilize my contributions in this here 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.

@michelletran-codecov michelletran-codecov requested review from a team April 25, 2025 18:47
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 25, 2025
@michelletran-codecov michelletran-codecov force-pushed the CCMRG-458_add_codecov_user_resolution branch from fc746b2 to be16d8f Compare April 25, 2025 18:55
@michelletran-codecov michelletran-codecov requested a review from a team April 25, 2025 18:58
@michelletran-codecov michelletran-codecov force-pushed the CCMRG-458_add_codecov_user_resolution branch from be16d8f to 22cb4e8 Compare April 25, 2025 19:10
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #90411   +/-   ##
=======================================
  Coverage   87.78%   87.78%           
=======================================
  Files       10261    10263    +2     
  Lines      580220   580260   +40     
  Branches    22636    22636           
=======================================
+ Hits       509340   509378   +38     
- Misses      70445    70447    +2     
  Partials      435      435           

auth_token: Any


def codecov_user_resolution(user_id: int, organization_id: int) -> CodecovUser | None:
Copy link
Member

Choose a reason for hiding this comment

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

maybe resolve_codecov_user would be a better name?

user_id=user_id, provider_type="github"
)
if identities:
identity = identities[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we get many identities? And if so, why would we always choose the first? Perhaps a comment to help understand this 👌

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 I checked the database, there should be only one identity mapped to GitHub per user at this point. So, in practice, this is currently zero or one user. I can add a comment for this. 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

gotchaa so this will be like a one off mapping?

Copy link

@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.

do we still need to look up IDs for GitHub orgs that are relevant to the current Sentry context? not saying to do it in this PR, just checking whether that's still part of the plan


def resolve_codecov_user(user_id: int, organization_id: int) -> CodecovUser | None:
"""Given a Sentry User, and an organization id, find the GitHub user ID and GH access_token
that is linked to Codecov's user.

Choose a reason for hiding this comment

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

"that is linked to Codecov's user" implies Codecov has its own notion of this user's identity. maybe word like "that we can provide in place of a Codecov User"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, we're using the GH id to link it to Codecov's concept of a user (we are still using the owner object in Codecov). The name of the method might be confusing? As we're technically finding the GH user to link to Codecov.

"""
# Get identity from an AuthProvider if it's available.
auth_provider = access_service.get_auth_provider(organization_id)
if auth_provider and auth_provider.provider == "github":

Choose a reason for hiding this comment

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

are there constants/enums for auth_provider.provider and provider_type values?

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 haven't seen an enum

@michelletran-codecov michelletran-codecov force-pushed the CCMRG-458_add_codecov_user_resolution branch from 81fe2de to d6cb285 Compare April 28, 2025 19:56
@michelletran-codecov
Copy link
Contributor Author

do we still need to look up IDs for GitHub orgs that are relevant to the current Sentry context?

Yes. I'm going to do it in another PR.

Codecov needs to map the Sentry user onto a GitHub identity to be able to link them to the
associated Codecov user. This returns the external_id (GitHub id) and the auth_token to be
encrypted and used for requests to Codecov.
@michelletran-codecov michelletran-codecov force-pushed the CCMRG-458_add_codecov_user_resolution branch from d6cb285 to 50b4c8b Compare April 28, 2025 19:59
@michelletran-codecov michelletran-codecov merged commit a8c18c4 into master Apr 28, 2025
63 checks passed
@michelletran-codecov michelletran-codecov deleted the CCMRG-458_add_codecov_user_resolution branch April 28, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants