Skip to content

Instantly share code, notes, and snippets.

@thatkookooguy
Last active December 25, 2017 14:35
Show Gist options
  • Save thatkookooguy/fbaa9adf1ffe14f14186e8ba1b5b979c to your computer and use it in GitHub Desktop.
Save thatkookooguy/fbaa9adf1ffe14f14186e8ba1b5b979c to your computer and use it in GitHub Desktop.
diff2html-cli example file that gives 0 file changes
diff --git a/lib/commandDefinitions.js b/lib/commandDefinitions.js
index f1809d7..e5b9e1d 100644
--- a/lib/commandDefinitions.js
+++ b/lib/commandDefinitions.js
@@ -4,8 +4,10 @@ var statusGitflow = require('./gitflow/status');
var commitGitflow = require('./gitflow/commit');
var finishGitflow = require('./gitflow/finish');
var featureGitflow = require('./gitflow/feature');
+var releaseGitflow = require('./gitflow/release');
var hotfixGitflow = require('./gitflow/hotfix');
var developGitflow = require('./gitflow/develop');
+var syncGitflow = require('./gitflow/sync');
var masterGitflow = require('./gitflow/master');
// var inquirer = require('inquirer');
var shell = require('shelljs');
@@ -251,7 +253,7 @@ function addSubCommandFinish(program) {

function addSubCommandRelease(program) {
program
- .command('release <action>')
+ .command('release [releaseName]')
.description(kbString.build(
kbString.info(
'When you have enough completed features in origin/develop, '
@@ -259,7 +261,7 @@ function addSubCommandRelease(program) {
kbString.info('create a release branch, test it and fix it, '),
kbString.info('and then merge it into origin/master')
))
- .action(release)
+ .action(releaseGitflow.release)
.on('help', function(cmd) {
cmd.outputIndented('Examples', [
kbString.build(
@@ -285,7 +287,7 @@ function addSubCommandUpdate(program) {
.description(
kbString.info('keep up-to-date with completed features on GitHub')
)
- .action(update)
+ .action(syncGitflow.sync)
.on('help', function(cmd) {
cmd.outputIndented('Examples', [
kbString.build(
@@ -360,27 +362,13 @@ function clone() {
console.error('clone!');
}

-function release(args) {
- if (['start', 'finish'].indexOf(args.action) < 0) {
- console.error(ohNo([
- '[ERROR]: ',
- kbString.kibibitLogo(),
- kbString.kbString.success(' release '),
- 'expects either start or finish'
- ]));
- process.exit(1);
- }
-
- kbExec('git hf release ' + args.action);
-}
-
function push() {
kbExec('git hf push');
}

-function update() {
- kbExec('git hf update');
-}
+// function update() {
+// kbExec('git hf update');
+// }

function kbExec(command) {
if (shell.exec(command).code !== 0) {
diff --git a/lib/gitflow/init.js b/lib/gitflow/init.js
index 04bd3f3..e388e35 100644
--- a/lib/gitflow/init.js
+++ b/lib/gitflow/init.js
@@ -1,5 +1,5 @@
var os = require('os');
-var path = require('path');
+// var path = require('path');
var kbString = require('../kb-string');
var gitRoot = require('../kb-git-root');
var inquirer = require('inquirer');
@@ -9,6 +9,9 @@ var Q = require('q');
var colorize = require('json-colorizer');
var currentFolder = process.cwd();
var NodeGit = require('nodegit-flow');
+var keytar = require('keytar');
+var globalCfg = require('home-config').load('.kibibit-bit');
+var utility = require('./utility');
// var findRoot = require('find-root');

var GLOBAL = {
@@ -19,15 +22,6 @@ var GLOBAL = {

var ui = new inquirer.ui.BottomBar();

-var signingIn = [
- kbString.info(kbString.warning('/'), ' Signing in'),
- kbString.info(kbString.warning('|'), ' Signing in..'),
- kbString.info(kbString.warning('\\'), ' Signing in..'),
- kbString.info(kbString.warning('-'), ' Signing in...')
-];
-var signingInSteps = 4;
-// var client = github.client();
-
var initGitflow = {};

initGitflow.init = init;
@@ -36,12 +30,6 @@ initGitflow.hotfixBranchesPrefixDefault = hotfixBranchesPrefixDefault;
initGitflow.releaseBranchesPrefixDefault = releaseBranchesPrefixDefault;

initGitflow.questions = [
- // shouldInitRepo(),
- // shouldCopyGlobalSettings(),
- //askForGitHubUser(),
- //askForGitHubPassword(),
- //askForOTPCode(GLOBAL),
- // askIfRebaseOrMerge(),
askNameOfMasterBranch(),
askNameOfDevelopBranch(),
askPrefixOfFeatureBranches(),
@@ -82,46 +70,95 @@ function makeInitialCommit(branch) {
};
}

-function init(args, options) {
- console.log('starting');
- gitRoot.getGitRoot()
- .then(function(gitRoot) {
- console.log('this is git root', gitRoot);
- if (!gitRoot) {
- console.info(kbString.error('git repo not found'));
- console.log('initializing...');
- // initialize a git repo in this folder if it doesn't exist
- return NodeGit.Repository.init(currentFolder, 0);
- } else {
- // open the git repo if it exists
- return NodeGit.Repository.open(gitRoot);
- }
- })
+function ensureGitInitialized(gitRoot) {
+ if (!gitRoot) {
+ console.info(kbString.error('git repo not found'));
+ console.log('initializing...');
+ }
+
+ // initialize a git repo in this folder if it doesn't exist
+ // open the git repo if it exists
+ var action = gitRoot ?
+ NodeGit.Repository.open(gitRoot) :
+ NodeGit.Repository.init(currentFolder, 0);
+
+ return action
.then(function(repo) {
- // now we def have a repo.
GLOBAL.repo = repo;
- console.log('we have a repo');
- // is it a git flow repo?
- return NodeGit.Flow.isInitialized(GLOBAL.repo);
- })
+
+ return repo;
+ });
+}
+
+function ensureGitFlowNotInitialized() {
+ return NodeGit.Flow.isInitialized(GLOBAL.repo)
.then(function(isInit) {
GLOBAL.isGitflow = isInit;

- if (isInit) {
- console.log('repo is already a git flow repo');
+ if (GLOBAL.isGitflow) {
+ console.log(kbString.error('repo is already a git flow repo'));
process.exit(1);
}

+ return;
+ });
+}
+
+function init(args, options) {
+ gitRoot.getGitRoot()
+ .then(ensureGitInitialized)
+ .then(ensureGitFlowNotInitialized)
+ // TODO(thatkookooguy): add a step to check remote repo
+ // if exists already.
+ .then(function() {
// now we know we have a git repo that is not a git flow repo
// ask the user what he wants to do
printFlash();
// for now, this does nothing...
if (options.force) {
console.log(kbString.warning('WARNING: force detected'));
- // process.exit(0);
+ process.exit(1);
}

- return inquirer.prompt(initGitflow.questions);
+ return associateUser();
+ })
+ .then(function() {
+ console.log('user associated');
+ return utility.getGitHubUserData(GLOBAL.username, GLOBAL.token);
+ })
+ .then(function(githubUser) {
+ // console.log('github user', githubUser);
+ console.log('github user email', githubUser.email);
+ console.log('github user username', githubUser.login);
+
+ return utility.getOrgs();
+ })
+ .then(function(orgs) {
+ var orgNames = _.map(orgs, function(org) {
+ return org.login;
+ });
+ GLOBAL.orgs = orgNames;
+ console.log('user organizations', orgNames);
+ // process.exit(0);
+ // TODO(thatkookooguy): need to add a few questions
+ // - check if any users registered with bit in keychain in GLOBAL setting:
+ // - select an existing user or create a user
+ // - store new user token in keychain if created
+ // - create a remote repo (clone will connect to existing one)
+ // - name of repository?
+ // - create it for user or organization a user is a member of?
+ // - should include a readme.md?
+ // - add global git flow config file called .bit.json
+ // it will hold names of branches and prefixes
+ // (later, if bit will be used in a repo with that file,
+ // it will init automatically with that config if not initialized)
+ return inquirer.prompt([
+ askNameOfMasterBranch(),
+ askNameOfDevelopBranch(),
+ askPrefixOfFeatureBranches(),
+ askPrefixOfHotfixBranches(),
+ askPrefixOfReleaseBranches()
+ ]);
})
.then(function(answers) {
delete answers.GitHubPassword;
@@ -194,7 +231,8 @@ function init(args, options) {
})
.then(function() {
console.log('git flow repo initialized');
- process.exit(0);
+ return createOrigin();
+ //process.exit(0);
})
.catch(function(error) {
console.error('something went wrong: ', error);
@@ -202,6 +240,166 @@ function init(args, options) {
});
}

+function createOrigin() {
+ return inquirer.prompt([{
+ type: 'list',
+ name: 'whereToCreate',
+ message: 'Where should repo be created?',
+ choices: [
+ GLOBAL.username,
+ new inquirer.Separator()
+ ].concat(GLOBAL.orgs)
+ },
+ {
+ type: 'input',
+ name: 'repoName',
+ message: 'what do you want to name the repo?',
+ },
+ {
+ type: 'input',
+ name: 'repoDescription',
+ message: 'give the repo a short description (optional)',
+ }])
+ .then(function(answers) {
+ console.log('answers', answers);
+
+ GLOBAL.repoName = answers.repoName;
+ GLOBAL.repoDescription = answers.repoDescription;
+
+ if (answers.whereToCreate === GLOBAL.username) {
+ return utility.createRepoUser(GLOBAL.repoName, GLOBAL.repoDescription);
+ } else {
+ console.log('ORGANIZATION REPOOOOO!!!');
+ return utility.createRepoOrg(answers.whereToCreate,
+ GLOBAL.repoName, GLOBAL.repoDescription);
+ //process.exit(1);
+ }
+ })
+ .then(function(body) {
+ console.log('created repo', body.clone_url);
+
+ // OR ORIGIN!!!!!! INSTEAD OF NAME
+ return NodeGit.Remote
+ .create(GLOBAL.repo, 'origin', body.clone_url);
+ })
+ .then(function(remote) {
+ GLOBAL.remote = remote;
+ console.log('successfully added a new remote!', GLOBAL.remote.name());
+
+ return NodeGit.Flow.getConfig(GLOBAL.repo);
+ })
+ .then(function(config) {
+ return GLOBAL.remote.push([
+ 'refs/heads/master:refs/heads/master'
+ ], {
+ callbacks: {
+ certificateCheck: function() {
+ return 1;
+ },
+ credentials: function() {
+ console.log('asked for credentials', GLOBAL.token);
+ return NodeGit.Cred
+ .userpassPlaintextNew(GLOBAL.token, 'x-oauth-basic');
+ }
+ }
+ });
+ });
+}
+
+function selectExistingUser() {
+ return inquirer.prompt([ {
+ type: 'list',
+ name: 'selectUser',
+ message: 'Found registered users. Select a user for this repo',
+ choices: globalCfg.users.concat([
+ new inquirer.Separator(),
+ 'Add a new user'
+ ])
+ } ])
+ .then(function(answers) {
+ if (globalCfg.users.indexOf(answers.selectUser) > -1) {
+ console.log('existing user selected');
+
+ GLOBAL.username = answers.selectUser;
+
+ console.log('global username', GLOBAL.username);
+
+ return GLOBAL.repo.config()
+ .then(function(config) {
+ return config.setString('kibibit.user', GLOBAL.username);
+ })
+ .then(function() {
+ return keytar.getPassword('kibibit-cli', GLOBAL.username);
+ })
+ .then(function(value) {
+ console.log('got token from keychain', value);
+
+ GLOBAL.token = value;
+ // process.exit(0);
+ return;
+ });
+ } else {
+ console.log('create a new user');
+
+ return loginNewUser();
+ }
+ });
+}
+
+function loginNewUser() {
+ return inquirer.prompt([
+ askForGitHubUser(),
+ askForGitHubPassword(),
+ askForOTPCode(GLOBAL)
+ ])
+ .then(function(answers) {
+ console.log('user logged in', answers);
+ //save token in keychain
+ globalCfg.users.push(answers.GitHubUsername);
+
+ GLOBAL.username = answers.GitHubUsername;
+
+ globalCfg.save();
+
+ return keytar
+ .setPassword('kibibit-cli', answers.GitHubUsername, GLOBAL.token);
+ })
+ .then(function() {
+ console.log('wrote token to keychain');
+
+ return GLOBAL.repo.config()
+ .then(function(config) {
+ return config.setString('user.name', GLOBAL.username);
+ });
+ })
+ .then(function() {
+ return keytar.getPassword('kibibit-cli', GLOBAL.username);
+ })
+ .then(function(cred) {
+ console.log('all kibibit-cli creds: ', cred);
+ GLOBAL.token = cred;
+ return utility.getGitHubUserData(GLOBAL.username, GLOBAL.token);
+ // process.exit(0);
+ })
+ .then(function(githubUser) {
+ return config.setString('user.email', githubUser.email);
+ });
+}
+
+function associateUser() {
+ if (globalCfg.users && globalCfg.users.length > 0) {
+ console.log('found users');
+
+ return selectExistingUser();
+ } else {
+ console.log('no registered users found');
+
+ globalCfg.users = [];
+
+ return loginNewUser();
+ }
+}
+
function ensureSlash(prefix) {
return _.endsWith(prefix, '/') ? prefix : prefix + '/';
}
@@ -311,9 +509,6 @@ function askForGitHubUser() {

function askForGitHubPassword() {
return {
- when: function(userAnswers) {
- return !userAnswers.takeGlobalGitHubUser;
- },
type: 'password',
name: 'GitHubPassword',
message: 'GitHub password:',
@@ -456,16 +651,14 @@ function loginGitHub(username, password, otpCode) {

var loaderId = setInterval(function() {
if (loaderId) {
- ui.updateBottomBar(signingIn[signingInSteps++ % 4]);
+ ui.updateBottomBar(util.signingInAnimation[util.signingInSteps++ % 4]);
}
}, 300);

var scopes = {
- 'add_scopes': ['user', 'repo', 'gist'],
+ 'scopes': ['user', 'repo', 'gist', 'read:org'],
'note': [
- 'kibibit cli', ' - ', path.basename(gitRoot), ' - ',
- os.userInfo().username,
- '@',
+ 'kibibit cli','@',
os.hostname(),
' on ', os.type()
].join('')
@@ -515,7 +708,7 @@ function loginGitHub(username, password, otpCode) {
return deferred.promise;
}

-function checkRepoStatus(repo) {
+function checkRepoStatus() {
NodeGit.Flow.isInitialized(GLOBAL.repo)
.then(function(isInit) {
GLOBAL.isGitflow = isInit;
diff --git a/lib/gitflow/release.js b/lib/gitflow/release.js
new file mode 100644
index 0000000..f55d50a
--- /dev/null
+++ b/lib/gitflow/release.js
@@ -0,0 +1,154 @@
+var kbString = require('../kb-string');
+var _ = require('lodash');
+var Q = require('q');
+var NodeGit = require('nodegit-flow');
+var moment = require('moment');
+var gitRoot = require('../kb-git-root');
+
+var GLOBAL = {
+ repo: null,
+ releaseBranches: null
+};
+
+var releaseGitflow = {};
+
+releaseGitflow.release = release;
+
+module.exports = releaseGitflow;
+
+function startRelease(args) {
+ return NodeGit.Flow.startRelease(
+ GLOBAL.repo,
+ args.releaseName
+ )
+ .then(function(branch) {
+ console
+ .log('creating release named', args.releaseName);
+ return branch;
+ })
+ .catch(function(/*error*/) {
+ // console.trace(error);
+ return NodeGit.Flow.getConfig(GLOBAL.repo)
+ .then(function(config) {
+ // console.log(config);
+ GLOBAL.currReleaseBranch =
+ config['gitflow.prefix.release'] + args.releaseName;
+ console
+ .log('checking out existing release ', GLOBAL.currReleaseBranch);
+ return GLOBAL.repo.checkoutBranch(GLOBAL.currReleaseBranch);
+ // process.exit(1);
+ })
+ .then(function() {
+ return GLOBAL.repo.getBranch(GLOBAL.currReleaseBranch);
+ });
+ });
+}
+
+function release(args, options) {
+
+ gitRoot.getGitRoot()
+ .then(function(_gitRoot) {
+ if (!_gitRoot) {
+ console.info(kbString.error('git repo not found'));
+ process.exit(1);
+ } else {
+ GLOBAL.gitRoot = _gitRoot;
+ // open the git repo if it exists
+ return NodeGit.Repository.open(GLOBAL.gitRoot);
+ }
+ })
+ .then(function(repo) {
+ GLOBAL.repo = repo;
+
+ return NodeGit.Tag.list(GLOBAL.repo).then(function(array) {
+ console.log('all tags!', array);
+ var releaseTags = _.filter(array, function(tag) {
+ return /^v\d+\.\d+\.\d+$/gi.test(tag);
+ });
+ console.log('only release tags', releaseTags);
+ process.exit(1);
+ return NodeGit.Tag.lookupPrefix(GLOBAL.repo, 'v', 1);
+ });
+ })
+ .then(function() {
+
+ if (!args.releaseName) {
+ return GLOBAL.repo.getReferenceNames(NodeGit.Reference.TYPE.LISTALL);
+ } else {
+ return startRelease(args)
+ .then(function(/* releaseBranch */) {
+ // upload branch to github
+ // (either empty or with an empty init commit)
+ // console.log(releaseBranch.shorthand()); // => release/my-release
+ process.exit(0);
+ });
+ }
+ })
+ .then(function(allBranches) {
+ var regexItem = options.remote ?
+ /^refs\/remotes\/.*?\/release\// :
+ /^refs\/heads\/release\//;
+
+ allBranches = _.filter(allBranches, function(branch) {
+ return regexItem.test(branch); // release\/
+ });
+
+ var releaseBranches = _.map(allBranches, function(branch) {
+ return branch.replace(regexItem, '');
+ });
+
+ GLOBAL.releaseBranches = releaseBranches;
+
+ console.log(kbString.success([
+ 'Found ',
+ releaseBranches.length, ' ',
+ kbString.important(options.remote ? 'remote' : 'local'),
+ ' releases:\n',
+ '======================'
+ ]));
+
+ // todo(thatkookooguy): simplify this!
+ return Q.all(_.map(allBranches, function(branch) {
+ return GLOBAL.repo.getBranchCommit(branch)
+ .then(function(result) {
+ return result;
+ }, function(error) {
+ var deferred = Q.defer();
+ deferred.resolve(error);
+
+ return deferred.promise;
+ });
+ }));
+ })
+ .then(function(allLastCommits) {
+ _.forEach(allLastCommits, function(commit, index) {
+ if (commit.errno) {
+ console.log(kbString.build([
+ kbString.info([
+ '[',
+ 'release/',
+ GLOBAL.releaseBranches[index],
+ ']'
+ ]),
+ ' ',
+ kbString.error('no commits yet...'),
+ ' ---ERROR: ', commit.message
+ ]));
+ return;
+ }
+ console.log(kbString.build([
+ kbString.info('[', 'release/', GLOBAL.releaseBranches[index], ']'),
+ ' ',
+ kbString.white('(', commit.author(), ')'),
+ kbString.error(' > '),
+ kbString.success(commit.message().trim().split('\n', 1)[0]),
+ kbString.warning(' (', moment(commit.date()).fromNow(), ')')
+ ]));
+ });
+ process.exit(0);
+ })
+ .catch(function(error) {
+ console.trace('oops.... something went wrong...', error);
+ process.exit(1);
+ });
+}
diff --git a/lib/gitflow/sync.js b/lib/gitflow/sync.js
new file mode 100644
index 0000000..b70cf8f
--- /dev/null
+++ b/lib/gitflow/sync.js
@@ -0,0 +1,101 @@
+var GLOBAL = {};
+var NodeGit = require('nodegit-flow');
+var gitRoot = require('../kb-git-root');
+var keytar = require('keytar');
+// var kbString = require('../kb-string');
+
+var syncGitflow = {};
+
+syncGitflow.sync = sync;
+
+module.exports = syncGitflow;
+
+var cloneOptions = {
+ fetchOpts: {
+ callbacks: {
+ certificateCheck: function() {
+ return 1;
+ },
+ credentials: function() {
+ console.log('asked for credentials', GLOBAL.token);
+ return NodeGit.Cred.userpassPlaintextNew(GLOBAL.token, 'x-oauth-basic');
+ }
+ }
+ }
+};
+
+function sync() {
+ console.log('get started!');
+ gitRoot.getGitRoot()
+ .then(function(_gitRoot) {
+ console.log('gitRoot passed');
+ if (!_gitRoot) {
+ console.info('git repo not found');
+ process.exit(1);
+ } else {
+ GLOBAL.gitRoot = _gitRoot;
+ // open the git repo if it exists
+ console.log('opened repo');
+ return NodeGit.Repository.open(GLOBAL.gitRoot);
+ }
+ })
+ .then(function(repo) {
+ GLOBAL.repo = repo;
+ console.log('found repo. trying to fetch');
+ return NodeGit.Remote.list(GLOBAL.repo);
+ })
+ .then(function(remoteList) {
+ console.log('here are all the remotes:', remoteList);
+
+ if (!remoteList.length) {
+ console.log('no remotes found. need to add one to update');
+ process.exit(1);
+ }
+
+ return GLOBAL.repo.config()
+ .then(function(config) {
+ return config.getString('kibibit.user');
+ });
+ // process.exit(0);
+
+ // return GLOBAL.repo.fetch('origin', cloneOptions.fetchOpts);
+ })
+ .then(function(userToUse) {
+ GLOBAL.username = userToUse;
+ console.log('user to use', GLOBAL.username);
+ return keytar.getPassword('kibibit-cli', GLOBAL.username);
+ })
+ .then(function(token) {
+ GLOBAL.token = token;
+
+ console.log('your token', token);
+ return GLOBAL.repo.fetchAll(cloneOptions.fetchOpts);
+ process.exit(1);
+ })
+ .then(function() {
+ return NodeGit.Flow.getConfig(GLOBAL.repo);
+ })
+ .then(function(config) {
+ GLOBAL.gitflowConfig = config;
+ return GLOBAL.repo.mergeBranches(
+ GLOBAL.gitflowConfig['gitflow.branch.master'],
+ 'origin/' + GLOBAL.gitflowConfig['gitflow.branch.master']);
+ })
+ .then(function() {
+ return GLOBAL.repo.mergeBranches(
+ GLOBAL.gitflowConfig['gitflow.branch.develop'],
+ 'origin/' + GLOBAL.gitflowConfig['gitflow.branch.develop']);
+ })
+ // .done(function() {
+ // console.log('all done!');
+ // process.exit(0);
+ // })
+ .then(function(result) {
+ console.log('the result?', result);
+ process.exit(0);
+ })
+ .catch(function(error) {
+ console.trace(error);
+ process.exit(1);
+ });
+}
diff --git a/lib/gitflow/utility.js b/lib/gitflow/utility.js
index e0f4b8c..49fa496 100644
--- a/lib/gitflow/utility.js
+++ b/lib/gitflow/utility.js
@@ -2,6 +2,7 @@ var kbString = require('../kb-string');
var _ = require('lodash');
var Q = require('q');
var colorize = require('json-colorizer');
+var github = require('octonode');

var util = {};

@@ -10,9 +11,115 @@ util.openIndex = openIndex;
util.writeFilesInIndex = writeFilesInIndex;
util.writeIndexTree = writeIndexTree;
util.getRootCommit = getRootCommit;
+util.getGitHubUserData = getGitHubUserData;
+util.getOrgs = getOrgs;
+util.createRepoUser = createRepoUser;
+util.createRepoOrg = createRepoOrg;
+util.signingInAnimation = [
+ kbString.info(kbString.warning('/'), ' Signing in'),
+ kbString.info(kbString.warning('|'), ' Signing in..'),
+ kbString.info(kbString.warning('\\'), ' Signing in..'),
+ kbString.info(kbString.warning('-'), ' Signing in...')
+];
+util.signingInSteps = 4;

module.exports = util;

+var client;
+
+function createRepoUser(name, description) {
+ var deferred = Q.defer();
+
+ description = description || '';
+
+ if (!name) {
+ deferred.reject('name must be given');
+
+ return deferred.promise;
+ }
+
+ var ghme = client.me();
+
+ ghme.repo({
+ 'name': name,
+ 'description': description,
+ }, function(err, body) {
+ if (err) {
+ // console.log('ERROR!', err);
+
+ deferred.reject('can\'t create user repo');
+ } else {
+ deferred.resolve(body);
+ }
+ }); //repo
+
+ return deferred.promise;
+}
+
+function createRepoOrg(orgName, name, description) {
+ var deferred = Q.defer();
+
+ description = description || '';
+
+ if (!name || !orgName) {
+ deferred.reject('orgName & name must be given');
+
+ return deferred.promise;
+ }
+
+ var ghorg = client.org(orgName);
+
+ ghorg.repo({
+ name: name,
+ description: description
+ }, function(err, body) {
+ if (err) {
+ // console.log('ERROR!', err);
+ deferred.reject('can\'t create organization repo')
+ } else {
+ deferred.resolve(body);
+ }
+ });
+
+ return deferred.promise;
+}
+
+function getOrgs() {
+ var deferred = Q.defer();
+
+ var ghme = client.me();
+
+ ghme.orgs(function(err, body) {
+ if (err) {
+ // console.log('ERROR!', err);
+ deferred.reject('can\'t get organizations data from github');
+ } else {
+ deferred.resolve(body);
+ }
+ });
+
+ return deferred.promise;
+}
+
+function getGitHubUserData(username, token) {
+ console.log('trying to login to github', token);
+ var deferred = Q.defer();
+
+ client = github.client(token);
+
+ client.get('/user', {}, function (err, status, body) {
+ if (err) {
+ // console.log('ERROR!', err);
+ deferred.reject('can\'t get user data from github');
+ } else {
+ // console.log(body); //json object
+ deferred.resolve(body);
+ }
+ });
+
+ return deferred.promise;
+}
+
function addFilesToIndex(index, filesToCommit) {
var fName = arguments.callee.toString().match(/function ([^\(]+)/)[1];
if (!index) { return Q.reject(fName + ' expects an index arg'); }
diff --git a/lib/kb-git-root.js b/lib/kb-git-root.js
index 6eb81e4..ee5c0b1 100644
--- a/lib/kb-git-root.js
+++ b/lib/kb-git-root.js
@@ -15,11 +15,11 @@ try {
var foundRoot = findRoot(currentFolder, function (dir) {
return fs.existsSync(path.resolve(dir, '.git'));
});
-
+ // console.log('found git root', foundRoot);
deferred.resolve(foundRoot);
} catch (error) {
- // console.error(error);
- gitRoot = null;
+ // console.error('no git root found');
+ // gitRoot = null;
deferred.resolve(null);
}

@@ -28,5 +28,6 @@ try {
module.exports = kbGitRoot;

function getGitRoot() {
+ // console.log('yo');
return deferred.promise;
}
diff --git a/package.json b/package.json
index f93d320..ba49cfa 100644
--- a/package.json
+++ b/package.json
@@ -33,9 +33,11 @@
"find-root": "^1.1.0",
"gitlike-cli": "^0.1.0",
"highlight.js": "^9.12.0",
+ "home-config": "^0.1.0",
"indent-string": "^3.2.0",
"inquirer": "^4.0.0",
"json-colorizer": "^1.1.0",
+ "keytar": "^4.1.0",
"lodash": "^4.17.4",
"marked": "^0.3.7",
"moment": "^2.19.3",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment