Skip to content

Commit

Permalink
fix(bitbucket): source link root path
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <adam.setch@outlook.com>
  • Loading branch information
setchy committed Nov 22, 2024
1 parent e9588f1 commit c686728
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
19 changes: 18 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,20 @@ 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',
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 +136,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), [changelog](https://bitbucket.org/foo/bar/src/main/CHANGELOG.md))',
references:
'[homepage](https://example.com), [source](https://bitbucket.org/foo/bar), [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);

Check failure on line 34 in lib/workers/repository/update/pr/body/index.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

Check failure on line 34 in lib/workers/repository/update/pr/body/index.ts

View workflow job for this annotation

GitHub Actions / lint-other

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.

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) {

Check failure on line 76 in lib/workers/repository/update/pr/body/index.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Missing return type on function.
if (sourceUrl.startsWith('https://bitbucket.org/')) {

Check failure on line 77 in lib/workers/repository/update/pr/body/index.ts

View workflow job for this annotation

GitHub Actions / test (11/16)

workers/repository/update/pr/body/index › getPrBody › uses dependencyUrl as primary link

TypeError: Cannot read properties of undefined (reading 'startsWith') at startsWith (lib/workers/repository/update/pr/body/index.ts:77:17) at getSourceRootPath (lib/workers/repository/update/pr/body/index.ts:34:28) at Array.forEach (<anonymous>) at forEach (lib/workers/repository/update/pr/body/index.ts:19:19) at massageUpdateMetadata (lib/workers/repository/update/pr/body/index.ts:97:3) at Object.<anonymous> (lib/workers/repository/update/pr/body/index.spec.ts:157:16)
return 'src';
}

return 'tree';
}

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

0 comments on commit c686728

Please sign in to comment.