Added more feedback in case branch is already created

Signed-off-by: Jasper Boeijenga <jboeijenga@gmail.com>
This commit is contained in:
Jasper Boeijenga
2025-03-20 15:52:32 +01:00
parent 49cf8b5f91
commit 00498e48c9
@@ -414,20 +414,39 @@ which uses additional API calls in order to detect whether to 'create', 'update'
execute_filemode: file.executable,
}));
let createBranch: boolean;
if (actions.length) {
createBranch = true;
} else {
try {
await api.Branches.show(repoID, branchName);
createBranch = false;
ctx.logger.info(
`Using existing branch ${branchName} without modification.`,
);
} catch (e) {
createBranch = true;
let createBranch = actions.length > 0;
try {
const branch = await api.Branches.show(repoID, branchName);
if (createBranch) {
const mergeRequests = await api.MergeRequests.all({
projectId: repoID,
source_branch: branchName,
});
if (mergeRequests.length > 0) {
// If an open MR exists, include the MR link in the error message
throw new InputError(
`The branch creation failed because the branch already exists at: ${branch.web_url}. Additionally, there is a Merge Request for this branch: ${mergeRequests[0].web_url}`,
);
} else {
// If no open MR, just notify about the existing branch
throw new InputError(
`The branch creation failed because the branch already exists at: ${branch.web_url}.`,
);
}
}
ctx.logger.info(
`Using existing branch ${branchName} without modification.`,
);
} catch (e) {
if (e instanceof InputError) {
throw e;
}
createBranch = true;
}
if (createBranch) {
try {
await api.Branches.create(repoID, branchName, String(targetBranch));
@@ -439,6 +458,7 @@ which uses additional API calls in order to detect whether to 'create', 'update'
);
}
}
await ctx.checkpoint({
key: `commit.to.${repoID}.${branchName}`,
fn: async () => {