Skip to content

Commit

Permalink
Convert .rc* versions to proper semver, then compare (github#17600)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco authored Feb 1, 2021
1 parent c6312e1 commit 5cabf53
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions middleware/contextualizers/enterprise-release-notes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const semver = require('semver')
const renderContent = require('../../lib/render-content')
const patterns = require('../../lib/patterns')
const enterpriseReleases = require('../../lib/enterprise-server-releases').supported
Expand All @@ -19,8 +20,20 @@ function sortPatchKeys (release, version) {
})
return keys
.sort((a, b) => {
if (a.version > b.version) return -1
if (a.version < b.version) return 1
let aTemp = a.version
let bTemp = b.version

// There's an RC version here, so doing regular semver
// comparisons won't work. So, we'll convert the incompatible version
// strings to real semver strings, then compare.
const [aBase, aRc] = a.version.split('.rc')
if (aRc) aTemp = `${aBase}-rc.${aRc}`

const [bBase, bRc] = b.version.split('.rc')
if (bRc) bTemp = `${bBase}-rc.${bRc}`

if (semver.gt(aTemp, bTemp)) return -1
if (semver.lt(aTemp, bTemp)) return 1
return 0
})
}
Expand Down

0 comments on commit 5cabf53

Please sign in to comment.