Skip to content

Commit

Permalink
lots of bug fixes - properly using config now, cli still has problems
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Jul 12, 2013
1 parent a9d864f commit 6b2662d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 40 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Tool to create a remote github repository and add and push content to it.
```js
var gitify = require('gitify');

// change username and password to match your github account to see it in action
// change user and password to match your github account to see it in action
gitify(
{ username: 'joe'
, password: 'secret'
, reponame: 'foo' // if no reponame is given, the current folder name is used
{ user : 'joe'
, password : 'secret'
, repo : 'foo' // if no repo is given, the current folder name is used
}
, function (err) {
if (err) return console.error('err: ', err);
Expand All @@ -27,14 +27,17 @@ gitify(
###*gitify(opts : Object, cb : Function)*

- opts are optional and specify
- username: github username
- password: github password
- reponame: name under which the repo should be published on github
- description: description of the repository
- user\* : github user
- password\* : github password
- repo : name under which the repo should be published on github (defaults to current dir name)
- description : description of the repository (default empty)

**\*** if user and/or password are not supplied, they will be obtained by prompting the user on the first gitify run and
saved into a config at: `~/.config/gitify.js` for future runs

## Commandline

gitify [<reponame> <username> <password>]
gitify [<repo> <user> <password>]

## License

Expand Down
28 changes: 17 additions & 11 deletions bin/gitify.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#! /usr/bin/env node
#!/usr/bin/env node

var gitify = require('..')
, argv = process.argv;

var reponame = argv[2]
, password = argv[3]
, username = argv[4];
var repo = argv[2]
, password = argv[3]
, user = argv[4];

gitify({
username: username
, password: password
, reponame: reponame }
gitify(
{ user : user
, password : password
, repo : repo
}
, function (err) {
if (err) return console.error(err);
console.log('The current directory was successfully gitified.');
});
if (err) {
console.error(err);
if (err.err && err.err.errors) console.error(err.err.errors);
return;
}
console.log('The current directory was successfully gitified.');
}
);
8 changes: 4 additions & 4 deletions example/create-foo-for-joe.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

var gitify = require('..');

// change username and password to match your github account to see it in action
// change user and password to match your github account to see it in action
gitify(
{ username: 'joe'
, password: 'secret'
, reponame: 'foo' // if no reponame is given, the current folder name is used
{ user : 'joe'
, password : 'secret'
, repo : 'foo' // if no repo is given, the current folder name is used
}
, function (err) {
if (err) return console.error('err: ', err);
Expand Down
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
var createRepo = require('./lib/create-repo')
, initRepo = require('./lib/init-repo')
, credentials = require('./lib/credentials')
, reponame = require('./lib/reponame');
, getRepo = require('./lib/repo');


var gitify = module.exports = function (opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
var reponame = opts.reponame || reponame()
var repo = opts.repo || getRepo()

credentials(function (err, creds) {
if (err) return cb(err);
createRepo(
creds.uname
, creds.pwd
, reponame
creds.user
, creds.password
, repo
, opts.description || ''
, oncreated
);

function oncreated (err) {
if (err) return cb(err);
initRepo(creds.uname, reponame, cb);
initRepo(creds.user, repo, cb);
}
});

};
8 changes: 4 additions & 4 deletions lib/create-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
var request = require('request')
, uris = require('./uris');

var create = module.exports = function (uname, pwd, reponame, repodesc, cb) {
var create = module.exports = function (user, password, repo, repodesc, cb) {
var body = {
name : reponame
name : repo
, description : repodesc
, homepage : 'https://github.com'
, private : false
Expand All @@ -15,7 +15,7 @@ var create = module.exports = function (uname, pwd, reponame, repodesc, cb) {
};

var opts = {
uri : uris.create(uname, pwd)
uri : uris.create(user, password)
, json : true
, body : body
, headers : { 'user-agent': 'gitify' }
Expand All @@ -25,6 +25,6 @@ var create = module.exports = function (uname, pwd, reponame, repodesc, cb) {
if (err) return cb(err);
if (!/^2\d\d$/.test(res.statusCode)) return cb({ err: body, statusCode: res.statusCode });

cb(null, { message: reponame + ' for user ' + uname + ' successfully created' });
cb(null, { message: repo + ' for user ' + user + ' successfully created' });
});
};
13 changes: 8 additions & 5 deletions lib/init-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@ var spawn = require('child_process').spawn

function gitrun (cmds, cb) {
var git = spawn('git', cmds)
var errMsg = '';

git.stdout.on('data', function (d) {
console.log(d.toString());
});

git.stderr.on('data', function (d) { errMsg += d; })
git.stderr.on('data', function (d) {
// The following logs on stderr which is not indicating an error, so just log it
// To git@github.com:thlorenz/test-gitify.git
// d9ad070..4f8ebfd master -> master
console.error(d.toString());
});

git.on('close', function (code) {
if (errMsg) return cb(new Error(errMsg));
if (code !== 0) cb(new Error('git ' + cmds.join(' ') + ' returned with code ' + code));
cb();
});
}

var initRepo = module.exports = function (uname, reponame, cb) {
var initRepo = module.exports = function (user, repo, cb) {
runnel(
gitrun.bind(0, ['init'])
, gitrun.bind(0, ['add', '.'])
, gitrun.bind(0, ['commit','-m', '"initial repository"' ])
, gitrun.bind(0, ['remote', 'add', 'origin', 'git@github.com:' + uname + '/' + reponame + '.git' ])
, gitrun.bind(0, ['remote', 'add', 'origin', 'git@github.com:' + user + '/' + repo + '.git' ])
, gitrun.bind(0, ['push', 'origin', 'master' ])
, cb
);
Expand Down
File renamed without changes.

0 comments on commit 6b2662d

Please sign in to comment.