-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsetup-branch.ts
More file actions
35 lines (30 loc) · 1.04 KB
/
setup-branch.ts
File metadata and controls
35 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { ContentstackClient, getBranchFromAlias, log } from '@contentstack/cli-utilities';
import { ImportConfig } from 'src/types';
import { validateBranch } from './common-helper';
export const setupBranchConfig = async (
config: ImportConfig,
stackAPIClient: ReturnType<ContentstackClient['stack']>,
): Promise<void> => {
if (config.branchName) {
await validateBranch(stackAPIClient, config, config.branchName);
return;
}
if (config.branchAlias) {
config.branchName = await getBranchFromAlias(stackAPIClient, config.branchAlias);
return;
}
try {
const branches = await stackAPIClient
.branch()
.query()
.find()
.then(({ items }) => items);
if (branches.length) {
log.info(`The stack is branch-enabled, and branches exist. By default, content will be imported into the main branch.`);
config.branchName = 'main';
log.debug(`Setting default target branch to 'main'`);
}
} catch (error) {
log.debug('Failed to fetch branches', { error });
}
};