(versionsObj)
| 81 | } |
| 82 | |
| 83 | function evaluateVersions(versionsObj) { |
| 84 | // get an array like: [ 'free-pro-team@latest', 'enterprise-server@2.21', 'enterprise-cloud@latest' ] |
| 85 | const versions = [] |
| 86 | |
| 87 | // where versions obj is something like: |
| 88 | // fpt: '*' |
| 89 | // ghes: '>=2.19' |
| 90 | // ghae: '*' |
| 91 | // ^ where each key corresponds to a plan's short name (defined in lib/all-versions.js) |
| 92 | Object.entries(versionsObj).forEach(([plan, planValue]) => { |
| 93 | // For each available plan (e.g., `ghes`), get the matching versions from allVersions. |
| 94 | // This will be an array of one or more version objects. |
| 95 | const matchingVersionObjs = Object.values(allVersions).filter( |
| 96 | (relevantVersionObj) => |
| 97 | relevantVersionObj.plan === plan || relevantVersionObj.shortName === plan |
| 98 | ) |
| 99 | |
| 100 | // For each matching version found above, compare it to the provided planValue. |
| 101 | // E.g., compare `enterprise-server@2.19` to `ghes: >=2.19`. |
| 102 | matchingVersionObjs.forEach((relevantVersionObj) => { |
| 103 | // If the version doesn't require any semantic comparison, we can assume it applies. |
| 104 | if (!(relevantVersionObj.hasNumberedReleases || relevantVersionObj.internalLatestRelease)) { |
| 105 | versions.push(relevantVersionObj.version) |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | // Special handling for a plan value that evaluates to the next GHES release number or a hardcoded `next`. |
| 110 | // Note these will not be included in the final array unless the `includeNextVersion` option is provided. |
| 111 | if (versionSatisfiesRange(next, planValue) || planValue === 'next') { |
| 112 | versions.push(`${relevantVersionObj.plan}@${next}`) |
| 113 | } |
| 114 | if (versionSatisfiesRange(nextNext, planValue)) { |
| 115 | versions.push(`${relevantVersionObj.plan}@${nextNext}`) |
| 116 | } |
| 117 | |
| 118 | // Determine which release to use for semantic comparison. |
| 119 | const releaseToCompare = relevantVersionObj.hasNumberedReleases |
| 120 | ? relevantVersionObj.currentRelease |
| 121 | : relevantVersionObj.internalLatestRelease |
| 122 | |
| 123 | if (versionSatisfiesRange(releaseToCompare, planValue)) { |
| 124 | versions.push(relevantVersionObj.version) |
| 125 | } |
| 126 | }) |
| 127 | }) |
| 128 | |
| 129 | return versions |
| 130 | } |
| 131 | |
| 132 | export default getApplicableVersions |
no test coverage detected