Skip to content

feat: (Codecov) add updateRepository function to update local storage and url query params for repo selection #89818

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

Conversation

adrian-codecov
Copy link
Contributor

@adrian-codecov adrian-codecov commented Apr 16, 2025

This PR adds the ability to store repository data to the URL query parameters as well as local storage and reflux.

For the Codecov to Sentry project, we're tasked with adding a series of components, some of which would benefit from saving fields into local storage and url params. Those selectors are seen in this image below, from left to right: Codecov organization (different from what Sentry calls an organization), a repository, a branch and a time range - this PR focuses on the adding repository functionality exclusively.
Screenshot 2025-04-14 at 1 06 48 PM

Main Features

  • Add updateRepository function in actionCreators, which calls the updateRepository reflux store function and updates + persists the repository in local storage and the url.
  • Add updateRepository function in pageFiltersStore, which mainly updates the state w/ the repository selection (see notes on absence of desync).
  • Adjust logic in several places, such as parse.tsx, persistence.tsx, pageFilters.tsx, to also evaluate for a repository.
  • Add repository in several types as needed. Some types accept the repository field to be undefined as otherwise I'd affect other non-related Codecov services would have to declare the repository when updating environments, projects or dates. I can adjust this if needed.
  • Adds/adjusts tests to include repository key when appropriate.

Update

  • After the first pass, I had to adjust a ton of tests that relied on the PageFilter store state, as my changes involves adding a new variable to the state. To make this less painful for next time, I moved all the tests signalled by TS to use a PageFilter fixture. Hence there's a big number of tests changed, but hopefully next time we add a variable to the filter, we only need to change the fixture instead.

Notes

  • Any feedback is welcome, specially since I'm touching a part of the code that will affect non-Codecov functionality with the new repository key being part of localstorage data.
  • I'll have another PR with a UI component soon that can help for manual testing for this deployment.
  • There's some things I'm not doing as I'm unfamiliar with the implications but I'm happy to address those if necessary. Off the top of my head, these include:
    • Adding the desync logic in case the URL params and store data is different.
    • Pinned filters: my understanding is there was an old way of storing things and a new way (pinning), so I added repository to that list. Please correct me if that's mistaken.

Thanks!

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 16, 2025
@adrian-codecov adrian-codecov changed the title feat: add updateRepository function to update local storage and url query params for repo selection feat: (Codecov) add updateRepository function to update local storage and url query params for repo selection Apr 16, 2025
Copy link
Contributor

@nicholas-codecov nicholas-codecov left a comment

Choose a reason for hiding this comment

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

everything looks good to me

@ryan953
Copy link
Member

ryan953 commented Apr 17, 2025

My initial thinking is that: it seems good to re-use the url and localstorage stuff that powers the global pageFilters stuff.

However adding in optional params to the top-level code interface seems like it'll be annoying over time. You'll probably want a unique version of pageFilters that will capture and require org+repo+branch+time. So i'd really suggest taking a look at splitting things up and planning for something that has strong types, but can still share some methods under the hood.

Copy link

codecov bot commented Apr 22, 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   #89818      +/-   ##
==========================================
- Coverage   83.07%   83.07%   -0.01%     
==========================================
  Files       10261    10261              
  Lines      579556   579549       -7     
  Branches    22622    22622              
==========================================
- Hits       481491   481484       -7     
  Misses      97622    97622              
  Partials      443      443              

@calvin-codecov calvin-codecov requested review from calvin-codecov and removed request for calvin-codecov April 23, 2025 21:27
@adrian-codecov adrian-codecov requested review from a team as code owners April 24, 2025 18:52
@adrian-codecov
Copy link
Contributor Author

Thanks for the pointers and advice @ryan953 and @malwilley!

Proceeded to make separate but similar types for the Codecov filters, allowing to reuse most of the functionality and keep things separate. I did create some methods exclusive to Codecov where relevant, as well as rename some types like SentryPageFilterUpdate to then create an overarching type like type PageFiltersUpdate = SentryPageFilterUpdate & CodecovPageFiltersUpdate - let me know if this is okay.

No sentry hook or file was affected, which is good w/ the type separation, just had to adjust a bunch of tests as the PageFilters' state will inevitably change with the addition of the repository key. As suggested per @malwilley, adjusted all of those tests to use a page filter fixture so next time we make a change to these we only have to change the fixture rather than the whole test.

Please let me know how it looks!

@@ -72,20 +79,27 @@ interface PageFiltersStoreDefinition extends StrictStoreDefinition<PageFiltersSt
pinned: Set<PinnedPageFilter>,
persist?: boolean
): void;
onInitializeUrlStateWithCodecovData(
Copy link
Member

Choose a reason for hiding this comment

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

It feels wrong to me that we separate codecov and sentry selections in these functions, yet the underlying state is a combination of the two. But the only other option I can think of is creating a completely separate store to track the codecov selection which is probably prohibitively difficult.

Not requesting changes based on this, just noting my thoughts about it. Tagging the frontend github team to see if anyone else has good ideas.

Copy link
Contributor Author

@adrian-codecov adrian-codecov Apr 24, 2025

Choose a reason for hiding this comment

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

Yeah it's not the most elegant solution but it's the one that caused less friction.

I tried adding an extra param to the existing initialize function, but that affected a bunch of other tests - it's an option but I'm not the biggest fan. Luckily this function is only used once, so it'd only affect one code file there.

Alternatively, I had fused the newSelection param to expect type SentryFilters + CodecovFilters, and inside the initialize fn create a helper that split that object into 'sentrySelection' and 'codecovSelection', but I wasn't too convinced with this one either.

Open to ideas!

Copy link
Member

Choose a reason for hiding this comment

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

I agree here with @malwilley, this feels wrong.

I tried adding an extra param to the existing initialize function, but that affected a bunch of other tests - it's an option but I'm not the biggest fan. Luckily this function is only used once, so it'd only affect one code file there.

Understood, but that is somewhat expected, as you are touching some code that is used very often at Sentry. Updating a ton of tests isn't great, and I get that it's tedious, but it's a lot easier than maintaining two different implementations under the hood.

@malwilley malwilley requested a review from a team April 24, 2025 23:14
@adrianviquez
Copy link
Contributor

Thanks for the pointers @malwilley and @scttcper, ready for another pass!

(I changed my GH account to my personal one so you'll see my recent commits are by a different user)

Copy link
Member

@JonasBa JonasBa left a comment

Choose a reason for hiding this comment

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

This feels like a bad move for the codebase for numerous reasons. I get that it's easy to add yet another flow, but this isn't the right solution. If Codecov is being merged into Sentry, we shouldn't need a separate code flow at the page filter level.

I would like to understand the issues of the considered alternatives (documenting them would go a long way here). You mentioned adding a query param breaks a lot of tests, which is somewhat expected, and while annoying, isn't particularly hard to fix. Miantaining an entirely separate flow and implementation for Codecov is something that is going to linger in the codebase forever, and I'd much rather we find a good implementation from the start and really integrate codecov into sentry as a first class product.

I am willing to help and dedicate some time to getting this properly integrated into our current pagefilters if that helps.

@@ -70,6 +83,10 @@ type PageFiltersUpdate = {
utc?: boolean | null;
};

type CodecovPageFiltersUpdate = {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a distinction of Codecov vs Sentry? If we are merging Codecov to Sentry, then this should not exist, and it should just be Sentry going forward.

I'm not a fan of this approach, as I'm fairly sure it will linger around until someone ultimately needs to address it (at which point, we'll have a lot of the code relying on this and it'll be a massive PITA to update)

@@ -72,20 +79,27 @@ interface PageFiltersStoreDefinition extends StrictStoreDefinition<PageFiltersSt
pinned: Set<PinnedPageFilter>,
persist?: boolean
): void;
onInitializeUrlStateWithCodecovData(
Copy link
Member

Choose a reason for hiding this comment

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

I agree here with @malwilley, this feels wrong.

I tried adding an extra param to the existing initialize function, but that affected a bunch of other tests - it's an option but I'm not the biggest fan. Luckily this function is only used once, so it'd only affect one code file there.

Understood, but that is somewhat expected, as you are touching some code that is used very often at Sentry. Updating a ton of tests isn't great, and I get that it's tedious, but it's a lot easier than maintaining two different implementations under the hood.

@adrianviquez
Copy link
Contributor

closing in favor of #90693

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants