Skip to content

feat: order affected ranges as they are in the version constraint#45

Merged
G-Rath merged 1 commit into
mainfrom
dont-sort
May 26, 2025
Merged

feat: order affected ranges as they are in the version constraint#45
G-Rath merged 1 commit into
mainfrom
dont-sort

Conversation

@G-Rath

@G-Rath G-Rath commented May 22, 2025

Copy link
Copy Markdown
Collaborator

I think this is slightly better since if you're comparing against the original version constraint you in theory don't need to search the whole constraint for the particular range, but really the motivation here is that the current sorting function is a bit choppy from a typing perspective - I was initially going to refactor it, but then realized there's not much difference so here we are.

The order of events in each range should not change nor need explicit sorting as I'm 98% sure it's impossible to express a different order unless we have a bug which is its own issue anyway

I'm happy to discuss different sort orders if people have opinions, but also we can revisit this later if needed too 🤷

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes the previous sorting logic for affected ranges and preserves the order they appear in the version constraint, and updates multiple OSV advisory JSON files to match the new ordering.

  • build_affected_ranges now directly returns ranges in original order, dropping the semver-based sort helpers
  • Unused sorting helper functions (event_to_semver_for_sorting, semver_for_sorting) are removed
  • Advisory JSON files are re-ordered to reflect constraint order and one timestamp is updated

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scripts/generate_osv_advisories.py Simplify build_affected_ranges, remove sorting helpers
advisories/persistent_login/osv-sa-contrib-2024-044.json Re-order ranges to match constraint order
advisories/panels/osv-sa-contrib-2025-033.json Update modified timestamp
advisories/eca/osv-sa-contrib-2025-031.json Re-order ranges to match constraint order
advisories/core/osv-sa-core-2023-005.json Move three version ranges earlier (dedupe bottom section)
Comments suppressed due to low confidence (3)

scripts/generate_osv_advisories.py:291

  • [nitpick] Add a docstring to build_affected_ranges clarifying that it preserves the order of ranges as they appear in the original version constraint.
def build_affected_ranges(sa_advisory: drupal.Advisory) -> list[osv.Range]:

scripts/generate_osv_advisories.py:294

  • [nitpick] Add a unit test to verify that build_affected_ranges returns affected ranges in the exact order they appear in the field_affected_versions string.
return [

scripts/generate_osv_advisories.py:298

  • Remove any remaining imports related to semver and typing.Any if they are no longer used after deleting the sorting helper functions.
def semver_for_sorting(semver: typing.Any) -> str:

@jonholdsworth jonholdsworth left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If that sorting order is indeed guaranteed, this is nice, getting rid of unnecessary code is good.

@Unifex Unifex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Less code is good. The reason makes sense for me too.

LGTM.

@G-Rath G-Rath merged commit a55f0a5 into main May 26, 2025
5 checks passed
@G-Rath G-Rath deleted the dont-sort branch May 26, 2025 00:15
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.

5 participants