Skip to content

fix: preserve folder/request ordering in Postman export#7581

Merged
bijin-bruno merged 1 commit into
usebruno:mainfrom
abhishek-bruno:fix/postman-export-preserve-item-ordering
Mar 26, 2026
Merged

fix: preserve folder/request ordering in Postman export#7581
bijin-bruno merged 1 commit into
usebruno:mainfrom
abhishek-bruno:fix/postman-export-preserve-item-ordering

Conversation

@abhishek-bruno
Copy link
Copy Markdown
Member

@abhishek-bruno abhishek-bruno commented Mar 26, 2026

Description

JIRA

  • Fixes Postman export does not preserve folder/request ordering #7535 — Postman export now preserves the same folder/request ordering as the Bruno sidebar
  • Folders are sorted using sortByNameThenSequence (alphabetical with seq-based positioning), requests by seq ascending, with folders appearing before requests — matching the sidebar and CLI runner behavior
  • Sorting applies recursively to nested folders

Changes

  • packages/bruno-converters/src/postman/bruno-to-postman.js — Added sort helpers and modified generateItemSection to sort items before mapping to Postman format
  • packages/bruno-converters/tests/postman/bruno-to-postman.spec.js — Added 5 integration tests for ordering behavior

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features
    • Postman collection exports now feature deterministic, hierarchical ordering
    • Folders consistently appear before requests in exported collections
    • Items are organized by sequence and name for improved structure

- Added functions to sort items by sequence and name, ensuring folders are prioritized over requests in the export output.
- Enhanced the `brunoToPostman` function to utilize the new sorting logic.
- Introduced comprehensive tests to validate the sorting behavior for folders and requests, including nested structures.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 26, 2026

Walkthrough

This change adds deterministic ordering to Postman collection exports. The generateItemSection function now applies sorting before export—placing folders before requests, ordering folders alphabetically with seq precedence, and sorting requests by ascending seq—matching Bruno's sidebar display logic.

Changes

Cohort / File(s) Summary
Postman Export Ordering
packages/bruno-converters/src/postman/bruno-to-postman.js
Added helper functions to classify folders vs. requests and sort items deterministically: folders ordered by name/seq, requests by ascending seq. Introduced sortItemsForExport to apply sorting before mapping in generateItemSection, ensuring consistent export ordering.
Export Ordering Tests
packages/bruno-converters/tests/postman/bruno-to-postman.spec.js
Added comprehensive test suite validating folder-first ordering, alphabetical folder sorting, request sorting by seq, recursive folder nesting, and handling of items without seq. Five test cases cover the full ordering specification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

size/M

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • bijin-bruno

Poem

📦 Folders first, then requests aligned,
Alphabetically sorted, seq refined,
Export chaos tamed with order divine,
Postman collections now perfectly designed ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main change: deterministic ordering of folders and requests in Postman exports to preserve Bruno sidebar ordering.
Linked Issues check ✅ Passed All coding objectives from issue #7535 are met: folders separated and sorted by name/sequence, requests sorted by seq ascending, folders placed before requests, and sorting applied recursively to nested items.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #7535: sort helpers and generateItemSection modifications in the converter, plus integration tests validating the new ordering behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/bruno-converters/src/postman/bruno-to-postman.js (1)

9-36: Consider adding a JSDoc comment to explain the sorting strategy.

This algorithm is non-trivial: alphabetical sort first, then inserting items with valid seq at their target positions while grouping duplicates. A brief doc comment would help future maintainers understand the intent without tracing through the logic.

Also, minor style nit: prefer f.seq over f['seq'] for consistency with the rest of the codebase.

Proposed JSDoc and style fix
+/**
+ * Sorts items alphabetically by name, then repositions items with a valid
+ * integer seq (>0) to their target index (seq - 1). Items sharing the same
+ * seq are grouped together.
+ */
 const sortByNameThenSequence = (items) => {
   const isSeqValid = (seq) => Number.isFinite(seq) && Number.isInteger(seq) && seq > 0;

   const alphabeticallySorted = [...items].sort((a, b) => a.name && b.name && a.name.localeCompare(b.name));

-  const withoutSeq = alphabeticallySorted.filter((f) => !isSeqValid(f['seq']));
-  const withSeq = alphabeticallySorted.filter((f) => isSeqValid(f['seq'])).sort((a, b) => a.seq - b.seq);
+  const withoutSeq = alphabeticallySorted.filter((f) => !isSeqValid(f.seq));
+  const withSeq = alphabeticallySorted.filter((f) => isSeqValid(f.seq)).sort((a, b) => a.seq - b.seq);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-converters/src/postman/bruno-to-postman.js` around lines 9 -
36, Add a clear JSDoc above the sortByNameThenSequence function describing the
two-step sorting strategy (alphabetical by name, then insert items with a valid
seq at seq-1 positions, grouping duplicates) and any edge-cases (non-positive or
missing seq values), and update occurrences of f['seq'] to use dot notation
(f.seq) for consistency; ensure the JSDoc names the function and parameters and
briefly describes the return value so future maintainers can understand the
intent without reading the implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bruno-converters/src/postman/bruno-to-postman.js`:
- Around line 9-36: Add a clear JSDoc above the sortByNameThenSequence function
describing the two-step sorting strategy (alphabetical by name, then insert
items with a valid seq at seq-1 positions, grouping duplicates) and any
edge-cases (non-positive or missing seq values), and update occurrences of
f['seq'] to use dot notation (f.seq) for consistency; ensure the JSDoc names the
function and parameters and briefly describes the return value so future
maintainers can understand the intent without reading the implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 04df7f71-8b13-4898-b685-02ed1b0c5438

📥 Commits

Reviewing files that changed from the base of the PR and between 9944819 and a07cb28.

📒 Files selected for processing (2)
  • packages/bruno-converters/src/postman/bruno-to-postman.js
  • packages/bruno-converters/tests/postman/bruno-to-postman.spec.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Postman export does not preserve folder/request ordering

2 participants