Skip to content

Commit

Permalink
Merge pull request #60 from alexanderbeletsky/handle-409
Browse files Browse the repository at this point in the history
Handle 409 error (empty repository)
  • Loading branch information
buunguyen committed May 17, 2014
2 parents 205afed + 1e8e4ef commit 45e3fcc
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/inject.js
Expand Up @@ -4,8 +4,8 @@
, SHOWN = 'octotree.shown'
, REGEXP = /([^\/]+)\/([^\/]+)(?:\/([^\/]+))?/ // (username)/(reponame)/(subpart)
, RESERVED_USER_NAMES = [
'settings', 'orgs', 'organizations',
'site', 'blog', 'about',
'settings', 'orgs', 'organizations',
'site', 'blog', 'about',
'styleguide', 'showcases', 'trending',
'stars', 'dashboard', 'notifications'
]
Expand Down Expand Up @@ -82,16 +82,16 @@

var match = location.pathname.match(REGEXP)
if (!match) return false

// Not a repository, skip
if (~RESERVED_USER_NAMES.indexOf(match[1])) return false
if (~RESERVED_REPO_NAMES.indexOf(match[2])) return false

// Not a code page, skip
if (match[3] && !~['tree', 'blob'].indexOf(match[3])) return false

return {
username : match[1],
return {
username : match[1],
reponame : match[2],
branch : $('*[data-master-branch]').data('ref') || $('*[data-master-branch] > .js-select-button').text() || 'master'
}
Expand Down Expand Up @@ -163,6 +163,11 @@
else message = 'You have exceeded the GitHub API hourly limit and need GitHub access token to make extra requests. Follow <a href="https://github.com/settings/tokens/new" target="_blank">this link</a> to create one and paste it in the textbox below.'
}

else if (err.error === 409) {
header = 'Repository is empty or not yet available!'
message = 'This repository is not ready for browsing yet. Follow <a href="https://developer.github.com/v3/git/" target="_blank">this link</a> for details.'
}

updateSidebar('<div class="octotree_header_error">' + header + '</div>', message)
}

Expand All @@ -183,19 +188,19 @@
.on('click', function(e) {
var $target = $(e.target)
if ($target.is('a.jstree-anchor') && $target.children(':first').hasClass('blob')) {
$.pjax({
url : $target.attr('href'),
$.pjax({
url : $target.attr('href'),
timeout : 5000, //gives it more time, should really have a progress indicator...
container : $('#js-repo-pjax-container')
container : $('#js-repo-pjax-container')
})
}
})
.on('ready.jstree', function() {
var headerText = '<div class="octotree_header_repo">' +
repo.username + ' / ' + repo.reponame +
var headerText = '<div class="octotree_header_repo">' +
repo.username + ' / ' + repo.reponame +
'</div>' +
'<div class="octotree_header_branch">' +
repo.branch +
'<div class="octotree_header_branch">' +
repo.branch +
'</div>'
updateSidebar(headerText)
})
Expand Down Expand Up @@ -225,7 +230,7 @@
if (shown) $html.removeClass(PREFIX)
else $html.addClass(PREFIX)
store.set(SHOWN, !shown)
}
}

function saveToken(event) {
event.preventDefault()
Expand Down

0 comments on commit 45e3fcc

Please sign in to comment.