Skip to content

Instantly share code, notes, and snippets.

@lsloan
Forked from tantalor/github.jquery.js
Last active February 6, 2020 16:06
Show Gist options
  • Save lsloan/b600906631c913f575d1 to your computer and use it in GitHub Desktop.
Save lsloan/b600906631c913f575d1 to your computer and use it in GitHub Desktop.
An example JavaScript program using jQuery to get a list of GitHub projects.
Gist title: "List GitHub Projects Using jQuery"
Summary: An example JavaScript program using jQuery to get a list of GitHub projects.
Original source: http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html
// http://aboutcode.net/2010/11/11/list-github-projects-using-javascript.html
jQuery.githubUserRepositories = function(username, callback) {
jQuery.getJSON("https://api.github.com/users/" + username + "/repos?callback=?", callback);
}
jQuery.fn.loadRepositores = function(username) {
this.html("<span>Querying GitHub for repositories...</span>");
var target = this;
$.githubUserRepositories(username, function(data) {
var repos = data.data;
sortByNumberOfWatchers(repos);
var list = $('<dl/>');
target.empty().append(list);
$(repos).each(function() {
list.append('<dt><a href="'+ this.url +'">' + this.name + '</a></dt>');
list.append('<dd>' + this.description + '</dd>');
});
});
function sortByNumberOfWatchers(repos) {
repos.sort(function(a,b) {
return b.watchers - a.watchers;
});
}
};
@lsloan
Copy link
Author

lsloan commented Jun 17, 2015

I changed the GH API URL and which attribute of the returned data is used. The change of URL actually changes the nature of the githubUser function into a "githubUserRepositories" one. If we wanted the githubUser function to continue to return data about the user, another method could be added that would do the repo query based on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment