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

Use correct latest crates.io version #9454

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nyurik
Copy link

@nyurik nyurik commented Aug 8, 2023

For download count and license, get the correct latest version from the versions array.

Fix #9453

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2023

Warnings
⚠️ This PR modified service code for crates but not its test code.
That's okay so long as it's refactoring existing code.
Messages
📖 ✨ Thanks for your contribution to Shields, @nyurik!

Generated by 🚫 dangerJS against 683a2c9

@calebcartwright
Copy link
Member

I think it would probably be best to first take the simplest route with the existing problem on the yanked version (first non-yanked version), and then have a follow up discussion/potential PR for any logic changes.

@calebcartwright
Copy link
Member

See also #8666, as it may be worth overhauling the selection logic and encapsulating it somewhere for usage across the relevant classes

@nyurik
Copy link
Author

nyurik commented Aug 9, 2023

@calebcartwright thx for the link, it does confirm the same type of logic I used as used by the crates.io itself to compute latest stable vs latest, etc.

I do not think filtering out yanked versions is the right approach. I think everyone's expectation would be that shields show the same version as the default page on crates.io for all non-version-specific requests. The version shield already follows that logic, but the download count and license ones do not. Unfortunately I am not as familiar with ts as I would like, so I might not be the best person for overall code restructuring.

Here's the current logic of crates.io:

  /**
   * This is the default version that will be shown when visiting the crate
   * details page. Note that this can be `undefined` if all versions of the crate
   * have been yanked.
   * @return {string}
   */
  get defaultVersion() {
    if (this.max_stable_version) {
      return this.max_stable_version;
    }
    if (this.max_version && this.max_version !== '0.0.0') {
      return this.max_version;
    }
  }

I think shields should implement the same function in the base class, plus there should be another function defaultVersionObject which finds the .versions array entry that corresponds to the one returned by above defaultVersion().

Then all 3 classes would call it and act accordingly.

@nyurik
Copy link
Author

nyurik commented Aug 9, 2023

oops, i think there was a in-flight issue - i tried to address the comments

@nyurik nyurik force-pushed the fix-latest-ver-cratesio branch 3 times, most recently from 0c41d2d to cfc3e59 Compare August 9, 2023 02:14
@nyurik
Copy link
Author

nyurik commented Aug 9, 2023

After a few back and forth, I think i got the more consolidated version - where the base class handles both the defaultVersion() -> string and defaultVersionObject() -> obj, and the 3 derived classes just use those functions directly. Seems far cleaner, and more consistent with the expectations

@nyurik nyurik force-pushed the fix-latest-ver-cratesio branch 2 times, most recently from 82168cb to 002840c Compare August 13, 2023 01:45
@nyurik
Copy link
Author

nyurik commented Aug 13, 2023

@calebcartwright hi, are there any blockers for this PR? Anything I can improve?

@nyurik
Copy link
Author

nyurik commented Aug 13, 2023

CC: @chris48s - not sure if that's the right person though, my apologies if not

@chris48s
Copy link
Member

chris48s commented Aug 13, 2023

I don't mind jumping in on this one if I need to, but given @calebcartwright

I'm assuming he will do the final review on this one.

@calebcartwright
Copy link
Member

Thanks @nyurik. We're a rather smaller maintainer team, so it's basically an "any maintainer, as and when they have time" review strategy vs. any specific person.

I haven't had a chance to go through the updated code yet, but will also note in response to expectations around versions is that one thing we have to balance is that Shields also has its own behavior around our version badges and we strive for consistency in our badges/badge behavior across the various services and ecosystem.

To be clear, I'm not pushing back on anything nor prescribing anything specific at this point, just noting that we have other factors and constraints our badge defaults work within separate from the target service we fetch data from.

@calebcartwright calebcartwright added the service-badge New or updated service badge label Aug 13, 2023
@nyurik
Copy link
Author

nyurik commented Aug 28, 2023

@calebcartwright thx for the response. I am not too certain I understood it though - shields already uses crate.io-provided "current version" as the default for one of the shields (get current version). What changes are you saying this PR should make in order to be merged? How would this be different from other shields? Thx!

For download count and license, get the correct latest version from the versions array.

Fix badges#9453
@nyurik
Copy link
Author

nyurik commented Oct 30, 2023

@calebcartwright hi, a friendly ping - is there anything i can help with this stalled PR? Please take a look at my last comment about behavior consistency, and how I think Rust shields can benefit from it. Thx!

@calebcartwright
Copy link
Member

@calebcartwright thx for the response. I am not too certain I understood it though - shields already uses crate.io-provided "current version" as the default for one of the shields (get current version). What changes are you saying this PR should make in order to be merged? How would this be different from other shields? Thx!

I was simply sharing some additional context about this project, and that a large part of why it exists in the first place is to provide consistency in badges independent of, and occasionally intentionally in contradiction of, what the upstream systems of records do.

I.e. service/platform Foo doing X does not necessarily mean that we should/will do X too in our badge; we have to balance consistency across an additional layer

@calebcartwright
Copy link
Member

As far as the PR itself, yes the review has stalled out but that's not on you and there's not really anything you can do to help.

We're essentially down to only 1 maintainer that's putting in time on the project consistently, and that's certainly had a detrimental effect on review capacity.

Looking back through the code after some significant amount of time, I can't help but feel like our entire codebase for providing download and version badges from crates.io is surprisingly, and hopefully unnecessarily, complex, and that the changes proposed here are exacerbating that complexity. E.g. the conditionality around the schema, the resultant necessitaty to perform falsy checks (including in some cases duplicatively)

My inclination at this point is actually to investigate a holistic change, and likely simplification, of our crates code, as I fear we're continuing to pile on to some code that's been around for a while and perhaps accounting for things that it doesn't necessarily need to anymore.

I recognize this suggested pivot would perpetuate the current state of an issue like #9453 where the incorrect stat is shown in cases where a crate has a "later" version with a different value and which has been yanked. However, I'm not convinced that's necessarily a common scenario, and I suspect there are some viable workarounds (e.g. /crates/dv/:crate/:version with a specific, correct version, or /crates/dr/:crate/, and/or GitHub or GitLab license badge for the associated repo)

@PyvesB
Copy link
Member

PyvesB commented Sep 22, 2024

@calebcartwright any chance you could take another peak at this one? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
service-badge New or updated service badge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect version shown for crates.io
4 participants