forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
81 lines (69 loc) · 1.65 KB
/
utils.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
75
76
77
78
79
80
81
'use strict';
// Process Functions for Labeller
const alexa_labels = ['top-1m', 'top-100k', 'top-10k', 'top-1k', 'top-100'];
class Utils {
constructor(octokit, httpse) {
this.octokit = octokit;
this.httpse = httpse;
}
labelled(pr) {
// Check if Alexa labels already applied
let m = true;
pr.labels.forEach(element => {
if( alexa_labels.includes(element.name))
m = false;
});
// Return filtered pull requests
return m;
}
// look at files in PR
files(files, alexa) {
let rank;
files.data.forEach(file => {
if(file.filename.match(/^src\/chrome\/content\/rules\//) !== null){
// Look at PR changes directly
let matches = file.patch.match(/((host)="([^"]|"")*")/g);
// strip to main domain
if( matches !== null) {
if( alexa.includes(matches[0].slice(6,-1))) {
let index = (matches[0].slice(6,-1))
rank = alexa.indexOf(index);
return rank;
}
}
}
});
if(rank) {
return rank;
} else {
return null;
}
}
// Get Alexa label
return_label(rank_num) {
let label;
if(rank_num < 100){
label = "top-100";
} else if(rank_num < 1000){
label = "top-1k";
} else if(rank_num < 10000){
label = "top-10k";
} else if(rank_num < 100000){
label = "top-100k";
} else {
label = "top-1m";
}
return label;
}
// Add Alexa Label
add_label(chosen_label, pr_number) {
this.octokit.issues.addLabels({
...this.httpse,
issue_number: pr_number,
labels: [chosen_label]
});
}
}
module.exports = {
Utils: Utils
}