([project, version, file, line], { isEdit = false })
| 2 | import githubMap, { mainDir } from '../utils/github-map'; |
| 3 | |
| 4 | export function githubLink([project, version, file, line], { isEdit = false }) { |
| 5 | const isEmberProject = project === 'ember'; |
| 6 | const majorVersion = parseInt(version?.split('.')[0].replace('v', ''), 10); |
| 7 | |
| 8 | // Check if the project is 'ember' and adjust the tag only if the major version is >= 6 to match the Git tags |
| 9 | const adjustedVersion = |
| 10 | isEmberProject && majorVersion >= 6 ? `${version}-ember-source` : version; |
| 11 | |
| 12 | if (isEdit) { |
| 13 | return `https://github.com/${githubMap[project]}/edit/release${mainDir( |
| 14 | project, |
| 15 | adjustedVersion, |
| 16 | )}${file}#L${line}`; |
| 17 | } |
| 18 | |
| 19 | // This 'packages' replacement can be removed if the following PR goes into a patch release of |
| 20 | // Ember Data 4.12: https://github.com/emberjs/data/pull/8598/files |
| 21 | // |
| 22 | // If the file has packages already in the path, make sure we don't |
| 23 | // add duplicate packages via the mainDir function. |
| 24 | // Fixes an issue with ember data URLS having an incorrect |
| 25 | // 'packages/packages' in the GitHub source URL |
| 26 | // For example, without this fixedFile line, a `file` with value |
| 27 | // '../packages/store/addon/-private/record-arrays/identifier-array.ts' |
| 28 | // would become |
| 29 | // 'https://github.com/emberjs/data/tree/v4.10.0/packages/packages/store/addon/-private/record-arrays/identifier-array.ts#L118' |
| 30 | const fixedFile = file?.replace('../packages/', '../'); |
| 31 | |
| 32 | return `https://github.com/${ |
| 33 | githubMap[project] |
| 34 | }/tree/v${adjustedVersion}${mainDir( |
| 35 | project, |
| 36 | adjustedVersion, |
| 37 | )}${fixedFile}#L${line}`; |
| 38 | } |
| 39 | |
| 40 | export default helper(githubLink); |
no test coverage detected