-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommit-scorer.js
55 lines (42 loc) · 1.74 KB
/
commit-scorer.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
const nconf = require('nconf');
exports.getScore = (patch, currentDate, commitDate) => {
return getScoreWithoutDecay(patch).then((score) => {
let timeFromCommit = Math.abs(currentDate.getTime() - commitDate.getTime());
let daysFromCommit = Math.ceil(timeFromCommit / (1000 * 3600 * 24));
let boost = Math.log(Math.pow(2, 600/daysFromCommit));
return Promise.resolve(score * boost);
});
};
let getScoreWithoutDecay = patch => {
if (patch.isAdded() || patch.isDeleted())
return Promise.resolve(10);
if (!patch.isModified())
return Promise.resolve(patch.isRenamed() ? 3 : 0);
return patch.hunks()
.then(hunks => {
let realModificationsAmountPromises =
hunks.map(hunk => {
return hunk.lines().then(lines => {
return Promise.resolve(countRealModifications(lines));
})
})
return Promise.all(realModificationsAmountPromises);
})
.then(values => {
let realChangedLines = values.reduce((a, b) => a + b, 0);
return Promise.resolve(realChangedLines ? 7 : 0);
});
};
const countRealModifications = lines => {
let realChanges = lines.filter(line => {
if (line.origin() == 32) // Unmodified line.
return false;
if (shouldIgnoreContent(line.content().trim()))
return false;
return true;
});
return realChanges.length;
}
const shouldIgnoreContent = content =>
nconf.get('ignoreModifiedLineWords').some(word => content.startsWith(word)) ||
nconf.get('ignoreModifiedWholeLines').some(word => content == word)