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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions lib/modules/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
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
20 changes: 18 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 { BITBUCKET_WEB_ENDPOINT } from '../../../../../modules/platform/bitbucket';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export a new optional platform API instead, we don't want to have deep import from platforms here.

Copy link
Collaborator Author

@setchy setchy Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think that will work since its not the renovate platform, but the specific update platform/host that I need to check

eg: renovate running on a GitHub repository with an update for a Bitbucket-hosted package

is there another way to achieve this? essentially I want to check the updates host type (bitbucket, github, etc)

import { regEx } from '../../../../../util/regex';
import { toBase64 } from '../../../../../util/string';
import * as template from '../../../../../util/template';
Expand Down Expand Up @@ -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
})`,
);
Expand All @@ -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})`);
}
Expand All @@ -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;
Expand Down