Skip to content

Commit

Permalink
Fixes #26 - fetch commits from github instead of the local repo for a…
Browse files Browse the repository at this point in the history
… cdn request
  • Loading branch information
davglass committed Dec 4, 2012
1 parent 850c9f6 commit 2edc077
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var nopt = require('nopt'),
known = {
watch: Boolean,
quiet: Boolean,
local: Boolean,
t: Number,
c: Number,
x: Array,
Expand Down
10 changes: 8 additions & 2 deletions lib/cmds/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ mods = {
if (status && status.length && !self.force) {
log.bail('git root is dirty, please commit first or use --force');
}
git.log(function(logs) {
var cmd = 'ghlog';
if (self.options.parsed.local) {
cmd = 'log';
}
git[cmd](function(logs) {
log.info('found the following commits:');
logs.forEach(function(item) {
log.log(' ' + item.sha.substr(0, 8) + ' ' +item.note);
Expand Down Expand Up @@ -316,7 +320,9 @@ mods = {
'waiting - list all modules in the cdn pending queue',
'queue - list all modules in the cdn queue',
'logs - list cdn logs for buildtag (latest is default, --buildtag for other)',
'tags - show the last 10 gallery build tags'
'tags - show the last 10 gallery build tags',
'--local check local commits instead of github',
'--force allow cdn request with dirty git root'
];
}
};
Expand Down
38 changes: 38 additions & 0 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ http://yuilibrary.com/license/
var log = require('./log'),
fs = require('fs'),
path = require('path'),
config = require('./config'),
exec = require('child_process').exec,
request = require('request'),
util = require('./util'),

mods = {
Expand Down Expand Up @@ -36,6 +38,42 @@ mods = {
cb(branch);
});
},
ghlog: function(cb) {
log.info('fetching commits from github');
this.findRoot();
var info = this.userAndRepo(),
self = this,
p = path.relative(path.join(this.root, '../'), process.cwd()),
url = 'https://api.github.com/repos/' + info[0] + '/' + info[1] + '/commits?per_page=100&path=' + p,
headers = {
'Content-Type' : 'application/json',
'User-Agent': 'yogi CLI tool'
};

if (config.get('gh_token')) {
headers['Authorization'] = 'bearer ' + config.get('gh_token');
}

request.get({
url: url,
headers: headers,
json: true
}, function(err, res) {
if (err) {
return mods.log(cb);
}
var commits = [];

res.body.forEach(function(item) {
var o = {
sha: item.sha,
note: item.commit.message
};
commits.push(o);
});
cb(commits);
});
},
log: function(cb) {
this.findRoot();
exec('git --no-pager log -n 10 --no-merges --format=oneline .', {
Expand Down

0 comments on commit 2edc077

Please sign in to comment.