Skip to content

Instantly share code, notes, and snippets.

@mikegreiling
Created January 29, 2016 04:03
Show Gist options
  • Save mikegreiling/8bbad08c9498a791434f to your computer and use it in GitHub Desktop.
Save mikegreiling/8bbad08c9498a791434f to your computer and use it in GitHub Desktop.
A simple Auth0 webtask (webtask.io) for IFTTT which saves GitHub issue ages indexed by issue label(s) upon issue close
var moment = require('moment');
var parallel = require('async').parallel;
var MongoClient = require('mongodb').MongoClient;
function update_label_stats(label, age, db, cb) {
var where = {
label: label
};
var update = {
$push: {
ages: age
}
};
var options = {
upsert: true
};
db.collection('labels').updateOne(where, update, options, function (err) {
err ? cb(err) : cb(null);
});
}
module.exports = function (ctx, done) {
var opened = moment(ctx.data.opened, 'MMMM D, YYYY at h:mma');
var closed = moment(ctx.data.closed, 'MMMM D, YYYY at h:mma');
var issue_age = (closed - opened) / 1000;
var issue_labels = (ctx.data.labels || 'none').split(',');
MongoClient.connect(ctx.data.MONGO_URL, function (err, db) {
if (err) return done(err);
var mongo_tasks = issue_labels.map(function (label) {
return function (cb) {
update_label_stats(label, issue_age, db, function (err) {
err ? cb(err) : cb(null);
});
};
});
parallel(mongo_tasks, function (err) {
err ? done(err) : done(null, 'Success.');
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment