From 0ba9080f4078a55cc65960ae78d41be85e0af02c Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 23 Nov 2024 08:02:37 -0500 Subject: [PATCH 1/5] fix(bitbucket): source link root path Signed-off-by: Adam Setch --- lib/modules/platform/bitbucket/index.ts | 2 ++ .../repository/update/pr/body/index.spec.ts | 20 ++++++++++++++++++- .../repository/update/pr/body/index.ts | 20 +++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/modules/platform/bitbucket/index.ts b/lib/modules/platform/bitbucket/index.ts index 9678aa2443b45e..58706e510583d8 100644 --- a/lib/modules/platform/bitbucket/index.ts +++ b/lib/modules/platform/bitbucket/index.ts @@ -55,6 +55,8 @@ const bitbucketHttp = new BitbucketHttp(); const BITBUCKET_PROD_ENDPOINT = 'https://api.bitbucket.org/'; +export const BITBUCKET_WEB_ENDPOINT = 'https://bitbucket.org/'; + let config: Config = {} as any; const defaults = { endpoint: BITBUCKET_PROD_ENDPOINT }; diff --git a/lib/workers/repository/update/pr/body/index.spec.ts b/lib/workers/repository/update/pr/body/index.spec.ts index eb5149a2685a1f..0308e4d8c26562 100644 --- a/lib/workers/repository/update/pr/body/index.spec.ts +++ b/lib/workers/repository/update/pr/body/index.spec.ts @@ -89,12 +89,21 @@ describe('workers/repository/update/pr/body/index', () => { homepage: 'https://example.com', }; + const upgradeBitbucket = { + manager: 'some-manager', + branchName: 'some-branch', + sourceUrl: 'https://bitbucket.org/foo/bar', + sourceDirectory: '/baz', + changelogUrl: 'https://bitbucket.org/foo/bar/src/main/CHANGELOG.md', + homepage: 'https://example.com', + }; + getPrBody( { manager: 'some-manager', baseBranch: 'base', branchName: 'some-branch', - upgrades: [upgrade, upgrade1], + upgrades: [upgrade, upgrade1, upgradeBitbucket], }, { debugData: { @@ -128,6 +137,15 @@ describe('workers/repository/update/pr/body/index', () => { homepage: 'https://example.com', sourceUrl: 'https://github.com/foo/bar', }); + expect(upgradeBitbucket).toMatchObject({ + branchName: 'some-branch', + depNameLinked: + '[undefined](https://example.com) ([source](https://bitbucket.org/foo/bar/src/HEAD/baz), [changelog](https://bitbucket.org/foo/bar/src/main/CHANGELOG.md))', + references: + '[homepage](https://example.com), [source](https://bitbucket.org/foo/bar/src/HEAD/baz), [changelog](https://bitbucket.org/foo/bar/src/main/CHANGELOG.md)', + homepage: 'https://example.com', + sourceUrl: 'https://bitbucket.org/foo/bar', + }); }); it('uses dependencyUrl as primary link', () => { diff --git a/lib/workers/repository/update/pr/body/index.ts b/lib/workers/repository/update/pr/body/index.ts index 1c1e5d8d1f9e88..a83d280e0c69e0 100644 --- a/lib/workers/repository/update/pr/body/index.ts +++ b/lib/workers/repository/update/pr/body/index.ts @@ -1,6 +1,7 @@ import type { RenovateConfig } from '../../../../../config/types'; import type { PrDebugData } from '../../../../../modules/platform'; import { platform } from '../../../../../modules/platform'; +import { BITBUCKET_WEB_ENDPOINT } from '../../../../../modules/platform/bitbucket'; import { regEx } from '../../../../../util/regex'; import { toBase64 } from '../../../../../util/string'; import * as template from '../../../../../util/template'; @@ -31,12 +32,14 @@ function massageUpdateMetadata(config: BranchConfig): void { depNameLinked = `[${depNameLinked}](${primaryLink})`; } + const sourceRootPath = getSourceRootPath(sourceUrl); + const otherLinks = []; if (sourceUrl && (!!sourceDirectory || homepage)) { otherLinks.push( `[source](${ sourceDirectory - ? joinUrlParts(sourceUrl, 'tree/HEAD/', sourceDirectory) + ? joinUrlParts(sourceUrl, sourceRootPath, 'HEAD', sourceDirectory) : sourceUrl })`, ); @@ -55,7 +58,12 @@ function massageUpdateMetadata(config: BranchConfig): void { if (sourceUrl) { let fullUrl = sourceUrl; if (sourceDirectory) { - fullUrl = joinUrlParts(sourceUrl, 'tree/HEAD/', sourceDirectory); + fullUrl = joinUrlParts( + sourceUrl, + sourceRootPath, + 'HEAD', + sourceDirectory, + ); } references.push(`[source](${fullUrl})`); } @@ -66,6 +74,14 @@ function massageUpdateMetadata(config: BranchConfig): void { }); } +function getSourceRootPath(sourceUrl: string | undefined): string { + if (sourceUrl?.startsWith(BITBUCKET_WEB_ENDPOINT)) { + return 'src'; + } + + return 'tree'; +} + interface PrBodyConfig { appendExtra?: string | null | undefined; rebasingNotice?: string; From 3b274072d42cf8201fff80610ab2ad08ca780f58 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 23 Nov 2024 10:44:06 -0500 Subject: [PATCH 2/5] inline for now until we have a better option Signed-off-by: Adam Setch --- lib/modules/platform/bitbucket/index.ts | 2 -- lib/workers/repository/update/pr/body/index.ts | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/modules/platform/bitbucket/index.ts b/lib/modules/platform/bitbucket/index.ts index 58706e510583d8..9678aa2443b45e 100644 --- a/lib/modules/platform/bitbucket/index.ts +++ b/lib/modules/platform/bitbucket/index.ts @@ -55,8 +55,6 @@ const bitbucketHttp = new BitbucketHttp(); const BITBUCKET_PROD_ENDPOINT = 'https://api.bitbucket.org/'; -export const BITBUCKET_WEB_ENDPOINT = 'https://bitbucket.org/'; - let config: Config = {} as any; const defaults = { endpoint: BITBUCKET_PROD_ENDPOINT }; diff --git a/lib/workers/repository/update/pr/body/index.ts b/lib/workers/repository/update/pr/body/index.ts index a83d280e0c69e0..3dbc1e39a664c6 100644 --- a/lib/workers/repository/update/pr/body/index.ts +++ b/lib/workers/repository/update/pr/body/index.ts @@ -1,7 +1,6 @@ import type { RenovateConfig } from '../../../../../config/types'; import type { PrDebugData } from '../../../../../modules/platform'; import { platform } from '../../../../../modules/platform'; -import { BITBUCKET_WEB_ENDPOINT } from '../../../../../modules/platform/bitbucket'; import { regEx } from '../../../../../util/regex'; import { toBase64 } from '../../../../../util/string'; import * as template from '../../../../../util/template'; @@ -75,7 +74,7 @@ function massageUpdateMetadata(config: BranchConfig): void { } function getSourceRootPath(sourceUrl: string | undefined): string { - if (sourceUrl?.startsWith(BITBUCKET_WEB_ENDPOINT)) { + if (sourceUrl?.startsWith('https://bitbucket.org/')) { return 'src'; } From ef3c524bbbc55b98e08bbfd6b40027d7f38b6cb8 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 25 Nov 2024 14:10:16 -0500 Subject: [PATCH 3/5] refactor: use detectPlatform util Signed-off-by: Adam Setch --- lib/workers/repository/update/pr/body/index.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/workers/repository/update/pr/body/index.ts b/lib/workers/repository/update/pr/body/index.ts index 3dbc1e39a664c6..d65e993bbbd221 100644 --- a/lib/workers/repository/update/pr/body/index.ts +++ b/lib/workers/repository/update/pr/body/index.ts @@ -1,6 +1,7 @@ import type { RenovateConfig } from '../../../../../config/types'; import type { PrDebugData } from '../../../../../modules/platform'; import { platform } from '../../../../../modules/platform'; +import { detectPlatform } from '../../../../../util/common'; import { regEx } from '../../../../../util/regex'; import { toBase64 } from '../../../../../util/string'; import * as template from '../../../../../util/template'; @@ -31,7 +32,11 @@ function massageUpdateMetadata(config: BranchConfig): void { depNameLinked = `[${depNameLinked}](${primaryLink})`; } - const sourceRootPath = getSourceRootPath(sourceUrl); + const sourcePlatform = detectPlatform(sourceUrl); + let sourceRootPath = 'tree'; + if (sourcePlatform === 'bitbucket') { + sourceRootPath = 'src'; + } const otherLinks = []; if (sourceUrl && (!!sourceDirectory || homepage)) { @@ -73,14 +78,6 @@ function massageUpdateMetadata(config: BranchConfig): void { }); } -function getSourceRootPath(sourceUrl: string | undefined): string { - if (sourceUrl?.startsWith('https://bitbucket.org/')) { - return 'src'; - } - - return 'tree'; -} - interface PrBodyConfig { appendExtra?: string | null | undefined; rebasingNotice?: string; From 2953458d79ca2eff8907efac26177b919f5abb01 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 25 Nov 2024 14:13:43 -0500 Subject: [PATCH 4/5] refactor: use detectPlatform util Signed-off-by: Adam Setch --- lib/workers/repository/update/pr/body/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/workers/repository/update/pr/body/index.ts b/lib/workers/repository/update/pr/body/index.ts index d65e993bbbd221..258661120c6223 100644 --- a/lib/workers/repository/update/pr/body/index.ts +++ b/lib/workers/repository/update/pr/body/index.ts @@ -32,10 +32,13 @@ function massageUpdateMetadata(config: BranchConfig): void { depNameLinked = `[${depNameLinked}](${primaryLink})`; } - const sourcePlatform = detectPlatform(sourceUrl); let sourceRootPath = 'tree'; - if (sourcePlatform === 'bitbucket') { - sourceRootPath = 'src'; + + if (sourceUrl) { + const sourcePlatform = detectPlatform(sourceUrl); + if (sourcePlatform === 'bitbucket') { + sourceRootPath = 'src'; + } } const otherLinks = []; From 10556bc7ce8c16b41c387f8460cc29d867a51ab6 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Mon, 25 Nov 2024 14:14:26 -0500 Subject: [PATCH 5/5] refactor: use detectPlatform util Signed-off-by: Adam Setch --- lib/workers/repository/update/pr/body/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/workers/repository/update/pr/body/index.ts b/lib/workers/repository/update/pr/body/index.ts index 258661120c6223..984a3ff83b9b48 100644 --- a/lib/workers/repository/update/pr/body/index.ts +++ b/lib/workers/repository/update/pr/body/index.ts @@ -33,7 +33,6 @@ function massageUpdateMetadata(config: BranchConfig): void { } let sourceRootPath = 'tree'; - if (sourceUrl) { const sourcePlatform = detectPlatform(sourceUrl); if (sourcePlatform === 'bitbucket') {