Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't commit if no change

  • Loading branch information...
commit 76b14b295477fd6006873c593589246fbee166e3 1 parent e44e90b
@pksunkara authored
Showing with 48 additions and 39 deletions.
  1. +5 −1 lib/police/ask.js
  2. +43 −38 lib/police/github.js
View
6 lib/police/ask.js
@@ -67,6 +67,7 @@ ask.properties = function (pkg, gh) {
ask.gh.tree = gh.tree;
ask.gh.mode = gh.mode;
ask.gh.commit = gh.commit;
+ ask.gh.content = gh.content;
ghlock = false;
});
@@ -196,7 +197,10 @@ ask.fields = function (pkg, fields, callback) {
delete pkg.engine;
}
- police.github.write(JSON.stringify(ask.sort(pkg), null, 2) + '\n', callback);
+ police.github.write(JSON.stringify(ask.sort(pkg), null, 2) + '\n', function () {
+ prop = [];
+ callback();
+ });
});
});
}
View
81 lib/police/github.js
@@ -85,10 +85,11 @@ github.singleModule = function (name, callback) {
if (blob.length==1) {
police.winston.info(' Getting blob ' + blob[0].sha.substr(0,10).magenta);
github.blob(name, blob[0].sha, function (body) {
- var pkg = JSON.parse(new Buffer(body.content, 'base64').toString('utf8'));
+ var content = new Buffer(body.content, 'base64').toString('utf8');
+ var pkg = JSON.parse(content);
if (police.add || police.edit) {
var sname = name.split('/');
- police.ask.properties(pkg, {name: name, user: sname[0], tree: tree.sha, mode: blob[0].mode, commit: commit.sha});
+ police.ask.properties(pkg, {name: name, user: sname[0], tree: tree.sha, mode: blob[0].mode, commit: commit.sha, content: content});
}
police.check.pkg(pkg, callback);
});
@@ -120,50 +121,54 @@ github.singleModule = function (name, callback) {
*/
github.write = function (data, callback) {
- github.get('/user', function (body) {
- police.ask.gh.puser = body;
+ if (data != police.ask.gh.content) {
+ github.get('/user', function (body) {
+ police.ask.gh.puser = body;
- police.winston.info(' Updating ' + 'blob'.magenta);
- github.post('/repos/' + police.ask.gh.name + '/git/blobs', {content: data, encoding: 'utf-8'}, function (body) {
+ police.winston.info(' Updating ' + 'blob'.magenta);
+ github.post('/repos/' + police.ask.gh.name + '/git/blobs', {content: data, encoding: 'utf-8'}, function (body) {
- police.winston.info(' Updating ' + 'tree'.magenta);
- github.post('/repos/' + police.ask.gh.name + '/git/trees', {
- base_tree: police.ask.gh.tree,
- tree: [
- {
- path: 'package.json',
- mode: police.ask.gh.mode,
- type: 'blob',
- sha: body.sha
- }
- ]
- }, function (body) {
-
- police.winston.info(' Updating ' + 'commit'.magenta);
- github.post('/repos/' + police.ask.gh.name + '/git/commits', {
- message: 'Updated `package.json` using `police`',
- author: {
- name: 'Pavan Kumar Sunkara',
- email: 'pavan.sss1991@gmail.com',
- date: moment(new Date()).format('YYYY-MM-DDTHH:mm:ssZ')
- },
- committer: {
- name: police.ask.gh.puser.name,
- email: police.ask.gh.puser.email,
- date: moment(new Date()).format('YYYY-MM-DDTHH:mm:ssZ')
- },
- parents: [ police.ask.gh.commit ],
- tree: body.sha
+ police.winston.info(' Updating ' + 'tree'.magenta);
+ github.post('/repos/' + police.ask.gh.name + '/git/trees', {
+ base_tree: police.ask.gh.tree,
+ tree: [
+ {
+ path: 'package.json',
+ mode: police.ask.gh.mode,
+ type: 'blob',
+ sha: body.sha
+ }
+ ]
}, function (body) {
- police.winston.info(' Updating ' + 'master'.magenta);
- github.put('/repos/' + police.ask.gh.name + '/git/refs/heads/master', {sha: body.sha}, function (body) {
- callback();
+ police.winston.info(' Updating ' + 'commit'.magenta);
+ github.post('/repos/' + police.ask.gh.name + '/git/commits', {
+ message: 'Updated `package.json` using `police`',
+ author: {
+ name: 'Pavan Kumar Sunkara',
+ email: 'pavan.sss1991@gmail.com',
+ date: moment(new Date()).format('YYYY-MM-DDTHH:mm:ssZ')
+ },
+ committer: {
+ name: police.ask.gh.puser.name,
+ email: police.ask.gh.puser.email,
+ date: moment(new Date()).format('YYYY-MM-DDTHH:mm:ssZ')
+ },
+ parents: [ police.ask.gh.commit ],
+ tree: body.sha
+ }, function (body) {
+
+ police.winston.info(' Updating ' + 'master'.magenta);
+ github.put('/repos/' + police.ask.gh.name + '/git/refs/heads/master', {sha: body.sha}, function (body) {
+ callback();
+ });
});
});
});
});
- });
+ } else {
+ callback();
+ }
}
/*
Please sign in to comment.
Something went wrong with that request. Please try again.