-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushScanReducer.js
74 lines (66 loc) · 1.66 KB
/
pushScanReducer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var config = require('config');
var util = require('util');
var partials = require('express-partials');
var session = require('express-session')
var MongoStore = require('connect-mongo')(session);
//mongo
var mongo = require('mongodb');
var monk = require('monk');
var db = monk(config.get('mongo.uri'));
var async = require('async');
var pushScans = db.get('push_scans')
async.waterfall([
function(callback){
pushScans.find({},function(err,allPushScans){
console.log('found %s push scans',allPushScans.length)
callback(err,allPushScans)
})
},
function(allPushScans,callback){
async.eachLimit(allPushScans,10,function(pushScan,callback){
var updateSet = {
commits: pushScan.push.commits,
repository: {
id: pushScan.push.repository.id,
name: pushScan.push.repository.name,
owner: {
login: pushScan.push.repository.owner.login
}
},
sender: {
login: pushScan.push.sender.login,
id: pushScan.push.sender.id
},
};
if('installation' in pushScan.push){
updateSet['installation'] = {id: pushScan.push.installation.id}
}
pushScans.findOneAndUpdate({
_id: pushScan._id
},{
$set: {
push: updateSet
}
},{
new: true
},function(err,pushScan){
if(err){
callback(err)
}else{
console.log('updated push %s',pushScan._id)
callback()
}
})
},function(err){
callback(err)
})
}
],function(err){
console.log('err is %s',err)
})