fix(bitbucket): source link root path (#32689)

Signed-off-by: Adam Setch <adam.setch@outlook.com>
This commit is contained in:
Adam Setch 2024-11-27 03:54:58 -05:00 committed by GitHub
parent 231ee54f0e
commit c4f4934701
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 3 deletions

View file

@ -89,12 +89,21 @@ describe('workers/repository/update/pr/body/index', () => {
homepage: 'https://example.com', 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( getPrBody(
{ {
manager: 'some-manager', manager: 'some-manager',
baseBranch: 'base', baseBranch: 'base',
branchName: 'some-branch', branchName: 'some-branch',
upgrades: [upgrade, upgrade1], upgrades: [upgrade, upgrade1, upgradeBitbucket],
}, },
{ {
debugData: { debugData: {
@ -128,6 +137,15 @@ describe('workers/repository/update/pr/body/index', () => {
homepage: 'https://example.com', homepage: 'https://example.com',
sourceUrl: 'https://github.com/foo/bar', 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', () => { it('uses dependencyUrl as primary link', () => {

View file

@ -1,6 +1,7 @@
import type { RenovateConfig } from '../../../../../config/types'; import type { RenovateConfig } from '../../../../../config/types';
import type { PrDebugData } from '../../../../../modules/platform'; import type { PrDebugData } from '../../../../../modules/platform';
import { platform } from '../../../../../modules/platform'; import { platform } from '../../../../../modules/platform';
import { detectPlatform } from '../../../../../util/common';
import { regEx } from '../../../../../util/regex'; import { regEx } from '../../../../../util/regex';
import { toBase64 } from '../../../../../util/string'; import { toBase64 } from '../../../../../util/string';
import * as template from '../../../../../util/template'; import * as template from '../../../../../util/template';
@ -31,12 +32,20 @@ function massageUpdateMetadata(config: BranchConfig): void {
depNameLinked = `[${depNameLinked}](${primaryLink})`; depNameLinked = `[${depNameLinked}](${primaryLink})`;
} }
let sourceRootPath = 'tree';
if (sourceUrl) {
const sourcePlatform = detectPlatform(sourceUrl);
if (sourcePlatform === 'bitbucket') {
sourceRootPath = 'src';
}
}
const otherLinks = []; const otherLinks = [];
if (sourceUrl && (!!sourceDirectory || homepage)) { if (sourceUrl && (!!sourceDirectory || homepage)) {
otherLinks.push( otherLinks.push(
`[source](${ `[source](${
sourceDirectory sourceDirectory
? joinUrlParts(sourceUrl, 'tree/HEAD/', sourceDirectory) ? joinUrlParts(sourceUrl, sourceRootPath, 'HEAD', sourceDirectory)
: sourceUrl : sourceUrl
})`, })`,
); );
@ -55,7 +64,12 @@ function massageUpdateMetadata(config: BranchConfig): void {
if (sourceUrl) { if (sourceUrl) {
let fullUrl = sourceUrl; let fullUrl = sourceUrl;
if (sourceDirectory) { if (sourceDirectory) {
fullUrl = joinUrlParts(sourceUrl, 'tree/HEAD/', sourceDirectory); fullUrl = joinUrlParts(
sourceUrl,
sourceRootPath,
'HEAD',
sourceDirectory,
);
} }
references.push(`[source](${fullUrl})`); references.push(`[source](${fullUrl})`);
} }