simple, not tested, possibly not working, without views, git controllers
This commit is contained in:
parent
9e1814a10c
commit
cf2d6866b4
|
@ -0,0 +1,15 @@
|
||||||
|
class Git::BaseController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
|
before_filter :find_project
|
||||||
|
before_filter :find_repository
|
||||||
|
|
||||||
|
protected
|
||||||
|
def find_project
|
||||||
|
@project = Project.find_by_title!(params[:project_name])
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_repository
|
||||||
|
@repository = @project.git_repository
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,61 @@
|
||||||
|
class Git::BlobsController < Git::BaseController
|
||||||
|
before_filter :set_path
|
||||||
|
before_filter :set_treeish
|
||||||
|
before_filter :set_commit_hash
|
||||||
|
|
||||||
|
def show
|
||||||
|
if @commit_hash
|
||||||
|
@tree = @repository.tree(@commit_hash)
|
||||||
|
else
|
||||||
|
@tree = @repository.tree(@treeish)
|
||||||
|
@commit_hash = @repository.repo.log(@treeish, @path).first.id
|
||||||
|
end
|
||||||
|
|
||||||
|
@blob = @tree / @path
|
||||||
|
end
|
||||||
|
|
||||||
|
def blame
|
||||||
|
if @commit_hash
|
||||||
|
@tree = @repository.tree(@commit_hash)
|
||||||
|
@commit = @repository.commits(@commit_hash).first
|
||||||
|
else
|
||||||
|
@tree = @repository.tree(@treeish)
|
||||||
|
@commit = @repository.repo.log(@treeish, @path).first
|
||||||
|
end
|
||||||
|
|
||||||
|
@blob = @tree / @path
|
||||||
|
|
||||||
|
@blame = Grit::Blob.blame(@repository.repo, @commit.id, @path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw
|
||||||
|
if @commit_hash
|
||||||
|
@tree = @repository.tree(@commit_hash)
|
||||||
|
else
|
||||||
|
@tree = @repository.tree(@treeish)
|
||||||
|
@commit_hash = @repository.repo.log(@treeish, @path).first.id
|
||||||
|
end
|
||||||
|
|
||||||
|
@blob = @tree / @path
|
||||||
|
|
||||||
|
headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"]
|
||||||
|
render :text => @blob.data, :content_type => @blob.mime_type
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
def find_repository
|
||||||
|
# @repository = @project.repositories.find_by_name!(params[:repository_name])
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_path
|
||||||
|
@path = params[:path].join("/")
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_treeish
|
||||||
|
@treeish = params[:treeish] ? params[:treeish] : "master"
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_commit_hash
|
||||||
|
@commit_hash = params[:commit_hash].present? ? params[:commit_hash] : nil
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,20 @@
|
||||||
|
class Git::CommitsController < Git::BaseController
|
||||||
|
|
||||||
|
def index
|
||||||
|
@branch_name = (params[:branch] ? params[:branch] : "master")
|
||||||
|
@path = params[:path]
|
||||||
|
|
||||||
|
@commits = @path.present? ? @repository.repo.log(@branch_name, @path) : @repository.commits(@branch_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@commit = @repository.commits(params[:id]).first
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.diff { render :text => @commit.diffs.map{|d| d.diff}.join("\n"), :content_type => "text/plain" }
|
||||||
|
format.patch { render :text => @commit.to_patch, :content_type => "text/plain" }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
class Git::RepositoriesController < Git::BaseController
|
||||||
|
|
||||||
|
def show
|
||||||
|
@commit = @repository.master
|
||||||
|
@tree = @commit.tree
|
||||||
|
end
|
||||||
|
|
||||||
|
def commits
|
||||||
|
branch_name = (params[:branch] ? params[:branch] : "master")
|
||||||
|
@commits = @repository.commits(branch_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,12 @@
|
||||||
|
class Git::TreesController < Git::BaseController
|
||||||
|
|
||||||
|
def show
|
||||||
|
@treeish = params[:treeish] ? params[:treeish] : "master"
|
||||||
|
@path = params[:path]
|
||||||
|
|
||||||
|
@tree = @repository.tree(@treeish)
|
||||||
|
@tree = @tree / @path if @path
|
||||||
|
|
||||||
|
# render :template => "repositories/show"
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,24 @@
|
||||||
Rosa::Application.routes.draw do
|
Rosa::Application.routes.draw do
|
||||||
devise_for :users
|
devise_for :users
|
||||||
|
|
||||||
|
# Tree
|
||||||
|
match 'platforms/:platform_name/projects/:project_name/git/tree/:treeish(/*path)', :controller => "git/trees", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :tree
|
||||||
|
|
||||||
|
# Commits
|
||||||
|
match 'platforms/:platform_name//projects/:project_name/git/commits/:treeish(/*path)', :controller => "git/commits", :action => :index, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :commits
|
||||||
|
match 'platforms/:platform_name//projects/:project_name/git/commit/:id(.:format)', :controller => "git/comnits", :action => :show, :defaults => { :format => :html }, :as => :commit
|
||||||
|
|
||||||
|
# Blobs
|
||||||
|
match 'platforms/:platform_name/projects/:project_name/git/blob/:treeish/*path', :controller => "git/blobs", :action => :show, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blob
|
||||||
|
match 'platforms/:platform_name/projects/:project_name/git/commit/blob/:commit_hash/*path', :controller => "git/blobs", :action => :show, :as => :blob_commit
|
||||||
|
|
||||||
|
# Blame
|
||||||
|
match 'platforms/:platform_name/projects/:project_name/git/blame/:treeish/*path', :controller => "git/blobs", :action => :blame, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :blame
|
||||||
|
match 'platforms/:platform_name/projects/:project_name/git/commit/blame/:commit_hash/*path', :controller => "git/blobs", :action => :blame, :as => :blame_commit
|
||||||
|
|
||||||
|
# Raw
|
||||||
|
match 'platforms/:platform_name/projects/:project_name/git/raw/:treeish/*path', :controller => "git/blobs", :action => :raw, :treeish => /[0-9a-zA-Z_.\-]*/, :defaults => { :treeish => :master }, :as => :raw
|
||||||
|
match 'platforms/:platform_name/projects/:project_name/git/commit/raw/:commit_hash/*path', :controller => "git/blobs", :action => :raw, :as => :raw_commit
|
||||||
|
|
||||||
root :to => "platforms#index"
|
root :to => "platforms#index"
|
||||||
end
|
end
|
Loading…
Reference in New Issue