Compare commits

...

13 commits

Author SHA1 Message Date
Sami Samhuri
ac9f2f6181 support GitHub API v3 2012-06-12 22:12:20 -07:00
Sami Samhuri
04ae6c4c71 add gitignore 2011-12-02 20:49:50 -08:00
Sami Samhuri
1306761490 fix style 2011-12-02 20:49:42 -08:00
Sami Samhuri
df2b8d7c33 bump version 2011-01-03 16:52:05 -08:00
Sami Samhuri
f547829a1b fix github repo url 2011-01-03 16:51:30 -08:00
Sami Samhuri
5c91a0a42c make vows a dev dependency 2011-01-03 16:13:30 -08:00
Sami Samhuri
dcae8398bf raw does not work with jsonp in the browser, disable it 2010-12-20 11:32:54 -08:00
Sami Samhuri
22af769100 only detect ie outside the browser 2010-11-28 22:40:21 -08:00
Sami Samhuri
ee61b0f95a release v0.1.0 2010-11-28 22:37:44 -08:00
Sami Samhuri
93fcb0eda2 ie8 support 2010-11-28 22:36:56 -08:00
Sami Samhuri
b23ab2fe01 bump version 2010-11-28 22:36:03 -08:00
Sami Samhuri
274b6e4802 remove script elements used for JSONP calls 2010-11-28 22:35:51 -08:00
Sami Samhuri
d997c74d70 support multiple simultaneous requests, version bump 2010-11-08 23:33:21 -08:00
13 changed files with 918 additions and 643 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
node_modules
gitter.tmproj

View file

@ -1,4 +1,4 @@
VOWS=vows/{blob,branch,commit,raw,repo,tree,user}.js
VOWS=vows/{blob,branch,commit,repo,tree,user}.js
spec:
vows --spec $(VOWS)

View file

