Skip to content

Commit

Permalink
Merge pull request #933 from MehulKChaudhari/fix/ember-source-broken-…
Browse files Browse the repository at this point in the history
…links
  • Loading branch information
kategengler authored Jan 20, 2025
2 parents f50f4fe + b0bea28 commit c5d03c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/helpers/github-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@ import { helper } from '@ember/component/helper';
import githubMap, { mainDir } from '../utils/github-map';

export function githubLink([project, version, file, line], { isEdit = false }) {
const isEmberProject = project === 'ember';
const majorVersion = parseInt(version?.split('.')[0].replace('v', ''), 10);

// Check if the project is 'ember' and adjust the tag only if the major version is >= 6 to match the Git tags
const adjustedVersion =
isEmberProject && majorVersion >= 6 ? `${version}-ember-source` : version;

if (isEdit) {
return `https://github.com/${githubMap[project]}/edit/release${mainDir(
project,
version
adjustedVersion
)}${file}#L${line}`;
}

Expand All @@ -22,9 +29,11 @@ export function githubLink([project, version, file, line], { isEdit = false }) {
// 'https://github.com/emberjs/data/tree/v4.10.0/packages/packages/store/addon/-private/record-arrays/identifier-array.ts#L118'
const fixedFile = file?.replace('../packages/', '../');

return `https://github.com/${githubMap[project]}/tree/v${version}${mainDir(
return `https://github.com/${
githubMap[project]
}/tree/v${adjustedVersion}${mainDir(
project,
version
adjustedVersion
)}${fixedFile}#L${line}`;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/helpers/github-link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ module('Unit | Helper | github link', function () {
);
});

test('should append "ember-source" to the version for git tags v6 and above', function (assert) {
let result = githubLink(
['ember', '6.0.0', 'ember-glimmer/lib/component.js', '35'],
{}
);
assert.equal(
result,
'https://github.com/emberjs/ember.js/tree/v6.0.0-ember-source/ember-glimmer/lib/component.js#L35'
);
});

test('should render a github link for ember-data from file info', function (assert) {
let result = githubLink(
['ember-data', '2.10.0', 'addon/-private/adapters/errors.js', '10'],
Expand Down

0 comments on commit c5d03c5

Please sign in to comment.