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(bitbucket): source link root path #32689

Merged
merged 7 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 17 additions & 2 deletions lib/workers/repository/update/pr/body/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,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
})`,
);
Expand All @@ -55,7 +57,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 All @@ -66,6 +73,14 @@ function massageUpdateMetadata(config: BranchConfig): void {
});
}

function getSourceRootPath(sourceUrl: string | undefined): string {
if (sourceUrl?.startsWith('https://bitbucket.org/')) {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
return 'src';
}

return 'tree';
}

interface PrBodyConfig {
appendExtra?: string | null | undefined;
rebasingNotice?: string;
Expand Down