Last active
December 25, 2017 14:35
-
-
Save thatkookooguy/fbaa9adf1ffe14f14186e8ba1b5b979c to your computer and use it in GitHub Desktop.
diff2html-cli example file that gives 0 file changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1mdiff --git a/lib/commandDefinitions.js b/lib/commandDefinitions.js[m | |
[1mindex f1809d7..e5b9e1d 100644[m | |
[1m--- a/lib/commandDefinitions.js[m | |
[1m+++ b/lib/commandDefinitions.js[m | |
[36m@@ -4,8 +4,10 @@[m [mvar statusGitflow = require('./gitflow/status');[m | |
var commitGitflow = require('./gitflow/commit');[m | |
var finishGitflow = require('./gitflow/finish');[m | |
var featureGitflow = require('./gitflow/feature');[m | |
[32m+[m[32mvar releaseGitflow = require('./gitflow/release');[m | |
var hotfixGitflow = require('./gitflow/hotfix');[m | |
var developGitflow = require('./gitflow/develop');[m | |
[32m+[m[32mvar syncGitflow = require('./gitflow/sync');[m | |
var masterGitflow = require('./gitflow/master');[m | |
// var inquirer = require('inquirer');[m | |
var shell = require('shelljs');[m | |
[36m@@ -251,7 +253,7 @@[m [mfunction addSubCommandFinish(program) {[m | |
[m | |
function addSubCommandRelease(program) {[m | |
program[m | |
[31m- .command('release <action>')[m | |
[32m+[m[32m .command('release [releaseName]')[m | |
.description(kbString.build([m | |
kbString.info([m | |
'When you have enough completed features in origin/develop, '[m | |
[36m@@ -259,7 +261,7 @@[m [mfunction addSubCommandRelease(program) {[m | |
kbString.info('create a release branch, test it and fix it, '),[m | |
kbString.info('and then merge it into origin/master')[m | |
))[m | |
[31m- .action(release)[m | |
[32m+[m[32m .action(releaseGitflow.release)[m | |
.on('help', function(cmd) {[m | |
cmd.outputIndented('Examples', [[m | |
kbString.build([m | |
[36m@@ -285,7 +287,7 @@[m [mfunction addSubCommandUpdate(program) {[m | |
.description([m | |
kbString.info('keep up-to-date with completed features on GitHub')[m | |
)[m | |
[31m- .action(update)[m | |
[32m+[m[32m .action(syncGitflow.sync)[m | |
.on('help', function(cmd) {[m | |
cmd.outputIndented('Examples', [[m | |
kbString.build([m | |
[36m@@ -360,27 +362,13 @@[m [mfunction clone() {[m | |
console.error('clone!');[m | |
}[m | |
[m | |
[31m-function release(args) {[m | |
[31m- if (['start', 'finish'].indexOf(args.action) < 0) {[m | |
[31m- console.error(ohNo([[m | |
[31m- '[ERROR]: ',[m | |
[31m- kbString.kibibitLogo(),[m | |
[31m- kbString.kbString.success(' release '),[m | |
[31m- 'expects either start or finish'[m | |
[31m- ]));[m | |
[31m- process.exit(1);[m | |
[31m- }[m | |
[31m-[m | |
[31m- kbExec('git hf release ' + args.action);[m | |
[31m-}[m | |
[31m-[m | |
function push() {[m | |
kbExec('git hf push');[m | |
}[m | |
[m | |
[31m-function update() {[m | |
[31m- kbExec('git hf update');[m | |
[31m-}[m | |
[32m+[m[32m// function update() {[m | |
[32m+[m[32m// kbExec('git hf update');[m | |
[32m+[m[32m// }[m | |
[m | |
function kbExec(command) {[m | |
if (shell.exec(command).code !== 0) {[m | |
[1mdiff --git a/lib/gitflow/init.js b/lib/gitflow/init.js[m | |
[1mindex 04bd3f3..e388e35 100644[m | |
[1m--- a/lib/gitflow/init.js[m | |
[1m+++ b/lib/gitflow/init.js[m | |
[36m@@ -1,5 +1,5 @@[m | |
var os = require('os');[m | |
[31m-var path = require('path');[m | |
[32m+[m[32m// var path = require('path');[m | |
var kbString = require('../kb-string');[m | |
var gitRoot = require('../kb-git-root');[m | |
var inquirer = require('inquirer');[m | |
[36m@@ -9,6 +9,9 @@[m [mvar Q = require('q');[m | |
var colorize = require('json-colorizer');[m | |
var currentFolder = process.cwd();[m | |
var NodeGit = require('nodegit-flow');[m | |
[32m+[m[32mvar keytar = require('keytar');[m | |
[32m+[m[32mvar globalCfg = require('home-config').load('.kibibit-bit');[m | |
[32m+[m[32mvar utility = require('./utility');[m | |
// var findRoot = require('find-root');[m | |
[m | |
var GLOBAL = {[m | |
[36m@@ -19,15 +22,6 @@[m [mvar GLOBAL = {[m | |
[m | |
var ui = new inquirer.ui.BottomBar();[m | |
[m | |
[31m-var signingIn = [[m | |
[31m- kbString.info(kbString.warning('/'), ' Signing in'),[m | |
[31m- kbString.info(kbString.warning('|'), ' Signing in..'),[m | |
[31m- kbString.info(kbString.warning('\\'), ' Signing in..'),[m | |
[31m- kbString.info(kbString.warning('-'), ' Signing in...')[m | |
[31m-];[m | |
[31m-var signingInSteps = 4;[m | |
[31m-// var client = github.client();[m | |
[31m-[m | |
var initGitflow = {};[m | |
[m | |
initGitflow.init = init;[m | |
[36m@@ -36,12 +30,6 @@[m [minitGitflow.hotfixBranchesPrefixDefault = hotfixBranchesPrefixDefault;[m | |
initGitflow.releaseBranchesPrefixDefault = releaseBranchesPrefixDefault;[m | |
[m | |
initGitflow.questions = [[m | |
[31m- // shouldInitRepo(),[m | |
[31m- // shouldCopyGlobalSettings(),[m | |
[31m- //askForGitHubUser(),[m | |
[31m- //askForGitHubPassword(),[m | |
[31m- //askForOTPCode(GLOBAL),[m | |
[31m- // askIfRebaseOrMerge(),[m | |
askNameOfMasterBranch(),[m | |
askNameOfDevelopBranch(),[m | |
askPrefixOfFeatureBranches(),[m | |
[36m@@ -82,46 +70,95 @@[m [mfunction makeInitialCommit(branch) {[m | |
};[m | |
}[m | |
[m | |
[31m-function init(args, options) {[m | |
[31m- console.log('starting');[m | |
[31m- gitRoot.getGitRoot()[m | |
[31m- .then(function(gitRoot) {[m | |
[31m- console.log('this is git root', gitRoot);[m | |
[31m- if (!gitRoot) {[m | |
[31m- console.info(kbString.error('git repo not found'));[m | |
[31m- console.log('initializing...');[m | |
[31m- // initialize a git repo in this folder if it doesn't exist[m | |
[31m- return NodeGit.Repository.init(currentFolder, 0);[m | |
[31m- } else {[m | |
[31m- // open the git repo if it exists[m | |
[31m- return NodeGit.Repository.open(gitRoot);[m | |
[31m- }[m | |
[31m- })[m | |
[32m+[m[32mfunction ensureGitInitialized(gitRoot) {[m | |
[32m+[m[32m if (!gitRoot) {[m | |
[32m+[m[32m console.info(kbString.error('git repo not found'));[m | |
[32m+[m[32m console.log('initializing...');[m | |
[32m+[m[32m }[m | |
[32m+[m | |
[32m+[m[32m // initialize a git repo in this folder if it doesn't exist[m | |
[32m+[m[32m // open the git repo if it exists[m | |
[32m+[m[32m var action = gitRoot ?[m | |
[32m+[m[32m NodeGit.Repository.open(gitRoot) :[m | |
[32m+[m[32m NodeGit.Repository.init(currentFolder, 0);[m | |
[32m+[m | |
[32m+[m[32m return action[m | |
.then(function(repo) {[m | |
[31m- // now we def have a repo.[m | |
GLOBAL.repo = repo;[m | |
[31m- console.log('we have a repo');[m | |
[31m- // is it a git flow repo?[m | |
[31m- return NodeGit.Flow.isInitialized(GLOBAL.repo);[m | |
[31m- })[m | |
[32m+[m | |
[32m+[m[32m return repo;[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction ensureGitFlowNotInitialized() {[m | |
[32m+[m[32m return NodeGit.Flow.isInitialized(GLOBAL.repo)[m | |
.then(function(isInit) {[m | |
GLOBAL.isGitflow = isInit;[m | |
[m | |
[31m- if (isInit) {[m | |
[31m- console.log('repo is already a git flow repo');[m | |
[32m+[m[32m if (GLOBAL.isGitflow) {[m | |
[32m+[m[32m console.log(kbString.error('repo is already a git flow repo'));[m | |
process.exit(1);[m | |
}[m | |
[m | |
[32m+[m[32m return;[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction init(args, options) {[m | |
[32m+[m[32m gitRoot.getGitRoot()[m | |
[32m+[m[32m .then(ensureGitInitialized)[m | |
[32m+[m[32m .then(ensureGitFlowNotInitialized)[m | |
[32m+[m[32m // TODO(thatkookooguy): add a step to check remote repo[m | |
[32m+[m[32m // if exists already.[m | |
[32m+[m[32m .then(function() {[m | |
// now we know we have a git repo that is not a git flow repo[m | |
// ask the user what he wants to do[m | |
printFlash();[m | |
// for now, this does nothing...[m | |
if (options.force) {[m | |
console.log(kbString.warning('WARNING: force detected'));[m | |
[31m- // process.exit(0);[m | |
[32m+[m[32m process.exit(1);[m | |
}[m | |
[m | |
[31m- return inquirer.prompt(initGitflow.questions);[m | |
[32m+[m[32m return associateUser();[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m[32m console.log('user associated');[m | |
[32m+[m[32m return utility.getGitHubUserData(GLOBAL.username, GLOBAL.token);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(githubUser) {[m | |
[32m+[m[32m // console.log('github user', githubUser);[m | |
[32m+[m[32m console.log('github user email', githubUser.email);[m | |
[32m+[m[32m console.log('github user username', githubUser.login);[m | |
[32m+[m | |
[32m+[m[32m return utility.getOrgs();[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(orgs) {[m | |
[32m+[m[32m var orgNames = _.map(orgs, function(org) {[m | |
[32m+[m[32m return org.login;[m | |
[32m+[m[32m });[m | |
[32m+[m[32m GLOBAL.orgs = orgNames;[m | |
[32m+[m[32m console.log('user organizations', orgNames);[m | |
[32m+[m[32m // process.exit(0);[m | |
[32m+[m[32m // TODO(thatkookooguy): need to add a few questions[m | |
[32m+[m[32m // - check if any users registered with bit in keychain in GLOBAL setting:[m | |
[32m+[m[32m // - select an existing user or create a user[m | |
[32m+[m[32m // - store new user token in keychain if created[m | |
[32m+[m[32m // - create a remote repo (clone will connect to existing one)[m | |
[32m+[m[32m // - name of repository?[m | |
[32m+[m[32m // - create it for user or organization a user is a member of?[m | |
[32m+[m[32m // - should include a readme.md?[m | |
[32m+[m[32m // - add global git flow config file called .bit.json[m | |
[32m+[m[32m // it will hold names of branches and prefixes[m | |
[32m+[m[32m // (later, if bit will be used in a repo with that file,[m | |
[32m+[m[32m // it will init automatically with that config if not initialized)[m | |
[32m+[m[32m return inquirer.prompt([[m | |
[32m+[m[32m askNameOfMasterBranch(),[m | |
[32m+[m[32m askNameOfDevelopBranch(),[m | |
[32m+[m[32m askPrefixOfFeatureBranches(),[m | |
[32m+[m[32m askPrefixOfHotfixBranches(),[m | |
[32m+[m[32m askPrefixOfReleaseBranches()[m | |
[32m+[m[32m ]);[m | |
})[m | |
.then(function(answers) {[m | |
delete answers.GitHubPassword;[m | |
[36m@@ -194,7 +231,8 @@[m [mfunction init(args, options) {[m | |
})[m | |
.then(function() {[m | |
console.log('git flow repo initialized');[m | |
[31m- process.exit(0);[m | |
[32m+[m[32m return createOrigin();[m | |
[32m+[m[32m //process.exit(0);[m | |
})[m | |
.catch(function(error) {[m | |
console.error('something went wrong: ', error);[m | |
[36m@@ -202,6 +240,166 @@[m [mfunction init(args, options) {[m | |
});[m | |
}[m | |
[m | |
[32m+[m[32mfunction createOrigin() {[m | |
[32m+[m[32m return inquirer.prompt([{[m | |
[32m+[m[32m type: 'list',[m | |
[32m+[m[32m name: 'whereToCreate',[m | |
[32m+[m[32m message: 'Where should repo be created?',[m | |
[32m+[m[32m choices: [[m | |
[32m+[m[32m GLOBAL.username,[m | |
[32m+[m[32m new inquirer.Separator()[m | |
[32m+[m[32m ].concat(GLOBAL.orgs)[m | |
[32m+[m[32m },[m | |
[32m+[m[32m {[m | |
[32m+[m[32m type: 'input',[m | |
[32m+[m[32m name: 'repoName',[m | |
[32m+[m[32m message: 'what do you want to name the repo?',[m | |
[32m+[m[32m },[m | |
[32m+[m[32m {[m | |
[32m+[m[32m type: 'input',[m | |
[32m+[m[32m name: 'repoDescription',[m | |
[32m+[m[32m message: 'give the repo a short description (optional)',[m | |
[32m+[m[32m }])[m | |
[32m+[m[32m .then(function(answers) {[m | |
[32m+[m[32m console.log('answers', answers);[m | |
[32m+[m | |
[32m+[m[32m GLOBAL.repoName = answers.repoName;[m | |
[32m+[m[32m GLOBAL.repoDescription = answers.repoDescription;[m | |
[32m+[m | |
[32m+[m[32m if (answers.whereToCreate === GLOBAL.username) {[m | |
[32m+[m[32m return utility.createRepoUser(GLOBAL.repoName, GLOBAL.repoDescription);[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m console.log('ORGANIZATION REPOOOOO!!!');[m | |
[32m+[m[32m return utility.createRepoOrg(answers.whereToCreate,[m | |
[32m+[m[32m GLOBAL.repoName, GLOBAL.repoDescription);[m | |
[32m+[m[32m //process.exit(1);[m | |
[32m+[m[32m }[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(body) {[m | |
[32m+[m[32m console.log('created repo', body.clone_url);[m | |
[32m+[m | |
[32m+[m[32m // OR ORIGIN!!!!!! INSTEAD OF NAME[m | |
[32m+[m[32m return NodeGit.Remote[m | |
[32m+[m[32m .create(GLOBAL.repo, 'origin', body.clone_url);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(remote) {[m | |
[32m+[m[32m GLOBAL.remote = remote;[m | |
[32m+[m[32m console.log('successfully added a new remote!', GLOBAL.remote.name());[m | |
[32m+[m | |
[32m+[m[32m return NodeGit.Flow.getConfig(GLOBAL.repo);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(config) {[m | |
[32m+[m[32m return GLOBAL.remote.push([[m | |
[32m+[m[32m 'refs/heads/master:refs/heads/master'[m | |
[32m+[m[32m ], {[m | |
[32m+[m[32m callbacks: {[m | |
[32m+[m[32m certificateCheck: function() {[m | |
[32m+[m[32m return 1;[m | |
[32m+[m[32m },[m | |
[32m+[m[32m credentials: function() {[m | |
[32m+[m[32m console.log('asked for credentials', GLOBAL.token);[m | |
[32m+[m[32m return NodeGit.Cred[m | |
[32m+[m[32m .userpassPlaintextNew(GLOBAL.token, 'x-oauth-basic');[m | |
[32m+[m[32m }[m | |
[32m+[m[32m }[m | |
[32m+[m[32m });[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction selectExistingUser() {[m | |
[32m+[m[32m return inquirer.prompt([ {[m | |
[32m+[m[32m type: 'list',[m | |
[32m+[m[32m name: 'selectUser',[m | |
[32m+[m[32m message: 'Found registered users. Select a user for this repo',[m | |
[32m+[m[32m choices: globalCfg.users.concat([[m | |
[32m+[m[32m new inquirer.Separator(),[m | |
[32m+[m[32m 'Add a new user'[m | |
[32m+[m[32m ])[m | |
[32m+[m[32m } ])[m | |
[32m+[m[32m .then(function(answers) {[m | |
[32m+[m[32m if (globalCfg.users.indexOf(answers.selectUser) > -1) {[m | |
[32m+[m[32m console.log('existing user selected');[m | |
[32m+[m | |
[32m+[m[32m GLOBAL.username = answers.selectUser;[m | |
[32m+[m | |
[32m+[m[32m console.log('global username', GLOBAL.username);[m | |
[32m+[m | |
[32m+[m[32m return GLOBAL.repo.config()[m | |
[32m+[m[32m .then(function(config) {[m | |
[32m+[m[32m return config.setString('kibibit.user', GLOBAL.username);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m[32m return keytar.getPassword('kibibit-cli', GLOBAL.username);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(value) {[m | |
[32m+[m[32m console.log('got token from keychain', value);[m | |
[32m+[m | |
[32m+[m[32m GLOBAL.token = value;[m | |
[32m+[m[32m // process.exit(0);[m | |
[32m+[m[32m return;[m | |
[32m+[m[32m });[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m console.log('create a new user');[m | |
[32m+[m | |
[32m+[m[32m return loginNewUser();[m | |
[32m+[m[32m }[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction loginNewUser() {[m | |
[32m+[m[32m return inquirer.prompt([[m | |
[32m+[m[32m askForGitHubUser(),[m | |
[32m+[m[32m askForGitHubPassword(),[m | |
[32m+[m[32m askForOTPCode(GLOBAL)[m | |
[32m+[m[32m ])[m | |
[32m+[m[32m .then(function(answers) {[m | |
[32m+[m[32m console.log('user logged in', answers);[m | |
[32m+[m[32m //save token in keychain[m | |
[32m+[m[32m globalCfg.users.push(answers.GitHubUsername);[m | |
[32m+[m | |
[32m+[m[32m GLOBAL.username = answers.GitHubUsername;[m | |
[32m+[m | |
[32m+[m[32m globalCfg.save();[m | |
[32m+[m | |
[32m+[m[32m return keytar[m | |
[32m+[m[32m .setPassword('kibibit-cli', answers.GitHubUsername, GLOBAL.token);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m[32m console.log('wrote token to keychain');[m | |
[32m+[m | |
[32m+[m[32m return GLOBAL.repo.config()[m | |
[32m+[m[32m .then(function(config) {[m | |
[32m+[m[32m return config.setString('user.name', GLOBAL.username);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m[32m return keytar.getPassword('kibibit-cli', GLOBAL.username);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(cred) {[m | |
[32m+[m[32m console.log('all kibibit-cli creds: ', cred);[m | |
[32m+[m[32m GLOBAL.token = cred;[m | |
[32m+[m[32m return utility.getGitHubUserData(GLOBAL.username, GLOBAL.token);[m | |
[32m+[m[32m // process.exit(0);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(githubUser) {[m | |
[32m+[m[32m return config.setString('user.email', githubUser.email);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction associateUser() {[m | |
[32m+[m[32m if (globalCfg.users && globalCfg.users.length > 0) {[m | |
[32m+[m[32m console.log('found users');[m | |
[32m+[m | |
[32m+[m[32m return selectExistingUser();[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m console.log('no registered users found');[m | |
[32m+[m | |
[32m+[m[32m globalCfg.users = [];[m | |
[32m+[m | |
[32m+[m[32m return loginNewUser();[m | |
[32m+[m[32m }[m | |
[32m+[m[32m}[m | |
[32m+[m | |
function ensureSlash(prefix) {[m | |
return _.endsWith(prefix, '/') ? prefix : prefix + '/';[m | |
}[m | |
[36m@@ -311,9 +509,6 @@[m [mfunction askForGitHubUser() {[m | |
[m | |
function askForGitHubPassword() {[m | |
return {[m | |
[31m- when: function(userAnswers) {[m | |
[31m- return !userAnswers.takeGlobalGitHubUser;[m | |
[31m- },[m | |
type: 'password',[m | |
name: 'GitHubPassword',[m | |
message: 'GitHub password:',[m | |
[36m@@ -456,16 +651,14 @@[m [mfunction loginGitHub(username, password, otpCode) {[m | |
[m | |
var loaderId = setInterval(function() {[m | |
if (loaderId) {[m | |
[31m- ui.updateBottomBar(signingIn[signingInSteps++ % 4]);[m | |
[32m+[m[32m ui.updateBottomBar(util.signingInAnimation[util.signingInSteps++ % 4]);[m | |
}[m | |
}, 300);[m | |
[m | |
var scopes = {[m | |
[31m- 'add_scopes': ['user', 'repo', 'gist'],[m | |
[32m+[m[32m 'scopes': ['user', 'repo', 'gist', 'read:org'],[m | |
'note': [[m | |
[31m- 'kibibit cli', ' - ', path.basename(gitRoot), ' - ',[m | |
[31m- os.userInfo().username,[m | |
[31m- '@',[m | |
[32m+[m[32m 'kibibit cli','@',[m | |
os.hostname(),[m | |
' on ', os.type()[m | |
].join('')[m | |
[36m@@ -515,7 +708,7 @@[m [mfunction loginGitHub(username, password, otpCode) {[m | |
return deferred.promise;[m | |
}[m | |
[m | |
[31m-function checkRepoStatus(repo) {[m | |
[32m+[m[32mfunction checkRepoStatus() {[m | |
NodeGit.Flow.isInitialized(GLOBAL.repo)[m | |
.then(function(isInit) {[m | |
GLOBAL.isGitflow = isInit;[m | |
[1mdiff --git a/lib/gitflow/release.js b/lib/gitflow/release.js[m | |
[1mnew file mode 100644[m | |
[1mindex 0000000..f55d50a[m | |
[1m--- /dev/null[m | |
[1m+++ b/lib/gitflow/release.js[m | |
[36m@@ -0,0 +1,154 @@[m | |
[32m+[m[32mvar kbString = require('../kb-string');[m | |
[32m+[m[32mvar _ = require('lodash');[m | |
[32m+[m[32mvar Q = require('q');[m | |
[32m+[m[32mvar NodeGit = require('nodegit-flow');[m | |
[32m+[m[32mvar moment = require('moment');[m | |
[32m+[m[32mvar gitRoot = require('../kb-git-root');[m | |
[32m+[m | |
[32m+[m[32mvar GLOBAL = {[m | |
[32m+[m[32m repo: null,[m | |
[32m+[m[32m releaseBranches: null[m | |
[32m+[m[32m};[m | |
[32m+[m | |
[32m+[m[32mvar releaseGitflow = {};[m | |
[32m+[m | |
[32m+[m[32mreleaseGitflow.release = release;[m | |
[32m+[m | |
[32m+[m[32mmodule.exports = releaseGitflow;[m | |
[32m+[m | |
[32m+[m[32mfunction startRelease(args) {[m | |
[32m+[m[32m return NodeGit.Flow.startRelease([m | |
[32m+[m[32m GLOBAL.repo,[m | |
[32m+[m[32m args.releaseName[m | |
[32m+[m[32m )[m | |
[32m+[m[32m .then(function(branch) {[m | |
[32m+[m[32m console[m | |
[32m+[m[32m .log('creating release named', args.releaseName);[m | |
[32m+[m[32m return branch;[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .catch(function(/*error*/) {[m | |
[32m+[m[32m // console.trace(error);[m | |
[32m+[m[32m return NodeGit.Flow.getConfig(GLOBAL.repo)[m | |
[32m+[m[32m .then(function(config) {[m | |
[32m+[m[32m // console.log(config);[m | |
[32m+[m[32m GLOBAL.currReleaseBranch =[m | |
[32m+[m[32m config['gitflow.prefix.release'] + args.releaseName;[m | |
[32m+[m[32m console[m | |
[32m+[m[32m .log('checking out existing release ', GLOBAL.currReleaseBranch);[m | |
[32m+[m[32m return GLOBAL.repo.checkoutBranch(GLOBAL.currReleaseBranch);[m | |
[32m+[m[32m // process.exit(1);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m[32m return GLOBAL.repo.getBranch(GLOBAL.currReleaseBranch);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction release(args, options) {[m | |
[32m+[m | |
[32m+[m[32m gitRoot.getGitRoot()[m | |
[32m+[m[32m .then(function(_gitRoot) {[m | |
[32m+[m[32m if (!_gitRoot) {[m | |
[32m+[m[32m console.info(kbString.error('git repo not found'));[m | |
[32m+[m[32m process.exit(1);[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m GLOBAL.gitRoot = _gitRoot;[m | |
[32m+[m[32m // open the git repo if it exists[m | |
[32m+[m[32m return NodeGit.Repository.open(GLOBAL.gitRoot);[m | |
[32m+[m[32m }[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(repo) {[m | |
[32m+[m[32m GLOBAL.repo = repo;[m | |
[32m+[m | |
[32m+[m[32m return NodeGit.Tag.list(GLOBAL.repo).then(function(array) {[m | |
[32m+[m[32m console.log('all tags!', array);[m | |
[32m+[m[32m var releaseTags = _.filter(array, function(tag) {[m | |
[32m+[m[32m return /^v\d+\.\d+\.\d+$/gi.test(tag);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m console.log('only release tags', releaseTags);[m | |
[32m+[m[32m process.exit(1);[m | |
[32m+[m[32m return NodeGit.Tag.lookupPrefix(GLOBAL.repo, 'v', 1);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m | |
[32m+[m[32m if (!args.releaseName) {[m | |
[32m+[m[32m return GLOBAL.repo.getReferenceNames(NodeGit.Reference.TYPE.LISTALL);[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m return startRelease(args)[m | |
[32m+[m[32m .then(function(/* releaseBranch */) {[m | |
[32m+[m[32m // upload branch to github[m | |
[32m+[m[32m // (either empty or with an empty init commit)[m | |
[32m+[m[32m // console.log(releaseBranch.shorthand()); // => release/my-release[m | |
[32m+[m[32m process.exit(0);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m }[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(allBranches) {[m | |
[32m+[m[32m var regexItem = options.remote ?[m | |
[32m+[m[32m /^refs\/remotes\/.*?\/release\// :[m | |
[32m+[m[32m /^refs\/heads\/release\//;[m | |
[32m+[m | |
[32m+[m[32m allBranches = _.filter(allBranches, function(branch) {[m | |
[32m+[m[32m return regexItem.test(branch); // release\/[m | |
[32m+[m[32m });[m | |
[32m+[m | |
[32m+[m[32m var releaseBranches = _.map(allBranches, function(branch) {[m | |
[32m+[m[32m return branch.replace(regexItem, '');[m | |
[32m+[m[32m });[m | |
[32m+[m | |
[32m+[m[32m GLOBAL.releaseBranches = releaseBranches;[m | |
[32m+[m | |
[32m+[m[32m console.log(kbString.success([[m | |
[32m+[m[32m 'Found ',[m | |
[32m+[m[32m releaseBranches.length, ' ',[m | |
[32m+[m[32m kbString.important(options.remote ? 'remote' : 'local'),[m | |
[32m+[m[32m ' releases:\n',[m | |
[32m+[m[32m '======================'[m | |
[32m+[m[32m ]));[m | |
[32m+[m | |
[32m+[m[32m // todo(thatkookooguy): simplify this![m | |
[32m+[m[32m return Q.all(_.map(allBranches, function(branch) {[m | |
[32m+[m[32m return GLOBAL.repo.getBranchCommit(branch)[m | |
[32m+[m[32m .then(function(result) {[m | |
[32m+[m[32m return result;[m | |
[32m+[m[32m }, function(error) {[m | |
[32m+[m[32m var deferred = Q.defer();[m | |
[32m+[m[32m deferred.resolve(error);[m | |
[32m+[m | |
[32m+[m[32m return deferred.promise;[m | |
[32m+[m[32m });[m | |
[32m+[m[32m }));[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(allLastCommits) {[m | |
[32m+[m[32m _.forEach(allLastCommits, function(commit, index) {[m | |
[32m+[m[32m if (commit.errno) {[m | |
[32m+[m[32m console.log(kbString.build([[m | |
[32m+[m[32m kbString.info([[m | |
[32m+[m[32m '[',[m | |
[32m+[m[32m 'release/',[m | |
[32m+[m[32m GLOBAL.releaseBranches[index],[m | |
[32m+[m[32m ']'[m | |
[32m+[m[32m ]),[m | |
[32m+[m[32m ' ',[m | |
[32m+[m[32m kbString.error('no commits yet...'),[m | |
[32m+[m[32m ' ---ERROR: ', commit.message[m | |
[32m+[m[32m ]));[m | |
[32m+[m[32m return;[m | |
[32m+[m[32m }[m | |
[32m+[m[32m console.log(kbString.build([[m | |
[32m+[m[32m kbString.info('[', 'release/', GLOBAL.releaseBranches[index], ']'),[m | |
[32m+[m[32m ' ',[m | |
[32m+[m[32m kbString.white('(', commit.author(), ')'),[m | |
[32m+[m[32m kbString.error(' > '),[m | |
[32m+[m[32m kbString.success(commit.message().trim().split('\n', 1)[0]),[m | |
[32m+[m[32m kbString.warning(' (', moment(commit.date()).fromNow(), ')')[m | |
[32m+[m[32m ]));[m | |
[32m+[m[32m });[m | |
[32m+[m[32m process.exit(0);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .catch(function(error) {[m | |
[32m+[m[32m console.trace('oops.... something went wrong...', error);[m | |
[32m+[m[32m process.exit(1);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[1mdiff --git a/lib/gitflow/sync.js b/lib/gitflow/sync.js[m | |
[1mnew file mode 100644[m | |
[1mindex 0000000..b70cf8f[m | |
[1m--- /dev/null[m | |
[1m+++ b/lib/gitflow/sync.js[m | |
[36m@@ -0,0 +1,101 @@[m | |
[32m+[m[32mvar GLOBAL = {};[m | |
[32m+[m[32mvar NodeGit = require('nodegit-flow');[m | |
[32m+[m[32mvar gitRoot = require('../kb-git-root');[m | |
[32m+[m[32mvar keytar = require('keytar');[m | |
[32m+[m[32m// var kbString = require('../kb-string');[m | |
[32m+[m | |
[32m+[m[32mvar syncGitflow = {};[m | |
[32m+[m | |
[32m+[m[32msyncGitflow.sync = sync;[m | |
[32m+[m | |
[32m+[m[32mmodule.exports = syncGitflow;[m | |
[32m+[m | |
[32m+[m[32mvar cloneOptions = {[m | |
[32m+[m[32m fetchOpts: {[m | |
[32m+[m[32m callbacks: {[m | |
[32m+[m[32m certificateCheck: function() {[m | |
[32m+[m[32m return 1;[m | |
[32m+[m[32m },[m | |
[32m+[m[32m credentials: function() {[m | |
[32m+[m[32m console.log('asked for credentials', GLOBAL.token);[m | |
[32m+[m[32m return NodeGit.Cred.userpassPlaintextNew(GLOBAL.token, 'x-oauth-basic');[m | |
[32m+[m[32m }[m | |
[32m+[m[32m }[m | |
[32m+[m[32m }[m | |
[32m+[m[32m};[m | |
[32m+[m | |
[32m+[m[32mfunction sync() {[m | |
[32m+[m[32m console.log('get started!');[m | |
[32m+[m[32m gitRoot.getGitRoot()[m | |
[32m+[m[32m .then(function(_gitRoot) {[m | |
[32m+[m[32m console.log('gitRoot passed');[m | |
[32m+[m[32m if (!_gitRoot) {[m | |
[32m+[m[32m console.info('git repo not found');[m | |
[32m+[m[32m process.exit(1);[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m GLOBAL.gitRoot = _gitRoot;[m | |
[32m+[m[32m // open the git repo if it exists[m | |
[32m+[m[32m console.log('opened repo');[m | |
[32m+[m[32m return NodeGit.Repository.open(GLOBAL.gitRoot);[m | |
[32m+[m[32m }[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(repo) {[m | |
[32m+[m[32m GLOBAL.repo = repo;[m | |
[32m+[m[32m console.log('found repo. trying to fetch');[m | |
[32m+[m[32m return NodeGit.Remote.list(GLOBAL.repo);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(remoteList) {[m | |
[32m+[m[32m console.log('here are all the remotes:', remoteList);[m | |
[32m+[m | |
[32m+[m[32m if (!remoteList.length) {[m | |
[32m+[m[32m console.log('no remotes found. need to add one to update');[m | |
[32m+[m[32m process.exit(1);[m | |
[32m+[m[32m }[m | |
[32m+[m | |
[32m+[m[32m return GLOBAL.repo.config()[m | |
[32m+[m[32m .then(function(config) {[m | |
[32m+[m[32m return config.getString('kibibit.user');[m | |
[32m+[m[32m });[m | |
[32m+[m[32m // process.exit(0);[m | |
[32m+[m | |
[32m+[m[32m // return GLOBAL.repo.fetch('origin', cloneOptions.fetchOpts);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(userToUse) {[m | |
[32m+[m[32m GLOBAL.username = userToUse;[m | |
[32m+[m[32m console.log('user to use', GLOBAL.username);[m | |
[32m+[m[32m return keytar.getPassword('kibibit-cli', GLOBAL.username);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(token) {[m | |
[32m+[m[32m GLOBAL.token = token;[m | |
[32m+[m | |
[32m+[m[32m console.log('your token', token);[m | |
[32m+[m[32m return GLOBAL.repo.fetchAll(cloneOptions.fetchOpts);[m | |
[32m+[m[32m process.exit(1);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m[32m return NodeGit.Flow.getConfig(GLOBAL.repo);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function(config) {[m | |
[32m+[m[32m GLOBAL.gitflowConfig = config;[m | |
[32m+[m[32m return GLOBAL.repo.mergeBranches([m | |
[32m+[m[32m GLOBAL.gitflowConfig['gitflow.branch.master'],[m | |
[32m+[m[32m 'origin/' + GLOBAL.gitflowConfig['gitflow.branch.master']);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .then(function() {[m | |
[32m+[m[32m return GLOBAL.repo.mergeBranches([m | |
[32m+[m[32m GLOBAL.gitflowConfig['gitflow.branch.develop'],[m | |
[32m+[m[32m 'origin/' + GLOBAL.gitflowConfig['gitflow.branch.develop']);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m // .done(function() {[m | |
[32m+[m[32m // console.log('all done!');[m | |
[32m+[m[32m // process.exit(0);[m | |
[32m+[m[32m // })[m | |
[32m+[m[32m .then(function(result) {[m | |
[32m+[m[32m console.log('the result?', result);[m | |
[32m+[m[32m process.exit(0);[m | |
[32m+[m[32m })[m | |
[32m+[m[32m .catch(function(error) {[m | |
[32m+[m[32m console.trace(error);[m | |
[32m+[m[32m process.exit(1);[m | |
[32m+[m[32m });[m | |
[32m+[m[32m}[m | |
[1mdiff --git a/lib/gitflow/utility.js b/lib/gitflow/utility.js[m | |
[1mindex e0f4b8c..49fa496 100644[m | |
[1m--- a/lib/gitflow/utility.js[m | |
[1m+++ b/lib/gitflow/utility.js[m | |
[36m@@ -2,6 +2,7 @@[m [mvar kbString = require('../kb-string');[m | |
var _ = require('lodash');[m | |
var Q = require('q');[m | |
var colorize = require('json-colorizer');[m | |
[32m+[m[32mvar github = require('octonode');[m | |
[m | |
var util = {};[m | |
[m | |
[36m@@ -10,9 +11,115 @@[m [mutil.openIndex = openIndex;[m | |
util.writeFilesInIndex = writeFilesInIndex;[m | |
util.writeIndexTree = writeIndexTree;[m | |
util.getRootCommit = getRootCommit;[m | |
[32m+[m[32mutil.getGitHubUserData = getGitHubUserData;[m | |
[32m+[m[32mutil.getOrgs = getOrgs;[m | |
[32m+[m[32mutil.createRepoUser = createRepoUser;[m | |
[32m+[m[32mutil.createRepoOrg = createRepoOrg;[m | |
[32m+[m[32mutil.signingInAnimation = [[m | |
[32m+[m[32m kbString.info(kbString.warning('/'), ' Signing in'),[m | |
[32m+[m[32m kbString.info(kbString.warning('|'), ' Signing in..'),[m | |
[32m+[m[32m kbString.info(kbString.warning('\\'), ' Signing in..'),[m | |
[32m+[m[32m kbString.info(kbString.warning('-'), ' Signing in...')[m | |
[32m+[m[32m];[m | |
[32m+[m[32mutil.signingInSteps = 4;[m | |
[m | |
module.exports = util;[m | |
[m | |
[32m+[m[32mvar client;[m | |
[32m+[m | |
[32m+[m[32mfunction createRepoUser(name, description) {[m | |
[32m+[m[32m var deferred = Q.defer();[m | |
[32m+[m | |
[32m+[m[32m description = description || '';[m | |
[32m+[m | |
[32m+[m[32m if (!name) {[m | |
[32m+[m[32m deferred.reject('name must be given');[m | |
[32m+[m | |
[32m+[m[32m return deferred.promise;[m | |
[32m+[m[32m }[m | |
[32m+[m | |
[32m+[m[32m var ghme = client.me();[m | |
[32m+[m | |
[32m+[m[32m ghme.repo({[m | |
[32m+[m[32m 'name': name,[m | |
[32m+[m[32m 'description': description,[m | |
[32m+[m[32m }, function(err, body) {[m | |
[32m+[m[32m if (err) {[m | |
[32m+[m[32m // console.log('ERROR!', err);[m | |
[32m+[m | |
[32m+[m[32m deferred.reject('can\'t create user repo');[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m deferred.resolve(body);[m | |
[32m+[m[32m }[m | |
[32m+[m[32m }); //repo[m | |
[32m+[m | |
[32m+[m[32m return deferred.promise;[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction createRepoOrg(orgName, name, description) {[m | |
[32m+[m[32m var deferred = Q.defer();[m | |
[32m+[m | |
[32m+[m[32m description = description || '';[m | |
[32m+[m | |
[32m+[m[32m if (!name || !orgName) {[m | |
[32m+[m[32m deferred.reject('orgName & name must be given');[m | |
[32m+[m | |
[32m+[m[32m return deferred.promise;[m | |
[32m+[m[32m }[m | |
[32m+[m | |
[32m+[m[32m var ghorg = client.org(orgName);[m | |
[32m+[m | |
[32m+[m[32m ghorg.repo({[m | |
[32m+[m[32m name: name,[m | |
[32m+[m[32m description: description[m | |
[32m+[m[32m }, function(err, body) {[m | |
[32m+[m[32m if (err) {[m | |
[32m+[m[32m // console.log('ERROR!', err);[m | |
[32m+[m[32m deferred.reject('can\'t create organization repo')[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m deferred.resolve(body);[m | |
[32m+[m[32m }[m | |
[32m+[m[32m });[m | |
[32m+[m | |
[32m+[m[32m return deferred.promise;[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction getOrgs() {[m | |
[32m+[m[32m var deferred = Q.defer();[m | |
[32m+[m | |
[32m+[m[32m var ghme = client.me();[m | |
[32m+[m | |
[32m+[m[32m ghme.orgs(function(err, body) {[m | |
[32m+[m[32m if (err) {[m | |
[32m+[m[32m // console.log('ERROR!', err);[m | |
[32m+[m[32m deferred.reject('can\'t get organizations data from github');[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m deferred.resolve(body);[m | |
[32m+[m[32m }[m | |
[32m+[m[32m });[m | |
[32m+[m | |
[32m+[m[32m return deferred.promise;[m | |
[32m+[m[32m}[m | |
[32m+[m | |
[32m+[m[32mfunction getGitHubUserData(username, token) {[m | |
[32m+[m[32m console.log('trying to login to github', token);[m | |
[32m+[m[32m var deferred = Q.defer();[m | |
[32m+[m | |
[32m+[m[32m client = github.client(token);[m | |
[32m+[m | |
[32m+[m[32m client.get('/user', {}, function (err, status, body) {[m | |
[32m+[m[32m if (err) {[m | |
[32m+[m[32m // console.log('ERROR!', err);[m | |
[32m+[m[32m deferred.reject('can\'t get user data from github');[m | |
[32m+[m[32m } else {[m | |
[32m+[m[32m // console.log(body); //json object[m | |
[32m+[m[32m deferred.resolve(body);[m | |
[32m+[m[32m }[m | |
[32m+[m[32m });[m | |
[32m+[m | |
[32m+[m[32m return deferred.promise;[m | |
[32m+[m[32m}[m | |
[32m+[m | |
function addFilesToIndex(index, filesToCommit) {[m | |
var fName = arguments.callee.toString().match(/function ([^\(]+)/)[1];[m | |
if (!index) { return Q.reject(fName + ' expects an index arg'); }[m | |
[1mdiff --git a/lib/kb-git-root.js b/lib/kb-git-root.js[m | |
[1mindex 6eb81e4..ee5c0b1 100644[m | |
[1m--- a/lib/kb-git-root.js[m | |
[1m+++ b/lib/kb-git-root.js[m | |
[36m@@ -15,11 +15,11 @@[m [mtry {[m | |
var foundRoot = findRoot(currentFolder, function (dir) {[m | |
return fs.existsSync(path.resolve(dir, '.git'));[m | |
});[m | |
[31m-[m | |
[32m+[m[32m // console.log('found git root', foundRoot);[m | |
deferred.resolve(foundRoot);[m | |
} catch (error) {[m | |
[31m- // console.error(error);[m | |
[31m- gitRoot = null;[m | |
[32m+[m[32m // console.error('no git root found');[m | |
[32m+[m[32m // gitRoot = null;[m | |
deferred.resolve(null);[m | |
}[m | |
[m | |
[36m@@ -28,5 +28,6 @@[m [mtry {[m | |
module.exports = kbGitRoot;[m | |
[m | |
function getGitRoot() {[m | |
[32m+[m[32m // console.log('yo');[m | |
return deferred.promise;[m | |
}[m | |
[1mdiff --git a/package.json b/package.json[m | |
[1mindex f93d320..ba49cfa 100644[m | |
[1m--- a/package.json[m | |
[1m+++ b/package.json[m | |
[36m@@ -33,9 +33,11 @@[m | |
"find-root": "^1.1.0",[m | |
"gitlike-cli": "^0.1.0",[m | |
"highlight.js": "^9.12.0",[m | |
[32m+[m[32m "home-config": "^0.1.0",[m | |
"indent-string": "^3.2.0",[m | |
"inquirer": "^4.0.0",[m | |
"json-colorizer": "^1.1.0",[m | |
[32m+[m[32m "keytar": "^4.1.0",[m | |
"lodash": "^4.17.4",[m | |
"marked": "^0.3.7",[m | |
"moment": "^2.19.3",[m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment