Skip to content

Commit

Permalink
feat: output a warning if the parent branch is protected (#280)
Browse files Browse the repository at this point in the history
antelman107 committed Sep 24, 2024
1 parent 209e5e1 commit 9fc1701
Showing 2 changed files with 27 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/commands/branches.ts
Original file line number Diff line number Diff line change
@@ -284,17 +284,17 @@ const create = async (
'--'?: string[];
},
) => {
const parentProps = await (() => {
const branches = await props.apiClient
.listProjectBranches(props.projectId)
.then(({ data }) => data.branches);

const parentProps = (() => {
if (!props.parent) {
return props.apiClient
.listProjectBranches(props.projectId)
.then(({ data }) => {
const branch = data.branches.find((b) => b.default);
if (!branch) {
throw new Error('No default branch found');
}
return { parent_id: branch.id };
});
const branch = branches.find((b) => b.default);
if (!branch) {
throw new Error('No default branch found');
}
return { parent_id: branch.id };
}

if (looksLikeLSN(props.parent)) {
@@ -308,15 +308,12 @@ const create = async (
if (looksLikeBranchId(props.parent)) {
return { parent_id: props.parent };
}
return props.apiClient
.listProjectBranches(props.projectId)
.then(({ data }) => {
const branch = data.branches.find((b) => b.name === props.parent);
if (!branch) {
throw new Error(`Branch ${props.parent} not found`);
}
return { parent_id: branch.id };
});

const branch = branches.find((b) => b.name === props.parent);
if (!branch) {
throw new Error(`Branch ${props.parent} not found`);
}
return { parent_id: branch.id };
})();

const { data } = await retryOnLock(() =>
@@ -341,7 +338,15 @@ const create = async (
}),
);

const parent = branches.find((b) => b.id === data.branch.parent_id);
if (parent?.protected) {
log.warning(
'The parent branch is protected; a unique role password has been generated for the new branch.',
);
}

const out = writer(props);

out.write(data.branch, {
fields: BRANCH_FIELDS,
title: 'branch',
3 changes: 3 additions & 0 deletions src/log.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,9 @@ export const log = {
process.stderr.write(`DEBUG: ${format(...args)}\n`);
}
},
warning: (...args: unknown[]) => {
process.stderr.write(`WARNING: ${format(...args)}\n`);
},
info: (...args: unknown[]) => {
process.stderr.write(`INFO: ${format(...args)}\n`);
},

0 comments on commit 9fc1701

Please sign in to comment.