Skip to content

Instantly share code, notes, and snippets.

@yoosefi
Created May 10, 2015 11:03
Show Gist options
  • Save yoosefi/36f2ddf3a5ec53b7e63b to your computer and use it in GitHub Desktop.
Save yoosefi/36f2ddf3a5ec53b7e63b to your computer and use it in GitHub Desktop.
var request = require('request');
module['exports'] = function SwearJar (hook) {
var jar = '';
request
.get('https://github.com/'+hook.params.repo+'/raw/'+hook.params.branch+'/'+hook.params.jar)
.on('response',function(res){
hook.debug(res);
res
.on('data',function(chunk){
jar += chunk;
})
.on('end',function(){
var swears = (jar.match(/\./g)||[]).length;
hook.res.writeHead(302,{
'Location': 'https://img.shields.io/badge/SwearJar-'+swears+'-lightgrey.svg',
'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0'
});
hook.res.end();
});
});
};
module['exports'].schema = {
"repo": {
"type": "string"
},
"branch": {
"type": "string",
"default": "master"
},
"jar": {
"type": "string",
"default": "swearjar"
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment