Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for using vim instead of rolling my own stdin reader

  • Loading branch information...
commit 47054b52036472d3c44ca768b9c40cb64768611a 1 parent 00a05af
@davglass davglass authored
View
4 configs/pr/default.txt
@@ -0,0 +1,4 @@
+# Add your text below these lines
+# Lines that begin with a # will be ignored
+
+
View
36 lib/cmds/pullrequest.js
@@ -8,6 +8,7 @@ var util = require('../util'),
git = require('../git'),
config = require('../config'),
api = require('../api'),
+ path = require('path'),
request = require('request'),
mods = {
yui: true,
@@ -33,6 +34,10 @@ mods = {
}
var module = util.findModule(true);
this.module = module;
+ console.log(module);
+ if (!module) {
+ log.bail('are you in a module directory?');
+ }
log.info('issuing a pull request to ' + this.user + ' for: ' + module.name);
if (this.simple) {
log.info('simple pull request, using last commit as message');
@@ -47,13 +52,28 @@ mods = {
api.get('/components/' + this.module.name + '/author', function(err, author) {
if (author && author.components && author.components.length) {
- var owner = author.components[0].author;
+ var owner = author.components[0].author,
+ lookup = (Array.isArray(owner)) ? owner : [owner];
+
log.info('found owner: ' + owner);
log.debug('looking up user info');
- api.get('/user/name/' + owner + '/github', function(err, github) {
- if (github && github.github) {
- log.debug('found github username: ' + github.github);
- self.body += '\nyogi pinging ' + self.module.name + ' owner: @' + github.github + '\n';
+
+ api.get('/user/name/' + lookup.join(';') + '/github', function(err, github) {
+ var owners = [];
+ if (github && Array.isArray(github)) {
+ github.forEach(function(i) {
+ if (i.github) {
+ owners.push(i.github);
+ }
+ });
+ } else if (github && github.github) {
+ owners = [github.github];
+ }
+ if (owners.length) {
+ log.debug('found github username(s): ' + owners);
+ owners.forEach(function(name) {
+ self.body += '\nyogi pinging ' + self.module.name + ' owner: @' + name + '\n';
+ });
} else {
log.warn('failed to locate default owner, submitting anyway');
}
@@ -172,8 +192,10 @@ mods = {
});
},
askBody: function() {
- var self = this;
- util.longPrompt('pull request body: (ctrl+C to end)\n', function(ans) {
+ var defaultFile = path.join(__dirname, '../../configs/pr/default.txt'),
+ self = this;
+
+ util.longPrompt(defaultFile, function(ans) {
self.body = ans;
self.confirm();
});
View
49 lib/util.js
@@ -5,9 +5,11 @@ http://yuilibrary.com/license/
*/
var fs = require('fs'),
path = require('path'),
+ osenv = require('osenv'),
log = require('./log'),
exists = fs.existsSync || path.existsSync,
readline = require('readline'),
+ editor = require('editor'),
find = function(dir, file, cb) {
if (dir === '/') {
cb(true);
@@ -162,29 +164,38 @@ mods = {
cb(answer);
});
},
- longPrompt: function(str, cb) {
- if (!rl) {
- rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
+ createTmp: function(file, cb) {
+ var fileName = path.basename(file),
+ stamp = (new Date()).getTime(),
+ tmpFile = path.join(osenv.tmpdir(), fileName + '.yogi-tmp-' + stamp),
+ newFile = fs.createWriteStream(tmpFile),
+ oldFile = fs.createReadStream(file);
+
+ oldFile.pipe(newFile);
- }
- var answer = [];
- process.stdout.write(str);
- rl.on('line', function(line) {
- answer.push(line);
+ oldFile.on('close', function() {
+ cb(tmpFile);
});
- rl.on('SIGINT', function() {
- rl.question('Are you sure? [y/n] ', function(ans) {
- if (ans.match(/^y(es)?$/i)) {
- rl.pause();
- cb(answer.join('\n'));
- }
+
+
+ },
+ longPrompt: function(file, cb) {
+ var self = this;
+ self.createTmp(file, function(fileName) {
+ log.info('opening ' + fileName + ' for editing.');
+ editor(fileName, function(code) {
+ log.debug('editor exited with code ' + code);
+ var data = fs.readFileSync(fileName, 'utf8'),
+ str = [];
+ data = data.split('\n');
+ data.forEach(function(line) {
+ if (line.indexOf('#') === -1) {
+ str.push(line);
+ }
+ });
+ cb(str.join('\n'));
});
});
-
- rl.resume();
}
};
View
3  package.json
@@ -20,7 +20,8 @@
"rimraf": "*",
"nopt": "1",
"mkdirp": "~0.3.3",
- "osenv": "*"
+ "osenv": "*",
+ "editor": "https://github.com/dominictarr/node-editor/tarball/master"
},
"scripts": {
"pretest": "./node_modules/.bin/jslint --white --sloppy --node --stupid --nomen --plusplus ./lib/*.js ./lib/*/*.js",

0 comments on commit 47054b5

Please sign in to comment.
Something went wrong with that request. Please try again.