Skip to content

Commit

Permalink
fix(bitbucket): source link root path (#32689)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <[email protected]>
  • Loading branch information
setchy authored Nov 27, 2024
1 parent 231ee54 commit c4f4934
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
20 changes: 19 additions & 1 deletion lib/workers/repository/update/pr/body/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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', () => {
Expand Down
18 changes: 16 additions & 2 deletions lib/workers/repository/update/pr/body/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -31,12 +32,20 @@ function massageUpdateMetadata(config: BranchConfig): void {
depNameLinked = `[${depNameLinked}](${primaryLink})`;
}

let sourceRootPath = 'tree';
if (sourceUrl) {
const sourcePlatform = detectPlatform(sourceUrl);
if (sourcePlatform === 'bitbucket') {
sourceRootPath = 'src';
}
}

const otherLinks = [];
if (sourceUrl && (!!sourceDirectory || homepage)) {
otherLinks.push(
`[source](${
sourceDirectory
? joinUrlParts(sourceUrl, 'tree/HEAD/', sourceDirectory)
? joinUrlParts(sourceUrl, sourceRootPath, 'HEAD', sourceDirectory)
: sourceUrl
})`,
);
Expand All @@ -55,7 +64,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})`);
}
Expand Down

0 comments on commit c4f4934

Please sign in to comment.