Skip to content

Commit

Permalink
More GitHub API and test program.
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwartz committed Apr 10, 2012
1 parent 6227072 commit 3562a96
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/GitHub.js
Expand Up @@ -134,6 +134,38 @@ var commands = {
}
}
},
createKey: {
help: 'createKey name filename - create a key from file containing RSA/DSA key.',
fn: function(args) {
var parts = args.split(/\s+/);
var name = parts.shift();
var filename = parts.join(' ');
var key = fs.readFile(filename);
if (!key) {
console.log('*** error: ' + filename + ' not found');
return;
}
console.dir(gh.createKey(name, key));
}
},
deleteKey: {
help: 'deleteKey id - delete key identifeid by id.',
fn: function(args) {
console.dir(gh.deleteKey(args));
}
},
listRepos: {
help: 'listRepos [user] - list [a user\'s] repositories.',
fn: function(args) {
console.dir(gh.listRepos(args));
}
},
listCollaborators: {
help: 'listCollaborators user/repo - list a repository\'s collaborators.',
fn: function(args) {
console.dir(gh.listCollaborators(args));
}
},
cd: {
help: 'cd path - change working directory to path.',
fn: function(args) {
Expand Down
31 changes: 31 additions & 0 deletions modules/GitHub.js
Expand Up @@ -178,7 +178,38 @@ GitHub.prototype.extend({
});
this.status = response.status;
return this.status == 204 ? true : Json.decode(response.responseText);
},

listRepos: function(user) {
user = user || this.username;
var url = this.url + '/users/' + user + '/repos';
console.log(url);
var response = cURL({
url: url
});
this.status = response.status;
return Json.decode(response.responseText);
},

listCollaborators: function(name) {
var parts = name.split('/');
var user;
if (parts.length > 1) {
name = parts[1];
user = parts[0];
}
else {
user = this.username;
}

var url = this.url + '/repos/' + user + '/' + name + '/collaborators';
var response = cURL({
url: url
});
this.status = response.status;
return Json.decode(response.responseText);
}

});

exports.GitHub = GitHub;

0 comments on commit 3562a96

Please sign in to comment.