Skip to content

Commit

Permalink
Support main branch in skuba init (#1335)
Browse files Browse the repository at this point in the history
* Support `main` branch in `skuba init`

* Fix changeset

* Update src/cli/init/git.ts

Co-authored-by: Ryan Ling <[email protected]>

* Update .changeset/smart-ghosts-complain.md

Co-authored-by: Ryan Ling <[email protected]>

* Update docs/cli/init.md

Co-authored-by: Ryan Ling <[email protected]>

---------

Co-authored-by: Ryan Ling <[email protected]>
  • Loading branch information
AaronMoat and 72636c committed Dec 12, 2023
1 parent 04f4316 commit c893558
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-ghosts-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': minor
---

init: Support `main` default branch
5 changes: 3 additions & 2 deletions docs/cli/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ git remote get-url origin
```

**skuba** has committed its initial template files and configured a remote `origin` for you.
You should create the corresponding repository on GitHub and push to it:
You should create the corresponding repository on GitHub and push to it.
Replace `main` with your default branch name as appropriate:

```shell
git push --set-upstream origin master
git push --set-upstream origin main
```

### Directory structure
Expand Down
3 changes: 2 additions & 1 deletion scripts/test-template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ yarn skuba init << EOF
"platformName": "arm64",
"repoName": "${directory}",
"serviceName": "serviceName",
"region": "ap-southeast-2"
"region": "ap-southeast-2",
"defaultBranch": "main"
},
"templateName": "${template}"
}
Expand Down
5 changes: 4 additions & 1 deletion src/cli/init/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const baseToTemplateData = async ({
ownerName,
platformName,
repoName,
defaultBranch,
}: BaseFields) => {
const [orgName, teamName] = ownerName.split('/');

Expand All @@ -163,6 +164,7 @@ const baseToTemplateData = async ({
orgName,
ownerName,
repoName,
defaultBranch,
// Use standalone username in `teamName` contexts
teamName: teamName ?? orgName,

Expand All @@ -176,14 +178,15 @@ const baseToTemplateData = async ({
};

export const configureFromPrompt = async (): Promise<InitConfig> => {
const { ownerName, platformName, repoName } =
const { ownerName, platformName, repoName, defaultBranch } =
await runForm<BaseFields>(BASE_PROMPT_PROPS);
log.plain(chalk.cyan(repoName), 'by', chalk.cyan(ownerName));

const templateData = await baseToTemplateData({
ownerName,
platformName,
repoName,
defaultBranch,
});

const destinationDir = repoName;
Expand Down
6 changes: 3 additions & 3 deletions src/cli/init/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { log } from '../../utils/logging';
interface GitHubProject {
orgName: string;
repoName: string;
defaultBranch: string;
}

export const initialiseRepo = async (
dir: string,
{ orgName, repoName }: GitHubProject,
{ orgName, repoName, defaultBranch }: GitHubProject,
) => {
await git.init({
// TODO: support main as an alternative.
defaultBranch: 'master',
defaultBranch,
dir,
fs,
});
Expand Down
4 changes: 2 additions & 2 deletions src/cli/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const init = async () => {
log.ok('yarn add --dev', skubaSlug);
log.ok('git add --all');
log.ok('git commit --message', `'Pin ${skubaSlug}'`);
log.ok('git push --set-upstream origin master');
log.ok(`git push --set-upstream origin ${templateData.defaultBranch}`);

log.newline();
process.exitCode = 1;
Expand All @@ -132,7 +132,7 @@ export const init = async () => {
log.newline();
log.plain('Then, push your local changes:');
log.ok('cd', destinationDir);
log.ok('git push --set-upstream origin master');
log.ok(`git push --set-upstream origin ${templateData.defaultBranch}`);

log.newline();
};
7 changes: 7 additions & 0 deletions src/cli/init/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ const BASE_CHOICES = [
validate: (value: unknown) =>
isPlatform(value) || `must be ${PLATFORM_OPTIONS}`,
},
{
name: 'defaultBranch',
message: 'Default Branch',
initial: 'master | main',
validate: (value: unknown) =>
typeof value === 'string' && value.length > 0 ? true : 'required',
},
] as const;

export const BASE_PROMPT_PROPS = {
Expand Down
2 changes: 2 additions & 0 deletions src/cli/init/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const initConfigInputSchema = z.object({
ownerName: z.string(),
repoName: z.string(),
platformName: z.union([z.literal('amd64'), z.literal('arm64')]),
defaultBranch: z.string(),
})
.catchall(z.string()),
templateName: z.string(),
Expand All @@ -28,6 +29,7 @@ const initConfigSchema = initConfigInputSchema
.object({
ownerName: z.string(),
repoName: z.string(),
defaultBranch: z.string(),

// Derived from ownerName
// TODO: use zod to transform `InitConfigInput` -> `InitConfig`?
Expand Down

0 comments on commit c893558

Please sign in to comment.