A fun CLI hack to automatically tweet about every git commit.
Prerequisites
npm install ntwitter npm install -g grunt-cli
Custom Grunt Tweet Task
grunt.registerTask('tweet', 'Tweet the commit info', function() {
var twitter = require('twitter');
var shell = require('shelljs');
var commit_comment = shell.exec('git log -1 --pretty=%B').output
.replace(/(\r\n|\n|\r)/gm, '');
var repo = shell.exec('basename $(git remote show -n origin | grep Fetch | cut -d: -f2-)').output
.replace(/(\r\n|\n|\r)/gm, '');
var author = shell.exec("git --no-pager show -s --format='%an'").output
.replace(/(\r\n|\n|\r)/gm, '');
var tweet = util.format('%s on %s by %s', commit_comment, repo, author);
var twit = new twitter({
consumer_key: 'Twitter',
consumer_secret: 'API',
access_token_key: 'keys',
access_token_secret: 'go here'
});
twit.updateStatus(tweet, function(err, data) {
console.log(data);
});
});
Have a pre-commit hook at .git/hooks/pre-commit calling grunt tweet to tweet on every commit!
The tweet would be something like: 'jshint suggestions from @passy on yo.git by Hemanth.HM'
#node#grunt#git#cli
About Hemanth HM
Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.