Skip to content

📝 CodeRabbit Chat: Implement requested code changes#341

Open
coderabbitai[bot] wants to merge 2 commits intomainfrom
coderabbitai/chat/7043b28
Open

📝 CodeRabbit Chat: Implement requested code changes#341
coderabbitai[bot] wants to merge 2 commits intomainfrom
coderabbitai/chat/7043b28

Conversation

@coderabbitai
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot commented Apr 15, 2026

Code changes was requested by @leynos.

The following files were modified:

  • security/audit-utils.js

Summary by Sourcery

Enhancements:

  • Extract helper functions to add and normalise per-package advisories while preserving de-duplication and metadata enrichment during bulk advisory processing.

leynos and others added 2 commits April 15, 2026 17:12
… pnpm audit

- Added fallback to npm bulk advisory endpoint when pnpm audit endpoint is retired.
- Improved resilience by parsing legacy and new audit outputs uniformly.
- Updated audit utilities to fetch installed package versions and query bulk advisories.
- Enhanced validate-audit.js to await asynchronous runAuditJson for advisory validation.
- Added comprehensive tests for the shared audit helper including bulk advisory fallback.
- Updated Makefile audit target to run audit:validate for consistent validation.

This enables seamless audit compliance checks despite registry audit endpoint changes.

Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
@coderabbitai coderabbitai Bot requested a review from leynos April 15, 2026 17:40
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 15, 2026

Reviewer's Guide

Refactors bulk advisory normalization in audit-utils.js by extracting helper functions for adding and processing package advisories, improving deduplication logic and structure while preserving behavior, along with a minor formatting change.

Sequence diagram for bulk advisory normalization helpers

sequenceDiagram
  participant Caller
  participant Normaliser as normaliseBulkAdvisories
  participant PackageNormaliser as normalisePackageAdvisories
  participant Adder as addNormalisedAdvisory
  participant Extractor as extractGithubAdvisoryId

  Caller->>Normaliser: normaliseBulkAdvisories bulkPayload
  Note over Normaliser: Create advisories object
  Normaliser->>Normaliser: Object.entries bulkPayload
  loop for each packageName and packageAdvisories
    Normaliser->>PackageNormaliser: normalisePackageAdvisories advisories, packageName, packageAdvisories
    PackageNormaliser->>PackageNormaliser: Check Array.isArray packageAdvisories
    alt packageAdvisories is not array
      PackageNormaliser-->>Normaliser: return
    else packageAdvisories is array
      loop for each advisory in packageAdvisories
        PackageNormaliser->>Adder: addNormalisedAdvisory advisories, packageName, advisory
        Adder->>Extractor: extractGithubAdvisoryId advisory url
        Extractor-->>Adder: githubAdvisoryId
        Adder->>Adder: Compute advisoryKey
        Adder->>Adder: Check advisoryKey in advisories
        alt advisoryKey exists
          Adder-->>PackageNormaliser: return without change
        else advisoryKey does not exist
          Adder->>Adder: Set advisories advisoryKey with advisory, github_advisory_id, package_name
          Adder-->>PackageNormaliser: return
        end
      end
      PackageNormaliser-->>Normaliser: return
    end
  end
  Normaliser-->>Caller: advisories
Loading

Flow diagram for normaliseBulkAdvisories refactor

flowchart TD
  A[normaliseBulkAdvisories receives bulkPayload] --> B{bulkPayload is null or undefined?}
  B -->|yes| C[Use empty object for iteration]
  B -->|no| D[Use bulkPayload entries]

  C --> E[Iterate Object.entries]
  D --> E[Iterate Object.entries]

  E --> F[For each entry get packageName and packageAdvisories]
  F --> G[Call normalisePackageAdvisories with advisories, packageName, packageAdvisories]

  G --> H{packageAdvisories is an array?}
  H -->|no| I[Return without changes]
  H -->|yes| J[Iterate advisories in packageAdvisories]

  J --> K[For each advisory call addNormalisedAdvisory]

  K --> L[addNormalisedAdvisory receives advisories, packageName, advisory]
  L --> M[Compute githubAdvisoryId via extractGithubAdvisoryId]
  M --> N[Compute advisoryKey as githubAdvisoryId or packageName colon id or unknown]

  N --> O{advisoryKey already in advisories?}
  O -->|yes| P[Return without adding duplicate]
  O -->|no| Q[Store advisory object keyed by advisoryKey with github_advisory_id and package_name]

  P --> R[Continue iteration]
  Q --> R[Continue iteration]

  R --> S[All entries processed]
  S --> T[Return advisories object]
