Merge branch 'master' of github.com:evilmartians/rosa-build

This commit is contained in:
Alexey Nayden 2011-03-10 16:21:39 +03:00
commit 7c39293855
12 changed files with 230 additions and 7 deletions

View File

@ -0,0 +1,20 @@
class Git::BaseController < ApplicationController
before_filter :authenticate_user!
before_filter :find_platfrom
before_filter :find_project
before_filter :find_repository
protected
def find_platform
@platform = Platform.find_by_name!(params[:platform_name])
end
def find_project
@project = Project.find_by_name!(params[:project_name])
end
def find_repository
@repository = @project.git_repository
end
end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 => "git/repositories/show"
end
end

View File

@ -1,2 +0,0 @@
class GitController < ApplicationController
end

View File

@ -0,0 +1,28 @@
class Git::Repository
delegate :commits, :tree, :tags, :heads, :to => :repo
attr_accessor :path, :name
def initialize(path, name)
@path = path
@name = name
end
def master
commits.first
end
def to_s
name
end
def repo
@repo ||= Grit::Repo.new(repo_path)
end
protected
def repo_path
@repo_path ||= File.join(path, name)
end
end

View File

@ -1,10 +1,13 @@
class Project < ActiveRecord::Base
belongs_to :platform
validate :name, :uniqueness => true, :presence => true
validate :unixname, :uniqueness => true, :presence => true
before_validation :generate_unixname
validate :validate_unixname
belongs_to :platform
before_validation :generate_unixname
include Project::HasRepository
protected

View File

@ -0,0 +1,14 @@
module Project::HasRepository
def self.included(model)
end
def git_repository
@repository ||= Git::Repository(git_repo_path, name)
end
protected
def git_repo_path
@git_repo_path ||= "xxx"
end
end

View File

@ -0,0 +1,34 @@
.row= link_to "Commits", commits_path(@platform.name, @project.name, @treeish)
.row.tags
%h3 Tags:
%ul
- @repository.tags.each do |tag|
%li= link_to tag.name, tree_path(@platform.name, @project.name, tag.name)
.row.heads
%h3 Heads:
%ul
- @repository.heads.each do |head|
%li= link_to head.name, tree_path(@platform.name, @project.name, head.name)
%table
%thead
%tr
%th name
%th age
%th message
%tbody
- if @path.present?
%tr
%td
= link_to "..", tree_path(@platform.name, @project.name, @treeish, File.join([@path, ".."].compact))
- @tree.contents.each do |entry|
%tr
%td
- if entry.is_a?(Grit::Blob)
= link_to entry.name, blob_path(@platform.name, @project.name, @treeish, File.join([@path, entry.name].compact))
- else
= link_to "#{entry.name}/", tree_path(@platform.name, @project.name, @repository.name, @treeish, File.join([@path, entry.name].compact))
%td== &nbsp;
%td== &nbsp;

View File

@ -3,3 +3,6 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register "text/plain", :diff
Mime::Type.register "text/plain", :patch

View File

@ -2,12 +2,29 @@ Rosa::Application.routes.draw do
devise_for :users
resources :platforms do
resources :projects do
resource :git
end
resources :projects
end
resources :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"
end