Skip to content

Commit 47bf28c

Browse files
authored
feat: output a warning if the parent branch is protected (#280)
1 parent 52c6ee8 commit 47bf28c

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/commands/branches.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,17 @@ const create = async (
284284
'--'?: string[];
285285
},
286286
) => {
287-
const parentProps = await (() => {
287+
const branches = await props.apiClient
288+
.listProjectBranches(props.projectId)
289+
.then(({ data }) => data.branches);
290+
291+
const parentProps = (() => {
288292
if (!props.parent) {
289-
return props.apiClient
290-
.listProjectBranches(props.projectId)
291-
.then(({ data }) => {
292-
const branch = data.branches.find((b) => b.default);
293-
if (!branch) {
294-
throw new Error('No default branch found');
295-
}
296-
return { parent_id: branch.id };
297-
});
293+
const branch = branches.find((b) => b.default);
294+
if (!branch) {
295+
throw new Error('No default branch found');
296+
}
297+
return { parent_id: branch.id };
298298
}
299299

300300
if (looksLikeLSN(props.parent)) {
@@ -308,15 +308,12 @@ const create = async (
308308
if (looksLikeBranchId(props.parent)) {
309309
return { parent_id: props.parent };
310310
}
311-
return props.apiClient
312-
.listProjectBranches(props.projectId)
313-
.then(({ data }) => {
314-
const branch = data.branches.find((b) => b.name === props.parent);
315-
if (!branch) {
316-
throw new Error(`Branch ${props.parent} not found`);
317-
}
318-
return { parent_id: branch.id };
319-
});
311+
312+
const branch = branches.find((b) => b.name === props.parent);
313+
if (!branch) {
314+
throw new Error(`Branch ${props.parent} not found`);
315+
}
316+
return { parent_id: branch.id };
320317
})();
321318

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

341+
const parent = branches.find((b) => b.id === data.branch.parent_id);
342+
if (parent?.protected) {
343+
log.warning(
344+
'The parent branch is protected; a unique role password has been generated for the new branch.',
345+
);
346+
}
347+
344348
const out = writer(props);
349+
345350
out.write(data.branch, {
346351
fields: BRANCH_FIELDS,
347352
title: 'branch',

src/log.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const log = {
77
process.stderr.write(`DEBUG: ${format(...args)}\n`);
88
}
99
},
10+
warning: (...args: unknown[]) => {
11+
process.stderr.write(`WARNING: ${format(...args)}\n`);
12+
},
1013
info: (...args: unknown[]) => {
1114
process.stderr.write(`INFO: ${format(...args)}\n`);
1215
},

0 commit comments

Comments
 (0)