Loading

File-Level Changes

Change Details Files
Refactor bulk advisory normalization into reusable helpers while preserving advisory deduplication and metadata enrichment.
  • Introduce addNormalisedAdvisory to compute stable advisory keys (GitHub ID or package/id fallback), skip duplicates, and attach github_advisory_id and package_name fields
  • Introduce normalisePackageAdvisories to validate advisory arrays and delegate per-advisory processing to addNormalisedAdvisory
  • Simplify normaliseBulkAdvisories to iterate bulk payload entries and call normalisePackageAdvisories for each package
  • Retain nullish-coalescing and optional-chaining behavior when deriving advisory IDs and handling missing payloads
security/audit-utils.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor Author

coderabbitai Bot commented Apr 15, 2026

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 70b3cc31-4381-4a3c-b8c4-3127300c52d9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="security/audit-utils.js" line_range="164" />
<code_context>
-      if (advisoryKey in advisories) {
-        continue;
-      }
+function normalisePackageAdvisories(advisories, packageName, packageAdvisories) {
+  if (!Array.isArray(packageAdvisories)) {
+    return;
</code_context>
<issue_to_address>
**issue (complexity):** Consider inlining the trivial normalisePackageAdvisories logic into normaliseBulkAdvisories while keeping addNormalisedAdvisory as the single helper for per-advisory normalisation.

You can simplify this by inlining `normalisePackageAdvisories` back into `normaliseBulkAdvisories` while keeping the useful `addNormalisedAdvisory` helper. This removes an extra layer of indirection without changing behaviour.

```js
function addNormalisedAdvisory(advisories, packageName, advisory) {
  const githubAdvisoryId = extractGithubAdvisoryId(advisory?.url);
  const advisoryKey =
    githubAdvisoryId ?? `${packageName}:${String(advisory?.id ?? 'unknown')}`;

  if (advisoryKey in advisories) {
    return;
  }

  advisories[advisoryKey] = {
    ...advisory,
    github_advisory_id: githubAdvisoryId,
    package_name: packageName,
  };
}

// Drop normalisePackageAdvisories and inline its trivial logic:
function normaliseBulkAdvisories(bulkPayload) {
  const advisories = {};

  for (const [packageName, packageAdvisories] of Object.entries(bulkPayload ?? {})) {
    if (!Array.isArray(packageAdvisories)) continue;

    for (const advisory of packageAdvisories) {
      addNormalisedAdvisory(advisories, packageName, advisory);
    }
  }

  return advisories;
}
```

This keeps the normalisation logic for each advisory encapsulated, but makes the per-package control flow visible in one place.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread security/audit-utils.js
if (advisoryKey in advisories) {
continue;
}
function normalisePackageAdvisories(advisories, packageName, packageAdvisories) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (complexity): Consider inlining the trivial normalisePackageAdvisories logic into normaliseBulkAdvisories while keeping addNormalisedAdvisory as the single helper for per-advisory normalisation.

You can simplify this by inlining normalisePackageAdvisories back into normaliseBulkAdvisories while keeping the useful addNormalisedAdvisory helper. This removes an extra layer of indirection without changing behaviour.

function addNormalisedAdvisory(advisories, packageName, advisory) {
  const githubAdvisoryId = extractGithubAdvisoryId(advisory?.url);
  const advisoryKey =
    githubAdvisoryId ?? `${packageName}:${String(advisory?.id ?? 'unknown')}`;

  if (advisoryKey in advisories) {
    return;
  }

  advisories[advisoryKey] = {
    ...advisory,
    github_advisory_id: githubAdvisoryId,
    package_name: packageName,
  };
}

// Drop normalisePackageAdvisories and inline its trivial logic:
function normaliseBulkAdvisories(bulkPayload) {
  const advisories = {};

  for (const [packageName, packageAdvisories] of Object.entries(bulkPayload ?? {})) {
    if (!Array.isArray(packageAdvisories)) continue;

    for (const advisory of packageAdvisories) {
      addNormalisedAdvisory(advisories, packageName, advisory);
    }
  }

  return advisories;
}

This keeps the normalisation logic for each advisory encapsulated, but makes the per-package control flow visible in one place.

Base automatically changed from fix-ci-audit-failure-frontend-pwa-k31pyk to main April 17, 2026 11:17
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.

1 participant