Update missing target branch error message

Signed-off-by: mbruhin <47482924+mbruhin@users.noreply.github.com>
This commit is contained in:
mbruhin
2025-12-02 11:35:26 -07:00
parent 57d8670c07
commit 5a6aca26b1
3 changed files with 40 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend-module-bitbucket-server': patch
---
Improve error message when provided target branch is missing
@@ -399,4 +399,33 @@ describe('publish:bitbucketServer:pull-request', () => {
'https://hosted.bitbucket.com/projects/project/repos/repo/pull-requests/1',
);
});
it('should throw an error when the target branch is not found', async () => {
server.use(
rest.get(
'https://hosted.bitbucket.com/rest/api/1.0/projects/project/repos/repo/branches',
(_, res, ctx) => {
return res(
ctx.status(200),
ctx.set('Content-Type', 'application/json'),
ctx.json(responseOfBranches),
);
},
),
);
await expect(
action.handler({
...mockContext,
input: {
...mockContext.input,
repoUrl: 'hosted.bitbucket.com?project=project&repo=repo',
targetBranch: 'non-existent-branch',
sourceBranch: 'develop',
},
}),
).rejects.toThrow(
/Target branch 'non-existent-branch' not found in repository project\/repo/,
);
});
});
@@ -380,6 +380,12 @@ export function createPublishBitbucketServerPullRequestAction(options: {
apiBaseUrl,
});
if (!toRef) {
throw new InputError(
`Target branch '${finalTargetBranch}' not found in repository ${project}/${repo}. Please ensure the branch exists before creating a pull request.`,
);
}
let fromRef = await findBranches({
project,
repo,