fix: preserve folder/request ordering in Postman export#7581
Conversation
- 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.
WalkthroughThis change adds deterministic ordering to Postman collection exports. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 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
seqat 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.seqoverf['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
📒 Files selected for processing (2)
packages/bruno-converters/src/postman/bruno-to-postman.jspackages/bruno-converters/tests/postman/bruno-to-postman.spec.js
Description
JIRA
sortByNameThenSequence(alphabetical with seq-based positioning), requests byseqascending, with folders appearing before requests — matching the sidebar and CLI runner behaviorChanges
packages/bruno-converters/src/postman/bruno-to-postman.js— Added sort helpers and modifiedgenerateItemSectionto sort items before mapping to Postman formatpackages/bruno-converters/tests/postman/bruno-to-postman.spec.js— Added 5 integration tests for ordering behaviorContribution Checklist:
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