Project: jhub

Source Code GitHub Release npm package version Build Status License

jhub is a simple JavaScript library, which makes it possible to query the GitHub API for various information, such as:

  • Repositories
    • Commits
    • Releases
  • Users
  • Organizations
    • Repositories
    • Members
  • Gists
    • Files

The source code for jhub can be found here, or installed using npm.

Basic examples

/*
Get repositories
*/
var hub = jhub.init('TangChr');
hub.userRepos(function(repos) {
    for(r in repos) {
        console.log(repos[r].name);
    }
});
/*
Get starred repositories
*/
var hub = jhub.init('TangChr');
hub.starredRepos(function(starred) {
    for(s in starred) {
        console.log(starred[s].name);
    }
});
/*
Get releases
*/
var hub = jhub.init('TangChr');
var repo = hub.userRepo('jhub');
repo.releases(function(releases) {
    for(r in releases) {
        console.log(releases[r].tagName + ': ' + releases[r].name);
    }
});
/*
Get commits
*/
var hub = jhub.init('TangChr');
var repo = hub.userRepo('jhub');
repo.commits(function(commits) {
    for(c in commits) {
        console.log(commits[c].author);
        console.log(commits[c].comitter);
        console.log(commits[c].message);
    }
});

“Advanced” examples

/*
List a users organizations
*/
var hub = jhub.init('TangChr');
hub.userOrgs(function(orgs) {
    for(o in orgs) {
        var org = hub.org(orgs[o].login);
        org.get(function(info) {
            console.log(info.login+': '+info.name);
        });
    }
});
/*
List all members of a specific organization
*/
var hub = jhub.init();
var org = hub.org('TangMedia');
org.members(function(members) {
    for(m in members) {
        var user = hub.user(members[m].login);
        user.get(function(info) {
            console.log(info.name);
        });
    }
});

Gists

/*
List all Gists for a specific user (only public Gists will be shown)
*/
var hub = jhub.init('TangChr');
hub.userGists(function(gists) {
    for(g in gists) {
        console.log(gists[g].description);
    }
});
/*
List all Gists for a specific user (only public Gists will be shown)
This example also lists the files in each Gist
*/
var hub = jhub.init('TangChr');
hub.userGists(function(gists) {
    for(g in gists) {
        var gist = hub.gist(gists[g].id);
        gist.get(function(info) {
            console.log('Gist: '+info.description);
                for(f in info.files)
                    console.log('- '+info.files[f].name);
        });
    }
});