Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ember-source broken links #933

Merged
19 changes: 16 additions & 3 deletions app/helpers/github-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ 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);

const baseVersion = `v${version.replace(/^v/, '')}`;
MehulKChaudhari marked this conversation as resolved.
Show resolved Hide resolved

// 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
? `${baseVersion}-ember-source`
: baseVersion;

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

Expand All @@ -22,9 +33,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/${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
Loading