Skip to content

Commit

Permalink
feat(start-feature): support passing in feature branch directly via cli
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Jun 25, 2019
1 parent 7604540 commit 8b1e49b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ program

program
.command('start-feature')
.arguments('[feature-branch]')
.description('Create new feature branch')
.action(async () => {
.action(async (featureBranch) => {
try {
await git.bailIfNotGitDirectory();
await git.startFeature(git.getConfig(process.cwd()));
await git.startFeature(git.getConfig(process.cwd()), featureBranch);
} catch (e) {
console.log(e.message);
}
Expand All @@ -112,7 +113,7 @@ program
await git.bailIfNotGitDirectory();
await git.startHotfix(hotfixBranch);
} catch (e) {
console.log(e.message, e);
console.log(e.message);
}
});

Expand Down
15 changes: 12 additions & 3 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function setConfig(key, {projectName, sprintNumber}) {
conf.set(`${key}sprintNumber`, sprintNumber);
}

async function startFeature(config) {
async function startFeature(config, featureBranch) {
if (!await isClean()) {
const {confirm} = await inquirer.confirmStash();
if (confirm) {
Expand All @@ -252,12 +252,21 @@ async function startFeature(config) {
throw new Error('Operation aborted.');
}
}

const {projectName, sprintNumber} = await inquirer.askProjectNameAndSprintNumber(config);
const {issueNumber, feature} = await inquirer.askIssueNumberAndFeature();
const parts = (featureBranch || '').match(/^(\d+)-(.*)/) || [];
if (featureBranch && !parts.length) {
console.log('invalid target feature branch');
}
const {issueNumber, feature} = parts.length
? {issueNumber: parts[1], feature: parts[2]}
: await inquirer.askIssueNumberAndFeature();

const refinedFeature = toDashCase(feature);
await fetchAll();
const baseBranch = `${projectName}/sprint-${sprintNumber}`;
const targetBranch = `${projectName}-sprint-${sprintNumber}/${issueNumber}-${refinedFeature}`;

await fetchAll();
await checkout(baseBranch);
await resetHardToRemoteBranch(`${DEFAULT_REMOTE}/${baseBranch}`);
await createAndCheckoutBranch(targetBranch);
Expand Down

0 comments on commit 8b1e49b

Please sign in to comment.