-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
93 lines (77 loc) · 2.4 KB
/
Copy pathMain.java
File metadata and controls
93 lines (77 loc) · 2.4 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
package GetJavaProjects;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.PagedIterable;
import Users.User;
public class Main {
public static void main(String[] args) throws IOException {
// args[0] : start from project id
List<User> users = new LinkedList<User>();
for (int i = 1 ; i < args.length; i = i + 2) {
users.add(new User(args[i], args[i+1]));
}
int nbreUser = 0;
int total = 0;
int javaProjects = 0;
String since = args[0];
for (User user : users) {
GitHub github = null;
try
{
github = GitHub.connectUsingPassword(user.getUsername(), user.getPassword());
// Extract all the GitHub public repositories
PagedIterable<GHRepository> repositories = github.listAllPublicRepositories(
since);
List<String> listJavaProjects = new LinkedList<String>();
for (GHRepository ghRepository : repositories) {
total ++;
try {
// Apparently, ghRepository.getLanguage() is not working,
// so I developed javaIsPrimaryLanguage
if (javaIsPrimaryLanguage(ghRepository)) {
javaProjects ++;
System.out.println(ghRepository.getFullName());
listJavaProjects.add(ghRepository.getFullName());
}
if (total == 4000*(nbreUser + 1)) {
since = ghRepository.getId() + "";
nbreUser ++;
break;
}
System.err.println("FROM : " + since + " : " + javaProjects + " / " + total);
} catch (Exception e) {
}
}
} catch (Exception e) {
System.err.println("Authentification failed : " + user.getUsername() + " / " + user.getPassword());
continue;
}
}
}
public static boolean javaIsPrimaryLanguage(GHRepository ghRepository) throws IOException {
String l = getPrimaryLanguage(ghRepository);
if (l != null && l.toLowerCase().equals("java")) {
return true;
}
return false;
}
public static String getPrimaryLanguage (GHRepository ghRepository) throws IOException {
int max = 0;
String result = null;
Map languages = ghRepository.listLanguages();
if (languages != null) {
for (Object language: languages.keySet()) {
if (max < (int) languages.get(language)) {
max = (int) languages.get(language);
result = (String) language;
}
}
}
return result;
}
}