-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawler.js
49 lines (43 loc) · 1.96 KB
/
crawler.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
var request = require('request');
var cheerio = require('cheerio');
var URL = require('url-parse');
var token = "464adba848db3ff77c490a2918a504bee6e31a7c";
var baseUrl = "http://github.amil.com.br/api/v3/";
var urlSufix = "?access_token=" + token;
var pageToVisit = baseUrl + "user/repos?access_token="+token;
request(pageToVisit, function(error, response, body) {
var repositories = JSON.parse(response.body)
Object.keys(repositories).map(function(objectKey, index) {
var repo = repositories[objectKey];
branchesUrl = baseUrl + "repos/clinical/" + repo.name + "/branches" + urlSufix
request(branchesUrl, function(error, response, body) {
var branches = JSON.parse(response.body)
Object.keys(branches).map(function(objectKey, index) {
var branch = branches[objectKey];
if(branch.name != "master"){
pullsUrl = baseUrl + "repos/clinical/" + repo.name + "/pulls" + urlSufix
var hasPullRequest = false;
request(pullsUrl, function(error, response, body) {
var pulls = JSON.parse(response.body)
Object.keys(pulls).map(function(objectKey, index) {
var pull = pulls[objectKey];
if(pull.head.ref == branch.name){
hasPullRequest = true;
issueUrl = baseUrl + "repos/clinical/" + repo.name + "/issues/" + pull.number + urlSufix
request(issueUrl, function(error, response, body) {
var issue = JSON.parse(response.body);
if(issue.labels.length == 0){
console.log("Repositório " + repo.name + " na branch " + branch.name + " no Pull Request " + pull.number + " não possui labels");
}
});
}
});
if(!hasPullRequest){
console.log("Repositório " + repo.name + " na branch " + branch.name + " não possui um pull request!");
}
});
}
});
});
});
});