-
Notifications
You must be signed in to change notification settings - Fork 6
/
statusManager.js
64 lines (56 loc) · 1.67 KB
/
statusManager.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
const auditFile = require('./auditFile');
const RESOLUTIONS = require('./resolutions/RESOLUTIONS');
const { printSkipping } = require('./views/main')
function addStatusToAction(action) {
let unresolved = false;
action.resolves.map(re => {
let status = auditFile.get({ id: re.id, path: re.path });
if (status) {
re.decision = status
if (status === RESOLUTIONS.FIX) {
// should have been fixed!
unresolved = true
}
if (status === RESOLUTIONS.EXPIRED) {
unresolved = true
}
if (status === RESOLUTIONS.NONE) {
unresolved = true
}
} else {
unresolved = true
}
return re;
});
action.isMarkedResolved = !unresolved
return action
}
function saveResolution(action, { resolution, reason, expiresAt }) {
// default expiry rules
if (!expiresAt && resolution === RESOLUTIONS.IGNORE && auditFile.getRules().ignoreExpiresInDays) {
expiresAt = auditFile.getRules().ignoreExpiresInDays * 24 * 60 * 60 * 1000
}
action.resolves.map(re => auditFile.set(
{ id: re.id, path: re.path },
{ resolution, reason, expiresAt }
))
return auditFile.flush()
}
function dropResolvedActions(actions) {
if (!actions) {
return actions;
}
return actions
.map(addStatusToAction)
.filter(action => {
if (action.isMarkedResolved) {
printSkipping(action)
}
return !action.isMarkedResolved;
})
}
module.exports = {
dropResolvedActions,
addStatusToAction,
saveResolution
};