Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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