-
-
Notifications
You must be signed in to change notification settings - Fork 702
Fix for deployment version comparison #1754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
WalkthroughThis pull request updates the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant DeploymentUtils
Client->>DeploymentUtils: Call compareDeploymentVersions(versionA, versionB)
DeploymentUtils->>DeploymentUtils: Convert string components to numbers using Number()
DeploymentUtils->>DeploymentUtils: Compare numerical values (numA vs numB)
DeploymentUtils-->>Client: Return result of comparison
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/webapp/app/v3/utils/deploymentVersions.ts (1)
3-28
: Consider adding error handling for invalid version formats.The function assumes that the input version strings will always be valid (contain a period and have numeric parts). While this fix addresses the core issue, it might be worth considering adding some basic validation or error handling for malformed inputs.
export function compareDeploymentVersions(versionA: string, versionB: string) { + // Validate input format + if (!versionA.includes(".") || !versionB.includes(".")) { + throw new Error("Invalid version format: versions must contain a period"); + } + const [dateA, numberA] = versionA.split("."); const [dateB, numberB] = versionB.split("."); + // Ensure all parts are valid + if (!dateA || !numberA || !dateB || !numberB || isNaN(Number(numberA)) || isNaN(Number(numberB))) { + throw new Error("Invalid version format: all parts must be valid numbers"); + } if (dateA < dateB) { return -1; } if (dateA > dateB) { return 1; } // Convert to numbers before comparing const numA = Number(numberA); const numB = Number(numberB); if (numA < numB) { return -1; } if (numA > numB) { return 1; } return 0; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/webapp/app/v3/utils/deploymentVersions.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: typecheck / typecheck
- GitHub Check: units / 🧪 Unit Tests
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
- GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
- GitHub Check: units / 🧪 Unit Tests
- GitHub Check: typecheck / typecheck
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/webapp/app/v3/utils/deploymentVersions.ts (2)
15-18
: Good fix addressing the version comparison issue.This explicit conversion of string values to numbers properly addresses the issue described in the PR objectives. When comparing version numbers lexicographically (as strings), "10" would be considered less than "2" because the first character "1" comes before "2". By converting to numbers first, you ensure that 10 is correctly compared as greater than 2.
This is particularly important when you have 10 or more deployments in a single day, as mentioned in the PR description.
19-19
: Correct implementation of numeric comparison.Updating the comparison to use the converted numeric values rather than the original string values ensures proper numeric ordering. This completes the fix for the deployment version comparison issue.
Also applies to: 23-23
If you're on >= 10 deploys in a day the comparison doesn't work because we were comparing them as strings… 🤦
This meant new deploys weren't being promoted, and it was impossible to promote a new one.
Summary by CodeRabbit