update gitter for GitHub API v3

This commit is contained in:
Sami Samhuri 2012-06-12 22:10:24 -07:00
parent 174d6ddf7f
commit 950461cc79
3 changed files with 733 additions and 610 deletions

File diff suppressed because it is too large Load diff

View file

@ -57,9 +57,9 @@
function updateBranches(name, branches) { function updateBranches(name, branches) {
function branchLink(b) { function branchLink(b) {
return '<a href=https://github.com/samsonjs/' + name + '/tree/' + b + '>' + b + '</a>' return '<a href=https://github.com/samsonjs/' + name + '/tree/' + b.name + '>' + b.name + '</a>'
} }
html('branches', listify(Object.keys(branches).map(branchLink))) html('branches', listify(branches.map(branchLink)))
} }
function updateContributors(contributors) { function updateContributors(contributors) {
@ -82,8 +82,8 @@
if (!t || +new Date() - t > 3600 * 1000) { if (!t || +new Date() - t > 3600 * 1000) {
console.log('stale ' + String(t)) console.log('stale ' + String(t))
data.set('t-' + name, +new Date()) data.set('t-' + name, +new Date())
GITR.repo('samsonjs/' + name) GITR.repo('samsonjs', name)
.getBranches(function(err, branches) { .fetchBranches(function(err, branches) {
if (err) { if (err) {
text('branches', '(oops)') text('branches', '(oops)')
} else { } else {
@ -91,7 +91,7 @@
updateBranches(name, branches) updateBranches(name, branches)
} }
}) })
.getLanguages(function(err, langs) { .fetchLanguages(function(err, langs) {
if (err) { if (err) {
text('langs', '(oops)') text('langs', '(oops)')
return return
@ -99,7 +99,7 @@
data.set('langs', langs) data.set('langs', langs)
updateLangs(langs) updateLangs(langs)
}) })
.getContributors(function(err, users) { .fetchContributors(function(err, users) {
if (err) { if (err) {
text('contributors', '(oops)') text('contributors', '(oops)')
} else { } else {
@ -107,7 +107,7 @@
updateContributors(users) updateContributors(users)
} }
}) })
.getWatchers(function(err, users) { .fetchWatchers(function(err, users) {
if (err) { if (err) {
text('nwatchers', '?') text('nwatchers', '?')
} else { } else {
@ -115,7 +115,7 @@
updateN('watchers', users) updateN('watchers', users)
} }
}) })
.getNetwork(function(err, repos) { .fetchForks(function(err, repos) {
if (err) { if (err) {
text('nforks', '?') text('nforks', '?')
} else { } else {

View file

@ -40,12 +40,12 @@
</p> </p>
<table align="center" id="stats"> <table align="center" id="stats">
<tr> <tr>
<td align="right"><span id="nrepos"><img src="../images/spinner@2x.gif" width="16" height="16"></span> projects</td> <td align="right"><span id="npublicRepos"><img src="../images/spinner@2x.gif" width="16" height="16"></span> projects</td>
<td>&mdash;</td> <td>&mdash;</td>
<td align="left"><span id="nfollowers"><img src="../images/spinner@2x.gif" width="16" height="16"></span> followers</td> <td align="left"><span id="nfollowers"><img src="../images/spinner@2x.gif" width="16" height="16"></span> followers</td>
</tr> </tr>
<tr> <tr>
<td align="right">watching <span id="nwatched"><img src="../images/spinner@2x.gif" width="16" height="16"></span> <td align="right"><span id="npublicGists"><img src="../images/spinner@2x.gif" width="16" height="16"> gists</span>
<td>&mdash;</td> <td>&mdash;</td>
<td align="left">following <span id="nfollowing"><img src="../images/spinner@2x.gif" width="16" height="16"></span></td> <td align="left">following <span id="nfollowing"><img src="../images/spinner@2x.gif" width="16" height="16"></span></td>
</tr> </tr>
@ -122,30 +122,32 @@ if (typeof console === 'undefined') {
document.getElementById(id).className = ' highlight' document.getElementById(id).className = ' highlight'
} }
function updateN(name, things) { function updateN(name, things) {
textHighlight('n' + name, things.length) textHighlight('n' + name, things)
} }
var data = createObjectStore('proj') var data = createObjectStore('proj')
, t = data.get('t-proj') , t = data.get('t-proj')
, names = ['followers', 'following', 'repos', 'watched'] , user = GITR.user('samsonjs')
, names = ['followers', 'following', 'publicRepos', 'publicGists']
if (!t || +new Date() - t > 3600 * 1000) { if (!t || +new Date() - t > 3600 * 1000) {
console.log('stale ' + String(t)) console.log('stale ' + String(t))
data.set('t-proj', +new Date()) data.set('t-proj', +new Date())
names.forEach(function(name) { user.fetch(function(err, user) {
GITR[name]('samsonjs', function(err, things) { if (user) {
data.set('user', user)
}
names.forEach(function(name) {
if (err) { if (err) {
text('n' + name, '?') updateN(name, '?')
} else { }
data.set(name, things) else {
updateN(name, things) updateN(name, user[name])
} }
}) })
}) })
} else { } else {
console.log('hit ' + t + ' (' + (+new Date() - t) + ')') console.log('hit ' + t + ' (' + (+new Date() - t) + ')')
names.forEach(function(name) { names.forEach(function(name) { updateN(name, data.get('user')[name]) })
updateN(name, data.get(name))
})
} }
} }
}()) }())