@ -1,9 +1,11 @@
gitter
======
A GitHub client inspired by [pengwynn/octopussy](/pengwynn/octopussy).
A GitHub client inspired by [pengwynn/octokit](https://github.com/pengwynn/octokit).
v2 API
v3 API
Works in Node.js and most web browsers.
Installation
@ -22,31 +24,31 @@ Usage
console.dir(user)
})
gh.repo('samsonjs/gitter', function(err, repo) {
gh.repo('samsonjs', 'gitter', function(err, repo) {
if (err) throw err
console.log('---- repo: ' + repo.owner + '/' + repo.name + ' ----')
console.dir(repo)
}).getWatchers(function(err, repos) {
}).fetchWatchers(function(err, watchers) {
if (err) throw err
console.log('---- watchers ----')
console.dir(repos)
}).getBranches(function(err, branches) {
console.dir(watchers)
}).fetchBranches(function(err, branches) {
if (err) throw err
console.log('---- branches: samsonjs/gitter ----')
console.dir(branches)
gh.commit(this.repo, branches['master'], function(err, commit) {
gh.commit(this.user, this.repo, branches['master'], function(err, commit) {
if (err) throw err
console.log('---- samsonjs/gitter/master commit: ' + commit.id + ' ----')
console.dir(commit.data())
})
})
For the full API have a look at the top of [lib/index.js](/samsonjs/gitter/blob/master/lib/index.js).
For the full API have a look at the top of [lib/index.js](https://github.com/samsonjs/gitter/blob/master/lib/index.js).
License
=======
Copyright 2010 Sami Samhuri sami.samhuri@gmail.com
Copyright 2010 - 2012 Sami Samhuri sami@samhuri.net
MIT (see included [LICENSE](/samsonjs/gitter/blob/master/LICENSE))
[MIT License](http://sjs.mit-license.org)

File diff suppressed because it is too large Load diff

View file

@ -1,25 +1,23 @@
{ "name" : "gitter"
, "description" : "GitHub client (API v2), inspired by pengwynn/octopussy"
, "version" : "0.0.2"
, "homepage" : "http://samhuri.net/node/gitter"
, "author" : "Sami Samhuri <sami.samhuri@gmail.com>"
, "description" : "GitHub client (API v3)"
, "version" : "0.2.0"
, "homepage" : "http://samhuri.net/proj/gitter"
, "author" : "Sami Samhuri <sami@samhuri.net>"
, "repository" :
{ "type" : "git"
, "url" : "http://github.com/samsonjs/gitter.git"
, "url" : "https://github.com/samsonjs/gitter"
}
, "bugs" :
{ "mail" : "sami.samhuri+gitter@gmail.com"
, "web" : "http://github.com/samsonjs/gitter/issues"
{ "mail" : "sami@samhuri.net"
, "url" : "http://github.com/samsonjs/gitter/issues"
}
, "directories" : { "lib" : "./lib" }
, "main" : "./lib/index"
, "engines" : { "node" : ">=0.3.0" }
, "engines" : { "node" : ">=0.6.0" }
, "licenses" :
[ { "type" : "MIT"
, "url" : "http://github.com/samsonjs/gitter/raw/master/LICENSE"
, "url" : "http://sjs.mit-license.org"
}
]
, "dependencies" : { "request" : "0.10.0 - 0.10.999"
, "vows" : "0.5.0 - 0.5.999"
}
}
, "devDependencies" : { "vows" : "0.6.2" }
}

View file

@ -1,35 +1,19 @@
var gh = require('../lib')
var gh = require('../')
, vows = require('vows')
, assert = require('assert')
, h = require('./helper')
, User = 'samsonjs'
, Repo = 'gitter'
, Proj = User + '/' + Repo
, TreeSha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc'
, Path = 'lib/index.js'
, Sha = '6c6cb9b3449c17e3ae4eee9061b4081ff33c8c64'
vows.describe('Blob').addBatch({
'after fetching a blob': {
topic: function() { gh.blob(Proj, TreeSha, Path, this.callback) },
'the data object can be accessed with the data() method': function(err, blob) {
assert.ifError(err)
assert.ok(blob)
assert.instanceOf(blob.data(), Object)
},
'data is a blob': function(err, blob) {
assert.ifError(err)
assert.ok(h.looksLikeABlob(blob.data()))
},
},
'after fetching commits for a blob': {
topic: function() { gh.blob(Proj, TreeSha, Path).getCommits(this.callback) },
'list of commits is available': function(err, commits) {
assert.ifError(err)
assert.ok(commits)
assert.instanceOf(commits, Array)
assert.equal(commits.length, 1)
assert.ok(commits.every(function(c) { return h.looksLikeACommit(c) }))
}
},
}).export(module)
'after fetching a blob': {
topic: function() { gh.blob(User, Repo, Sha, this.callback) },
'the data can be accessed via the content attribute': function(err, blob) {
assert.ifError(err)
assert.ok(blob)
assert.ok(blob.content)
}
}
}).export(module)

View file

@ -1,37 +1,23 @@
var gh = require('../lib')
var gh = require('../')
, vows = require('vows')
, assert = require('assert')
, h = require('./helper')
, User = 'samsonjs'
, Repo = 'gitter'
, Proj = User + '/' + Repo
, Branch = 'master'
vows.describe('Branch').addBatch({
'after fetching a branch': {
topic: function() { gh.branch(Proj, Branch, this.callback) },
'the data object can be accessed with the data() method': function(err, branch) {
assert.ifError(err)
assert.ok(branch)
assert.instanceOf(branch.data(), Object)
},
'attributes can be accessed with the data() method': function(err, branch) {
assert.ifError(err)
assert.instanceOf(branch.data('author'), Object)
},
'expected fields are present': function(err, branch) {
assert.ifError(err)
assert.ok(h.looksLikeABranch(branch.data()))
},
'after fetching a branch': {
topic: function() { gh.branch(User, Repo, Branch, this.callback) },
'attributes can be accessed': function(err, branch) {
assert.ifError(err)
assert.typeOf(branch.ref, 'string')
assert.instanceOf(branch.object, Object)
},
'after fetching commits': {
topic: function() { gh.commits(Proj, Branch, this.callback) },
'list of commits is available': function(err, commits) {
assert.ifError(err)
assert.ok(commits)
assert.instanceOf(commits, Array)
assert.ok(commits.every(function(c) { return h.looksLikeACommit(c) }))
}
}
'expected fields are present': function(err, branch) {
assert.ifError(err)
assert.ok(h.looksLikeABranch(branch))
},
}
}).export(module)

View file

@ -1,28 +1,22 @@
var gh = require('../lib')
var gh = require('../')
, vows = require('vows')
, assert = require('assert')
, h = require('./helper')
, User = 'samsonjs'
, Repo = 'gitter'
, Proj = User + '/' + Repo
, Sha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc'
vows.describe('Commit').addBatch({
'after fetching a commit': {
topic: function() { gh.commit(Proj, Sha, this.callback) },
'the data object can be accessed with the data() method': function(err, commit) {
assert.ifError(err)
assert.ok(commit)
assert.instanceOf(commit.data(), Object)
},
'attributes can be accessed with the data() method': function(err, commit) {
assert.ifError(err)
assert.instanceOf(commit.data('author'), Object)
},
'expected fields are present': function(err, commit) {
assert.ifError(err)
assert.ok(h.looksLikeACommit(commit.data()))
},
}
'after fetching a commit': {
topic: function() { gh.commit(User, Repo, Sha, this.callback) },
'attributes can be accessed': function(err, commit) {
assert.ifError(err)
assert.instanceOf(commit.author, Object)
},
'expected fields are present': function(err, commit) {
assert.ifError(err)
assert.ok(h.looksLikeACommit(commit))
},
}
}).export(module)

View file

@ -1,33 +1,56 @@
module.exports = { looksLikeABlob: looksLikeABlob
, looksLikeABranch: looksLikeACommit
, looksLikeAFullBlob: looksLikeAFullBlob
, looksLikeABranch: looksLikeARef
, looksLikeABranchList: looksLikeABranchList
, looksLikeACommit: looksLikeACommit
, looksLikeACollaborator: looksLikeAShortUser
, looksLikeAContributor: looksLikeAContributor
, looksLikeAFollower: looksLikeAShortUser
, looksLikeARepo: looksLikeARepo
, looksLikeASha: looksLikeASha
, looksLikeATree: looksLikeATree
, looksLikeAUser: looksLikeAUser
, looksLikeAWatcher: looksLikeAShortUser
}
var BlobKeys = ('mimeType mode name sha size').split(' ')
var BlobKeys = 'mode path sha type url'.split(' ')
var FullBlobKeys = 'content encoding sha size url'.split(' ')
var CommitKeys = ('author authoredDate committedDate committer id ' +
'message parents tree url').split(' ')
var CommitKeys = 'author committer message parents sha tree url'.split(' ')
var ContributorKeys = ('blog contributions email location login name type').split(' ')
var ContributorKeys = 'avatarUrl contributions gravatarId id login url'.split(' ')
var RefKeys = 'object ref url'.split(' ')
var BranchListKeys = 'commit name'.split(' ')
var RefObjectKeys = 'sha type url'.split(' ')
var RepoKeys = ('createdAt fork forks hasDownloads hasIssues hasWiki ' +
'name openIssues owner private pushedAt url watchers').split(' ')
var UserKeys = ('blog company createdAt email followersCount ' +
'followingCount id location login name ' +
'publicRepoCount publicGistCount type').split(' ')
var ShortUserKeys = 'avatarUrl gravatarId id login url'.split(' ')
var TreeKeys = 'tree sha url'.split(' ')
var UserKeys = ('blog company createdAt email followers ' +
'following id location login name ' +
'publicRepos publicGists type').split(' ')
function looksLikeABlob(obj) { return hasKeys(obj, BlobKeys) }
function looksLikeAFullBlob(obj) { return hasKeys(obj, FullBlobKeys) }
function looksLikeACommit(obj) { return hasKeys(obj, CommitKeys) }
function looksLikeAContributor(obj) { return hasKeys(obj, ContributorKeys) }
function looksLikeARef(obj) {
return hasKeys(obj, RefKeys) && hasKeys(obj.object, RefObjectKeys)
}
function looksLikeABranchList(obj) {
return obj.every(function(branch) { return hasKeys(branch, BranchListKeys) })
}
function looksLikeARepo(obj) { return hasKeys(obj, RepoKeys) }
function looksLikeASha(s) { return s && s.length === 40 }
function looksLikeATree(obj) { return obj && obj.every(function(b) { return looksLikeABlob(b) }) }
function looksLikeAShortUser(obj) { return hasKeys(obj, ShortUserKeys) }
function looksLikeATree(obj) {
return hasKeys(obj, TreeKeys) && obj.tree.every(looksLikeABlob)
}
function looksLikeAUser(obj) { return hasKeys(obj, UserKeys) }
function hasKeys(obj, keys) {

View file

@ -1,20 +0,0 @@
var gh = require('../lib')
, vows = require('vows')
, assert = require('assert')
, h = require('./helper')
, User = 'samsonjs'
, Repo = 'gitter'
, Proj = User + '/' + Repo
, Sha = 'a0a2d307cfe7810ccae0aec2ec6854d079de6511'
vows.describe('Raw').addBatch({
'after fetching a raw blob': {
topic: function() { gh.raw(Proj, Sha, this.callback) },
'the data object can be accessed with the data() method': function(err, raw) {
assert.ifError(err)
assert.ok(raw)
assert.equal(typeof raw.data(), 'string')
}
}
}).export(module)

View file

@ -1,100 +1,96 @@
var gh = require('../lib')
var gh = require('../')
, vows = require('vows')
, assert = require('assert')
, h = require('./helper')
, User = 'samsonjs'
, Repo = 'gitter'
, Proj = User + '/' + Repo
, ForkedRepo = 'strftime'
, CollaboratorsRepo = 'mojo.el'
vows.describe('Repo').addBatch({
'after fetching a repo': {
topic: function() { gh.repo(Proj, this.callback) },
'the data object can be accessed with the data() method': function(err, repo) {
assert.ifError(err)
assert.ok(repo)
assert.instanceOf(repo.data(), Object)
},
'attributes can be accessed with the data() method': function(err, repo) {
assert.ifError(err)
assert.equal(repo.data('owner'), User)
},
'expected fields are present': function(err, repo) {
assert.ifError(err)
assert.ok(h.looksLikeARepo(repo.data()))
},
'after fetching a repo': {
topic: function() { gh.repo(User, Repo, this.callback) },
'attributes can be accessed': function(err, repo) {
assert.ifError(err)
assert.equal(repo.owner.login, User)
},
'after fetching branches': {
topic: function() { gh.branches(Proj, this.callback) },
'map of branches is available': function(err, branches) {
assert.ifError(err)
assert.ok(branches)
assert.instanceOf(branches, Object)
assert.ok('master' in branches)
},
'names and commit ids of branches are available': function(err, branches) {
assert.ifError(err)
assert.ok(Object.keys(branches).every(function(b) { return h.looksLikeASha(branches[b]) }))
}
'expected fields are present': function(err, repo) {
assert.ifError(err)
assert.ok(h.looksLikeARepo(repo))
},
'after fetching collaborators': {
topic: function() { gh.collaborators(Proj, this.callback) },
'list of collaborators is available': function(err, collaborators) {
assert.ifError(err)
assert.ok(collaborators && collaborators.length >= 1)
assert.ok(collaborators.indexOf(User) !== -1)
},
'names of collaborators are available': function(err, collaborators) {
assert.ifError(err)
assert.ok(collaborators.every(function(c) { return c && c.length >= 1 }))
}
},
'after fetching branches': {
topic: function() { gh.branches(User, Repo, this.callback) },
'list of branches is available': function(err, branches) {
assert.ifError(err)
assert.ok(branches)
assert.instanceOf(branches, Array)
assert.ok(branches.some(function(branch) { return branch.name === 'master' }))
},
'after fetching contributors': {
topic: function() { gh.contributors(Proj, this.callback) },
'list of contributors is available': function(err, contributors) {
assert.ifError(err)
assert.ok(contributors && contributors.length >= 1)
},
'names of contributors are available': function(err, contributors) {
assert.ifError(err)
assert.ok(contributors.every(function(c) { return h.looksLikeAContributor(c) }))
}
},
'after fetching languages': {
topic: function() { gh.languages(Proj, this.callback) },
'map of languages is available': function(err, languages) {
assert.ifError(err)
assert.ok(languages)
assert.instanceOf(languages, Object)
assert.ok('JavaScript' in languages)
}
},
'after fetching network': {
topic: function() { gh.network(Proj, this.callback) },
'map of network is available': function(err, network) {
assert.ifError(err)
assert.ok(network && network.length >= 1)
assert.ok(network.every(function(r) { return h.looksLikeARepo(r) }))
}
},
'after fetching tags': {
topic: function() { gh.tags(Proj, this.callback) },
'map of tags is available': function(err, tags) {
assert.ifError(err)
assert.ok(tags)
assert.instanceOf(tags, Object)
}
},
'after fetching watchers': {
topic: function() { gh.watchers(Proj, this.callback) },
'list of watchers is available': function(err, watchers) {
assert.ifError(err)
assert.ok(watchers && watchers.length >= 1)
assert.ok(watchers.indexOf(User) !== -1)
},
'names of watchers are available': function(err, watchers) {
assert.ifError(err)
assert.ok(watchers.every(function(w) { return w && w.length >= 1 }))
}
'names and commit ids of branches are available': function(err, branches) {
assert.ifError(err)
assert.ok(h.looksLikeABranchList(branches))
}
},
'after fetching collaborators': {
topic: function() { gh.collaborators(User, CollaboratorsRepo, this.callback) },
'list of collaborators is available': function(err, collaborators) {
assert.ifError(err)
assert.ok(collaborators && collaborators.length >= 1)
assert.ok(collaborators.some(function(c) { return c.login === User }))
},
'names of collaborators are available': function(err, collaborators) {
assert.ifError(err)
assert.ok(collaborators.every(function(c) { return h.looksLikeACollaborator(c) }))
}
},
'after fetching contributors': {
topic: function() { gh.contributors(User, Repo, this.callback) },
'list of contributors is available': function(err, contributors) {
assert.ifError(err)
assert.ok(contributors && contributors.length >= 1)
},
'names of contributors are available': function(err, contributors) {
assert.ifError(err)
assert.ok(contributors.every(function(c) { return h.looksLikeAContributor(c) }))
}
},
'after fetching languages': {
topic: function() { gh.languages(User, Repo, this.callback) },
'map of languages is available': function(err, languages) {
assert.ifError(err)
assert.ok(languages)
assert.instanceOf(languages, Object)
assert.ok('JavaScript' in languages)
}
},
'after fetching fork': {
topic: function() { gh.forks(User, ForkedRepo, this.callback) },
'list of forks is available': function(err, forks) {
assert.ifError(err)
assert.ok(forks && forks.length >= 1)
assert.ok(forks.every(function(r) { return h.looksLikeARepo(r) }))
}
},
'after fetching tags': {
topic: function() { gh.tags(User, Repo, this.callback) },
'map of tags is available': function(err, tags) {
assert.ifError(err)
assert.ok(tags)
assert.instanceOf(tags, Object)
}
},
'after fetching watchers': {
topic: function() { gh.watchers(User, Repo, this.callback) },
'list of watchers is available': function(err, watchers) {
assert.ifError(err)
assert.ok(watchers && watchers.length >= 1)
assert.ok(watchers.some(function(w) { return w.login === User }))
},
'names of watchers are available': function(err, watchers) {
assert.ifError(err)
assert.ok(watchers.every(h.looksLikeAWatcher))
}
}
}).export(module)

View file

@ -1,53 +1,18 @@
var gh = require('../lib')
var gh = require('../')
, vows = require('vows')
, assert = require('assert')
, h = require('./helper')
, User = 'samsonjs'
, Repo = 'gitter'
, Proj = User + '/' + Repo
, TreeSha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc'
vows.describe('Tree').addBatch({
'after fetching a tree': {
topic: function() { gh.tree(Proj, TreeSha, this.callback) },
'the data object can be accessed with the data() method': function(err, tree) {
assert.ifError(err)
assert.ok(tree)
assert.instanceOf(tree.data(), Array)
},
'data is a git tree': function(err, tree) {
assert.ifError(err)
assert.ok(h.looksLikeATree(tree.blobs))
},
},
'after fetching blobs': {
topic: function() { gh.blobs(Proj, TreeSha, this.callback) },
'list of blobs is available': function(err, blobs) {
assert.ifError(err)
assert.ok(blobs)
assert.instanceOf(blobs, Object)
assert.ok(Object.keys(blobs).length > 1)
assert.ok('package.json' in blobs)
assert.ok(Object.keys(blobs).every(function(k) { return h.looksLikeASha(blobs[k]) }))
}
},
'after fetching full blobs': {
topic: function() { gh.tree(Proj, TreeSha).getFullBlobs(this.callback) },
'full blobs are available': function(err, blobs) {
assert.ifError(err)
assert.ok(blobs)
assert.instanceOf(blobs, Array)
assert.ok(blobs.every(function(b) { return h.looksLikeABlob(b) }))
}
},
'after fetching the full tree': {
topic: function() { gh.tree(Proj, TreeSha).getFullTree(this.callback) },
'full contents of tree are available': function(err, tree) {
assert.ifError(err)
assert.ok(tree)
assert.instanceOf(tree, Array)
assert.ok(tree.every(function(b) { return h.looksLikeABlob(b) }))
}
}
'after fetching a tree': {
topic: function() { gh.tree(User, Repo, TreeSha, this.callback) },
'data is a git tree': function(err, tree) {
assert.ifError(err)
assert.ok(h.looksLikeATree(tree))
}
}
}).export(module)

View file

@ -1,4 +1,4 @@
var gh = require('../lib')
var gh = require('../')
, vows = require('vows')
, assert = require('assert')
, h = require('./helper')
@ -8,18 +8,9 @@ var gh = require('../lib')
vows.describe('User').addBatch({
'after fetching a user': {
topic: function() { gh.user(User, this.callback) },
'the data object can be accessed with the data() method': function(err, user) {
assert.ifError(err)
assert.ok(user)
assert.instanceOf(user.data(), Object)
},
'attributes can be accessed with the data() method': function(err, user) {
assert.ifError(err)
assert.equal(user.data('login'), User)
},
'expected fields are present': function(err, user) {
assert.ifError(err)
assert.ok(h.looksLikeAUser(user.data()))
assert.ok(h.looksLikeAUser(user))
},
},
'after fetching their followers': {
@ -30,7 +21,7 @@ vows.describe('User').addBatch({
},
'usernames of followers are available': function(err, followers) {
assert.ifError(err)
assert.ok(followers.every(function(f) { return f && f.length > 1 }))
assert.ok(followers.every(h.looksLikeAFollower))
}
},
'after fetching users they follow': {
@ -41,7 +32,7 @@ vows.describe('User').addBatch({
},
'names of following users are available': function(err, following) {
assert.ifError(err)
assert.ok(following.every(function(f) { return f && f.length > 1 }))
assert.ok(following.every(h.looksLikeAFollower))
}
},
'after fetching their public repos': {