Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 2
Message 1 of 2

How to count the stars, forks, issues, and contributors of a user's all projects

unction cal_github_star(github_id) {
//1. 读入数据
//var github_id='guofei9987';
var url = "https://api.github.com/users/" + github_id + "/repos?page=";
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var a = JSON.parse(this.responseText);
onePage.push(a);
}
};

var Pages = [];
for (var i = 1; i < 200; i++) {
var onePage = [];
xmlhttp.open("GET", url + i, false);
xmlhttp.send();
Pages = Pages.concat(onePage[0]);
if (onePage[0].length == 0) {
break;
}
}


//2. 提取信息
repo_list = []
for (var j = 0; j < Pages.length; j++) {
if (!Pages[j]['fork']) {//排除fork别人的库
repo_list.push({
name: Pages[j]['name'],
stargazers_count: Pages[j]['stargazers_count'],
forks_count: Pages[j]['forks_count'],
html_url: Pages[j]['html_url'],
open_issues_count: Pages[j]['open_issues_count'],
watchers_count: Pages[j]['watchers_count'],
language: Pages[j]['language']

});
}
}


//排序
repo_list.sort(function (a, b) {
return a.stargazers_count - b.stargazers_count
});
repo_list.reverse();

//展示:表头
table_th = '<table border="1">' +
'<caption> User:' + github_id + '</caption>' +
'<tr>' +
'<th>Repository Name</th>' +
'<th>stars</th>' +
'<th>forks</th>' +
'<th>open_issues</th>' +
'<th>watchers</th>' +
'</tr>'

table_td = ''
total_rep = [0, 0, 0, 0]
for (i = 0; i < repo_list.length; i++) {
table_td +=
'<tr>' +
'<td><a href="' + repo_list[i].html_url + '"'
+ 'target="' + repo_list[i].name + '">'
+ repo_list[i].name + '</a></td>' +
'<td>' + repo_list[i].stargazers_count + '</td>' +
'<td>' + repo_list[i].forks_count + '</td>' +
'<td>' + repo_list[i].open_issues_count + '</td>' +
'<td>' + repo_list[i].watchers_count + '</td>' +
'</tr>';
total_rep[0] += repo_list[i].stargazers_count;
total_rep[1] += repo_list[i].forks_count;
total_rep[2] += repo_list[i].open_issues_count;
total_rep[3] += repo_list[i].watchers_count;
}



output = table_th +
'<tr>' +
'<th>Totally</th>' +
'<th>' + total_rep[0] + '</th>' +
'<th>' + total_rep[1] + '</th>' +
'<th>' + total_rep[2] + '</th>' +
'<th>' + total_rep[3] + '</th>' +
'</tr>' +
table_td +
'</table>';
return output;
}
1 Reply
Highlighted
Commander Lvl 1
Message 2 of 2

Re: How to count the stars, forks, issues, and contributors of a user's all projects

Hey! I understand your question and I'm guessing the info you posted is some code you wrote to try and do that. Do you mind updating the formatting of your code and put it in a formatted code section so it's easier to review? Also, can you please provide a little background about what you have right now and what is not working? 



*Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!*