Skip to content

Instantly share code, notes, and snippets.

@achalv
Forked from anonymous/jsbin.labotiri.html
Created June 30, 2014 03:50
Show Gist options
  • Save achalv/7a55f5b6034d01a39a6a to your computer and use it in GitHub Desktop.
Save achalv/7a55f5b6034d01a39a6a to your computer and use it in GitHub Desktop.
fetch names of repos you've contributed to.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
$(document).ready(function(){
$.ajax({
type: "get",
url: "https://api.github.com/users/achalv/repos?type=public&sort=updated&direction=desc",
dataType: "json",
success: function(returnedData){
console.log(returnedData);
var contribs = [];
returnedData.forEach(function(obj) {
//console.log(obj.fork);
var isFork = obj.fork;
var createdAt = obj.created_at;
var lastPushedAt = obj.pushed_at;
if((isFork)&&lastPushedAt>createdAt){
contribs.push(obj);
}
//contribs.forEach(function(result))
});
//console.log(contribs);
function sortByKey(array, key) {
return array.sort(function(a, b) {
var x = a[key]; var y = b[key];
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
var sContribs = sortByKey(contribs, 'size');
console.log(sContribs);
for(var i=0; i<sContribs.length;i++){
var subObj = sContribs[i];
console.log(subObj.name);
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment