Comparing version
@@ -8,3 +8,3 @@ const fs = require('fs') | ||
const { API_KEY_FILE, ENDPOINT } = require('../constants') | ||
const { PT_API_KEY_FILE, PT_ENDPOINT } = require('../constants') | ||
@@ -15,5 +15,5 @@ module.exports = async function (argv) { | ||
try { | ||
apiKey = fs.readFileSync(API_KEY_FILE, 'utf8') | ||
apiKey = fs.readFileSync(PT_API_KEY_FILE, 'utf8') | ||
} catch (err) { | ||
console.log('You need to store API key first'.red) | ||
console.log('You need to store Pivotal Tracker API key first'.red) | ||
process.exit(1) | ||
@@ -29,3 +29,3 @@ } | ||
const response = await fetch(`${ENDPOINT}/${argv.storyId}`, { | ||
const response = await fetch(`${PT_ENDPOINT}/${argv.storyId}`, { | ||
headers: { 'X-TrackerToken': apiKey } | ||
@@ -38,2 +38,5 @@ }) | ||
const currentBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim() | ||
const defaultBranch = execSync("git remote show origin | sed -n '/HEAD branch/s/.*: //p'").toString().trim() | ||
const commitAhead = Number(execSync(`git rev-list --count origin/${defaultBranch}...${currentBranch}`).toString().trim()) | ||
const useCurrentBranch = currentBranch === branchName | ||
@@ -44,9 +47,21 @@ const questions = [ | ||
name: 'useCurrentBranch', | ||
message: `Use current branch (${currentBranch})`, | ||
message: `Use current branch: ${colors.underline(currentBranch)}?`, | ||
default: false, | ||
when() { | ||
return !useCurrentBranch | ||
} | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'squash', | ||
message: `We detect ${commitAhead} commit(s) ahead of ${defaultBranch}, squash?`, | ||
default: false, | ||
when() { | ||
return commitAhead | ||
}, | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'commitMessage', | ||
message: 'Commit message: ', | ||
message: 'Commit message:', | ||
default: commitMessage, | ||
@@ -58,3 +73,3 @@ suffix: commitPrefix, | ||
name: 'push', | ||
message: `Push to branch`, | ||
message: 'Push to branch?', | ||
default: false, | ||
@@ -67,10 +82,14 @@ }, | ||
.then((answers) => { | ||
if (!answers.useCurrentBranch) { | ||
if (!useCurrentBranch && !answers.useCurrentBranch) { | ||
execSync(`git checkout -b ${branchName}`) | ||
} | ||
if (answers.squash) { | ||
execSync(`git reset --soft HEAD~${commitAhead}`) | ||
} | ||
execSync(`git commit -m "${commitPrefix} ${answers.commitMessage}"`) | ||
if (answers.push) { | ||
const output = execSync(`git push -u origin ${branchName}`).toString().trim() | ||
const output = execSync(`git push ${answers.squash ? '-f' : ''} -u origin HEAD`).toString().trim() | ||
console.log(output) | ||
@@ -77,0 +96,0 @@ } |
@@ -1,7 +0,7 @@ | ||
const API_KEY_FILE = `${__dirname}/api_key` | ||
const ENDPOINT = 'https://www.pivotaltracker.com/services/v5/stories' | ||
const PT_API_KEY_FILE = `${__dirname}/pt_api_key` | ||
const PT_ENDPOINT = 'https://www.pivotaltracker.com/services/v5/stories' | ||
module.exports = { | ||
API_KEY_FILE, | ||
ENDPOINT, | ||
PT_API_KEY_FILE, | ||
PT_ENDPOINT, | ||
} |
#!/usr/bin/env node | ||
const apiKeyCommand = require('./commands/api-key') | ||
const apiKeyCommand = require('./commands/pt-api-key') | ||
const ptCommand = require('./commands/pt') | ||
@@ -9,3 +9,3 @@ | ||
.usage('$0 <cmd> [args]') | ||
.command('api-key [apiKey]', 'store API key in your local machine', (yargs) => { | ||
.command('pt-api-key [apiKey]', 'store Pivotal Tracker API key in your local machine', (yargs) => { | ||
yargs.positional('apiKey', { | ||
@@ -12,0 +12,0 @@ type: 'string', |
{ | ||
"name": "dorong", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5193
19.49%127
16.51%8
-11.11%