Add a repo profile, pretty stupid right now (using HEAD)
This commit is contained in:
parent
add7bc8ec8
commit
ea69fc18ca
11
app.rb
11
app.rb
|
@ -25,3 +25,14 @@ get "/:username" do |username|
|
|||
haml :profile
|
||||
end
|
||||
|
||||
get "/:username/:repo" do |username, repo|
|
||||
@username = username
|
||||
@reponame = repo
|
||||
@tree = @api.tree_for(username, repo)["tree"]
|
||||
@tree.sort! do |left, right|
|
||||
left["type"] <=> right["type"]
|
||||
end
|
||||
@uri_base = "https://github.com/#{username}/#{repo}/blob/HEAD"
|
||||
haml :repo
|
||||
end
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ module RCSHub
|
|||
|
||||
attr_accessor :cache
|
||||
REPOS_CACHE_KEY = "repos-for:"
|
||||
TREE_CACHE_KEY = "tree-for:"
|
||||
CACHE_EXPIRE = 60 * 5
|
||||
|
||||
|
||||
|
@ -34,12 +35,30 @@ module RCSHub
|
|||
return result
|
||||
end
|
||||
|
||||
def tree_for(username, repo)
|
||||
key = "#{TREE_CACHE_KEY}#{username}"
|
||||
|
||||
unless @cache.nil?
|
||||
if result = @cache.get(key)
|
||||
return JSON.load(result)
|
||||
end
|
||||
end
|
||||
|
||||
result = fetch_tree_for(username, repo)
|
||||
@cache.setex(key, CACHE_EXPIRE, JSON.dump(result)) unless @cache.nil?
|
||||
return result
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_repos_for(username)
|
||||
return self.class.get("#{BASE_URL}/users/#{username}/repos")
|
||||
end
|
||||
|
||||
def fetch_tree_for(username, repo)
|
||||
return self.class.get("#{BASE_URL}/repos/#{username}/#{repo}/git/trees/HEAD")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 307 B |
|
@ -0,0 +1,85 @@
|
|||
%html
|
||||
%head
|
||||
%title= "Index of /#{@username}/#{@reponame}"
|
||||
%body
|
||||
%h1
|
||||
Index of /#{@username}/#{@reponame}
|
||||
|
||||
%table
|
||||
%tr
|
||||
%th
|
||||
%img{:src => "/icons/blank.png"}
|
||||
%th
|
||||
%a{:href => "#"}
|
||||
Name
|
||||
%th
|
||||
%a{:href => "#"}
|
||||
Last Modified
|
||||
%th
|
||||
%a{:href => "#"}
|
||||
Size
|
||||
%th
|
||||
%a{:href => "#"}
|
||||
Description
|
||||
%tr
|
||||
%th{:colspan => 5}
|
||||
%hr
|
||||
%tr
|
||||
%td
|
||||
%img{:src => "/icons/back.png"}
|
||||
%td
|
||||
%a{:href => "/#{@username}"}
|
||||
Parent Directory
|
||||
%td
|
||||
%td{:align => "right"}
|
||||
\-
|
||||
%tr
|
||||
%td
|
||||
%img{:src => "/icons/folder.png"}
|
||||
%td
|
||||
%a{:href => "/#{@username}/#{@reponame}/branches"}
|
||||
branches
|
||||
%td
|
||||
%td{:align => "right"}
|
||||
\-
|
||||
%tr
|
||||
%td
|
||||
%img{:src => "/icons/folder.png"}
|
||||
%td
|
||||
%a{:href => "/#{@username}/#{@reponame}/tags"}
|
||||
tags
|
||||
%td
|
||||
%td{:align => "right"}
|
||||
\-
|
||||
%tr
|
||||
%td
|
||||
%img{:src => "/icons/tar.png"}
|
||||
%td
|
||||
%a{:href => "/#{@username}/#{@reponame}/clone"}
|
||||
clone #{@reponame.downcase}.rcsrepo
|
||||
%td
|
||||
%td{:align => "right"}
|
||||
\-
|
||||
%tr
|
||||
%th{:colspan => 5}
|
||||
%hr
|
||||
|
||||
- @tree.reverse_each do |f|
|
||||
%tr{:class => "tree_file_row"}
|
||||
%td
|
||||
- if f["type"] == "tree"
|
||||
%img{:src => "/icons/folder.png"}
|
||||
- else
|
||||
%img{:src => "/icons/unknown.png"}
|
||||
%td
|
||||
%a{:href => "#{@uri_base}/#{f["path"]}"}
|
||||
#{f["path"]}
|
||||
%td
|
||||
|
||||
%td{:align => "right"}
|
||||
- if f["type"] == "tree"
|
||||
\-
|
||||
- else
|
||||
#{f["size"]}
|
||||
%td
|
||||
|
Loading…
Reference in New Issue