Skip to content

feat: capture any warnings as part of the advisories#46

Merged
G-Rath merged 3 commits into
mainfrom
output-warnings
May 26, 2025
Merged

feat: capture any warnings as part of the advisories#46
G-Rath merged 3 commits into
mainfrom
output-warnings

Conversation

@G-Rath

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

Copy link
Copy Markdown
Collaborator

This will make it easier to determine when an advisory needs improving, and to confirm when a "patch" has successfully addressed a warning, without bloating all our advisories since the majority of them will be warning free.

Note that I've already got fixes for the advisories with warnings in this patch, I just want to have the warnings captured in a "before" commit so that my follow-up patch will be more impressive show the warnings are correctly addressed.

@G-Rath

G-Rath commented May 22, 2025

Copy link
Copy Markdown
Collaborator Author

Initially I implemented a cute little custom dict that omitted the warnings property if it was an empty list when it was being turned into JSON, but decided against that for now as it would only be used in this once - I think it was cool though and hope to use it in future, so I'm sticking it here for now instead:

class D[K, T](dict[K, T]):
  """
  An almost-standard `dict` that does not include in its items properties 
  named `warnings` if their value is an empty list, meaning it will not
  be present when being converted to JSON
  """
  def items(self) -> typing.Any:
    for k in self.keys():
      v = self[k]
      if k != 'warnings' or (isinstance(v, list) and len(v) != 0):
        yield k, v

def build_affected_range(constraint: str) -> osv.Range:
  events, warnings = parse_version_constraint(constraint)

  return {
    'type': 'ECOSYSTEM',
    'events': events,
    'database_specific': D({'constraint': constraint, 'warnings': warnings})
  }

@G-Rath G-Rath force-pushed the output-warnings branch from 2f346be to 1f4050a Compare May 22, 2025 20:27

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

LGTM

@G-Rath G-Rath merged commit 19567d2 into main May 26, 2025
5 checks passed
@G-Rath G-Rath deleted the output-warnings branch May 26, 2025 01:51
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.

3 participants