(content, release, nextOldestRelease, file)
| 18 | // and update Liquid conditionals when a GHES release is being deprecated. It is also used by |
| 19 | // tests/content/remove-liquid-statements.js. |
| 20 | export default function removeLiquidStatements(content, release, nextOldestRelease, file) { |
| 21 | let newContent = content |
| 22 | |
| 23 | // Get an array of ifversion blocks with their content included. |
| 24 | const blocks = getLiquidConditionalsWithContent(newContent, 'ifversion') |
| 25 | if (!blocks.length) return newContent |
| 26 | |
| 27 | // Decorate those blocks with more GHES versioning information. |
| 28 | const versionBlocks = getVersionBlocks(blocks) |
| 29 | |
| 30 | // Determine whether we should remove the GHES range only or the GHES range and the content. |
| 31 | for (const versionBlock of versionBlocks) { |
| 32 | const actionMap = {} |
| 33 | |
| 34 | versionBlock.isGhesOnly = versionBlock.condArgs.every((arg) => arg.includes('ghes')) |
| 35 | versionBlock.hasSingleRange = versionBlock.ranges.length === 1 |
| 36 | versionBlock.andGhesRanges = versionBlock.condArgs.filter((arg) => arg.includes('and ghes')) |
| 37 | const isSafeToRemoveContent = |
| 38 | versionBlock.isGhesOnly && (versionBlock.hasSingleRange || versionBlock.andGhesRanges.length) |
| 39 | |
| 40 | if (canConditionalBeRemoved(supportedShortVersions, versionBlock.condOnly)) { |
| 41 | actionMap[removeConditionals] = true |
| 42 | } |
| 43 | |
| 44 | for (const rangeArgs of versionBlock.ranges) { |
| 45 | const rangeOperator = rangeArgs[1] |
| 46 | const releaseNumber = rangeArgs[2] |
| 47 | // We are only concerned with the release we are deprecating and the next oldest release.. |
| 48 | if (!(releaseNumber === release || releaseNumber === nextOldestRelease)) continue |
| 49 | // But are not concerned with conditionals _equal_ to the next oldest release, as those are still valid. |
| 50 | if (rangeOperator === '=' && releaseNumber === nextOldestRelease) continue |
| 51 | |
| 52 | // Remove Liquid in these scenarios. |
| 53 | const greaterThanVersionToDeprecate = rangeOperator === '>' && releaseNumber === release |
| 54 | const notEqualsVersionToDeprecate = rangeOperator === '!=' && releaseNumber === release |
| 55 | |
| 56 | // Remove Liquid and content in these scenarios, IF AND ONLY IF it's safe to remove content. |
| 57 | // For example, when there is no other versioning in the conditional. |
| 58 | const lessThanNextOldestVersion = |
| 59 | rangeOperator === '<' && (releaseNumber === nextOldestRelease || releaseNumber === release) |
| 60 | const equalsVersionToDeprecate = rangeOperator === '=' && releaseNumber === release |
| 61 | |
| 62 | let action |
| 63 | |
| 64 | // Determine which action to take: removeRangeAndContent, updateRangeRemoveGhes, updateRangeKeepGhes. |
| 65 | if (greaterThanVersionToDeprecate || notEqualsVersionToDeprecate) { |
| 66 | // If the original is `ghes > 2.21` or `fpt or ghes > 2.21`, we want to replace it with `ghes`; |
| 67 | // If the original is `ghes > 2.21 and ghes < 3.0`, we want to remove the range and leave just `ghes < 3.0`. |
| 68 | action = versionBlock.hasSingleRange ? updateRangeKeepGhes : updateRangeRemoveGhes |
| 69 | } |
| 70 | |
| 71 | if (lessThanNextOldestVersion || equalsVersionToDeprecate) { |
| 72 | // If it's not safe to remove content, we want to at least remove `ghes` from the range. |
| 73 | action = isSafeToRemoveContent ? removeRangeAndContent : updateRangeRemoveGhes |
| 74 | } |
| 75 | |
| 76 | if (action) { |
| 77 | actionMap[action] = versionBlock.condArgs.find((arg) => arg.endsWith(rangeArgs.join(' '))) |
no test coverage detected