From 07c51ba462a1211e2696ef5956a08b6d3b968513 Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Mon, 1 May 2023 12:13:53 -0400 Subject: [PATCH 1/5] Bugfix - fix broken ember-data GitHub URLS If the file has packages already in the path, make sure we don't add duplicate packages via the mainDir function. Fixes an issue with ember data URLS having an incorrect 'packages/packages' in the GitHub source URL Example problem was https://api.emberjs.com/ember-data/4.10/classes/RecordArray --- app/helpers/github-link.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/helpers/github-link.js b/app/helpers/github-link.js index 807f54b3..f3300895 100644 --- a/app/helpers/github-link.js +++ b/app/helpers/github-link.js @@ -1,6 +1,12 @@ import { helper } from '@ember/component/helper'; import githubMap, { mainDir } from '../utils/github-map'; +/** + * https://github.com/emberjs/data/tree/v4.10.0/packages/packages/ + * store/addon/-private/record-arrays/identifier-array.ts#L118 + * + * File: ../packages/store/addon/-private/record-arrays/identifier-array.ts + */ export function githubLink([project, version, file, line], { isEdit = false }) { if (isEdit) { return `https://github.com/${githubMap[project]}/edit/release${mainDir( @@ -8,10 +14,17 @@ export function githubLink([project, version, file, line], { isEdit = false }) { version )}${file}#L${line}`; } - return `https://github.com/${githubMap[project]}/tree/v${version}${mainDir( - project, - version - )}${file}#L${line}`; + + // If the file has packages already in the path, make sure we don't + // add duplicate packages via the mainDir function. + // Fixes an issue with ember data URLS having an incorrect + // 'packages/packages' in the GitHub source URL + const fixedFile = file.replace('../packages/', '../'); + + const result = `https://github.com/${ + githubMap[project] + }/tree/v${version}${mainDir(project, version)}${fixedFile}#L${line}`; + return result; } export default helper(githubLink); From 3d36c753859a8d9f27987fcd5518eae54d5f3709 Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Mon, 1 May 2023 15:30:37 -0400 Subject: [PATCH 2/5] Update comments and use optional chaining --- app/helpers/github-link.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/helpers/github-link.js b/app/helpers/github-link.js index f3300895..48fa7271 100644 --- a/app/helpers/github-link.js +++ b/app/helpers/github-link.js @@ -1,12 +1,6 @@ import { helper } from '@ember/component/helper'; import githubMap, { mainDir } from '../utils/github-map'; -/** - * https://github.com/emberjs/data/tree/v4.10.0/packages/packages/ - * store/addon/-private/record-arrays/identifier-array.ts#L118 - * - * File: ../packages/store/addon/-private/record-arrays/identifier-array.ts - */ export function githubLink([project, version, file, line], { isEdit = false }) { if (isEdit) { return `https://github.com/${githubMap[project]}/edit/release${mainDir( @@ -19,7 +13,11 @@ export function githubLink([project, version, file, line], { isEdit = false }) { // add duplicate packages via the mainDir function. // Fixes an issue with ember data URLS having an incorrect // 'packages/packages' in the GitHub source URL - const fixedFile = file.replace('../packages/', '../'); + // For example, without this fixedFile line, a `file` with value + // '../packages/store/addon/-private/record-arrays/identifier-array.ts' + // would become + // '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/', '../'); const result = `https://github.com/${ githubMap[project] From 71adbf09e04592c28e5f05a260c474597757754c Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Mon, 1 May 2023 20:19:24 -0400 Subject: [PATCH 3/5] Make linter happy --- app/helpers/github-link.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/helpers/github-link.js b/app/helpers/github-link.js index 48fa7271..8e6ec5c3 100644 --- a/app/helpers/github-link.js +++ b/app/helpers/github-link.js @@ -15,14 +15,13 @@ export function githubLink([project, version, file, line], { isEdit = false }) { // 'packages/packages' in the GitHub source URL // For example, without this fixedFile line, a `file` with value // '../packages/store/addon/-private/record-arrays/identifier-array.ts' - // would become + // would become // '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/', '../'); - const result = `https://github.com/${ + return `https://github.com/${ githubMap[project] }/tree/v${version}${mainDir(project, version)}${fixedFile}#L${line}`; - return result; } export default helper(githubLink); From 8884310a7a36c87d2253775b5cf5e872db22a0c8 Mon Sep 17 00:00:00 2001 From: Jared Galanis Date: Mon, 1 May 2023 20:27:28 -0400 Subject: [PATCH 4/5] appease prettier --- app/helpers/github-link.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/helpers/github-link.js b/app/helpers/github-link.js index 8e6ec5c3..b9fe9b5f 100644 --- a/app/helpers/github-link.js +++ b/app/helpers/github-link.js @@ -19,9 +19,10 @@ 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(project, version)}${fixedFile}#L${line}`; + return `https://github.com/${githubMap[project]}/tree/v${version}${mainDir( + project, + version + )}${fixedFile}#L${line}`; } export default helper(githubLink); From 4185932c458d8376059c9a4771d9b4ae93fc69a5 Mon Sep 17 00:00:00 2001 From: Jen Weber Date: Mon, 8 May 2023 11:28:04 -0400 Subject: [PATCH 5/5] More code comments --- app/helpers/github-link.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/helpers/github-link.js b/app/helpers/github-link.js index b9fe9b5f..c23247d6 100644 --- a/app/helpers/github-link.js +++ b/app/helpers/github-link.js @@ -9,6 +9,9 @@ export function githubLink([project, version, file, line], { isEdit = false }) { )}${file}#L${line}`; } + // This 'packages' replacement can be removed if the following PR goes into a patch release of + // Ember Data 4.12: https://github.com/emberjs/data/pull/8598/files + // // If the file has packages already in the path, make sure we don't // add duplicate packages via the mainDir function. // Fixes an issue with ember data URLS having an incorrect