Merge branch 'master' of github.com:warpc/rosa-build
This commit is contained in:
commit
c367fc818b
|
@ -1,12 +1,10 @@
|
||||||
# -*- encoding : utf-8 -*-
|
# -*- encoding : utf-8 -*-
|
||||||
class Git::BlobsController < Git::BaseController
|
class Git::BlobsController < Git::BaseController
|
||||||
before_filter :set_path
|
|
||||||
before_filter :set_commit_hash
|
|
||||||
before_filter :find_tree
|
before_filter :find_tree
|
||||||
|
before_filter :set_path_blob
|
||||||
|
before_filter :set_commit_hash
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@blob = @tree / @path
|
|
||||||
|
|
||||||
if params[:raw]
|
if params[:raw]
|
||||||
image_url = Rails.root.to_s + "/" + @path
|
image_url = Rails.root.to_s + "/" + @path
|
||||||
|
|
||||||
|
@ -19,21 +17,18 @@ class Git::BlobsController < Git::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def blame
|
def blame
|
||||||
@blob = @tree / @path
|
|
||||||
|
|
||||||
@blame = Grit::Blob.blame(@git_repository.repo, @commit.try(:id), @path)
|
@blame = Grit::Blob.blame(@git_repository.repo, @commit.try(:id), @path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw
|
def raw
|
||||||
@blob = @tree / @path
|
|
||||||
|
|
||||||
headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"]
|
headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"]
|
||||||
render :text => @blob.data, :content_type => @blob.mime_type
|
render :text => @blob.data, :content_type => @blob.mime_type
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def set_path
|
def set_path_blob
|
||||||
@path = params[:path]
|
@path = params[:path]
|
||||||
|
@blob = @tree / @path.encode_to_default
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_commit_hash
|
def set_commit_hash
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
class Git::CommitsController < Git::BaseController
|
class Git::CommitsController < Git::BaseController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@branch_name = (params[:branch] ? params[:branch] : "master")
|
@branch_name = params[:treeish] || "master"
|
||||||
@path = params[:path]
|
@path = params[:path]
|
||||||
|
|
||||||
if @path.present?
|
if @path.present?
|
||||||
|
|
|
@ -13,7 +13,7 @@ module CommitHelper
|
||||||
end
|
end
|
||||||
res << "</table>"
|
res << "</table>"
|
||||||
|
|
||||||
res.join("\n").html_safe
|
res.join("\n").encode_to_default.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
# def format_commit_message(message)
|
# def format_commit_message(message)
|
||||||
|
@ -34,7 +34,7 @@ module CommitHelper
|
||||||
|
|
||||||
def short_commit_message(message)
|
def short_commit_message(message)
|
||||||
# Why 42? Because it is the Answer!
|
# Why 42? Because it is the Answer!
|
||||||
truncate(message, :length => 42, :omission => "...")
|
truncate(message, :length => 42, :omission => "...").encode_to_default
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ module GitHelper
|
||||||
res = "#{link_to @project.name, tree_path(@project)} /"
|
res = "#{link_to @project.name, tree_path(@project)} /"
|
||||||
end
|
end
|
||||||
|
|
||||||
res.html_safe
|
res.encode_to_default.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_line_numbers(n)
|
def render_line_numbers(n)
|
||||||
|
@ -38,7 +38,9 @@ module GitHelper
|
||||||
|
|
||||||
def render_blob(blob)
|
def render_blob(blob)
|
||||||
res = ""
|
res = ""
|
||||||
blob.data.split("\n").collect{|line| "<div>#{line.present? ? h(line) : "<br>"}</div>"}.join
|
blob.data.encode_to_default.split("\n").collect do |line|
|
||||||
|
"<div>#{line.present? ? h(line) : "<br>"}</div>"
|
||||||
|
end.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def choose_render_way(blob)
|
def choose_render_way(blob)
|
||||||
|
@ -46,4 +48,9 @@ module GitHelper
|
||||||
return :text if blob.mime_type.match(/text|xml|json/)
|
return :text if blob.mime_type.match(/text|xml|json/)
|
||||||
:binary
|
:binary
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def force_encoding_to_site(string)
|
||||||
|
string.dup.encode_to_default
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
class GitHook
|
||||||
|
attr_reader :repo, :newrev, :oldrev, :newrev_type, :oldrev_type, :refname,
|
||||||
|
:change_type, :rev, :rev_type, :refname_type, :owner, :project
|
||||||
|
|
||||||
|
def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
|
||||||
|
@repo, @newrev, @oldrev, @refname, @newrev_type, @oldrev_type = repo, newrev, oldrev, ref, newrev_type, oldrev_type
|
||||||
|
@owner = User.find_by_uname owner_uname
|
||||||
|
@project = @owner.projects.where(:name => repo).first
|
||||||
|
@change_type = git_change_type
|
||||||
|
git_revision_types
|
||||||
|
commit_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def git_change_type
|
||||||
|
if @oldrev =~ /0+$/
|
||||||
|
return 'create'
|
||||||
|
elsif @newrev =~ /0+$/
|
||||||
|
return 'delete'
|
||||||
|
else
|
||||||
|
return 'update'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def git_revision_types
|
||||||
|
case @change_type
|
||||||
|
when 'create', 'update'
|
||||||
|
@rev = @newrev
|
||||||
|
@rev_type = @newrev_type
|
||||||
|
when 'delete'
|
||||||
|
@rev = @oldrev
|
||||||
|
@rev_type = @oldrev_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def commit_type
|
||||||
|
if @refname =~ /refs\/tags\/*/ && @rev_type == 'commit'
|
||||||
|
# un-annotated tag
|
||||||
|
@refname_type= 'tag'
|
||||||
|
#~ short_refname=refname + '##refs/tags/'
|
||||||
|
elsif @refname =~ /refs\/tags\/*/ && @rev_type == 'tag'
|
||||||
|
# annotated tag
|
||||||
|
@refname_type="annotated tag"
|
||||||
|
#~ short_refname= refname + '##refs/tags/'
|
||||||
|
elsif @refname =~ /refs\/heads\/*/ && @rev_type == 'commit'
|
||||||
|
# branch
|
||||||
|
@refname_type= 'branch'
|
||||||
|
elsif @refname =~ /refs\/remotes\/*'/ && @rev_type == 'commit'
|
||||||
|
# tracking branch
|
||||||
|
@refname_type="tracking branch"
|
||||||
|
@short_refname= @refname + '##refs/remotes/'
|
||||||
|
else
|
||||||
|
# Anything else (is there anything else?)
|
||||||
|
@refname_type= "*** Unknown type of update to $refname (#{rev_type})"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -162,6 +162,11 @@ class Project < ActiveRecord::Base
|
||||||
owner == user
|
owner == user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.process_hook(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
|
||||||
|
rec = GitHook.new(owner_uname, repo, newrev, oldrev, ref, newrev_type, oldrev_type)
|
||||||
|
#ActivityFeedObserver.instance.after_create rec # for example
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def build_path(dir)
|
def build_path(dir)
|
||||||
|
@ -178,6 +183,7 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
def create_git_repo
|
def create_git_repo
|
||||||
is_root? ? Grit::Repo.init_bare(path) : parent.git_repository.repo.delay.fork_bare(path)
|
is_root? ? Grit::Repo.init_bare(path) : parent.git_repository.repo.delay.fork_bare(path)
|
||||||
|
write_hook.delay
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_git_repo
|
def destroy_git_repo
|
||||||
|
@ -205,4 +211,10 @@ class Project < ActiveRecord::Base
|
||||||
FileUtils.rm_rf wiki_path
|
FileUtils.rm_rf wiki_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def write_hook
|
||||||
|
hook_file = File.join(path, 'hooks', 'post-receive')
|
||||||
|
FileUtils.cp(File.join(::Rails.root.to_s, 'lib', 'post-receive-hook'), hook_file)
|
||||||
|
#File.chmod(0775, hook_file) # need?
|
||||||
|
rescue Exception # FIXME
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,9 @@
|
||||||
- @blame.each do |elem|
|
- @blame.each do |elem|
|
||||||
%tr
|
%tr
|
||||||
%td.message{ :rowspan => elem[1].length }
|
%td.message{ :rowspan => elem[1].length }
|
||||||
.commit #{link_to shortest_hash_id(elem[0].id), commit_path(@project, elem[0].id)} by #{elem[0].author} #{elem[0].author != elem[0].committer ? "(#{elem[0].committer})" : "" }
|
.commit
|
||||||
|
#{link_to shortest_hash_id(elem[0].id), commit_path(@project, elem[0].id)} by
|
||||||
|
#{elem[0].author.to_s.encode_to_default} #{elem[0].author != elem[0].committer ? "(#{elem[0].committer.to_s.encode_to_default})" : "" }
|
||||||
.message
|
.message
|
||||||
%span.date= commit_date(elem[0].committed_date)
|
%span.date= commit_date(elem[0].committed_date)
|
||||||
%span.message= short_commit_message(elem[0].message)
|
%span.message= short_commit_message(elem[0].message)
|
||||||
|
@ -40,7 +42,7 @@
|
||||||
|
|
||||||
%td.code
|
%td.code
|
||||||
%pre
|
%pre
|
||||||
%div= elem[1].first
|
%div= elem[1].first.encode_to_default
|
||||||
|
|
||||||
- elem[1][1..-1].each do |line|
|
- elem[1][1..-1].each do |line|
|
||||||
%tr
|
%tr
|
||||||
|
@ -49,6 +51,6 @@
|
||||||
- index += 1
|
- index += 1
|
||||||
%td.code
|
%td.code
|
||||||
%pre
|
%pre
|
||||||
%div= line
|
%div= line.encode_to_default
|
||||||
|
|
||||||
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
%td.blob
|
%td.blob
|
||||||
:plain
|
:plain
|
||||||
<br/>
|
<br/>
|
||||||
<pre>#{ link_to @blob.basename, raw_path(@project, @treeish, @path) }</pre>
|
<pre>#{ link_to @blob.basename.encode_to_default, raw_path(@project, @treeish, @path) }</pre>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
.content
|
.content
|
||||||
.inner
|
.inner
|
||||||
|
|
||||||
%a{ :name => h(commit_diff.a_path) }
|
%a{ :name => h(commit_diff.a_path.encode_to_default) }
|
||||||
|
|
||||||
.blob_header
|
.blob_header
|
||||||
.size= h(commit_diff.a_path)
|
.size= h(commit_diff.a_path.encode_to_default)
|
||||||
- if commit_diff.b_path.present?
|
- if commit_diff.b_path.present?
|
||||||
.buttons
|
.buttons
|
||||||
= link_to("view file @ #{short_hash_id(@commit.id)}", blob_commit_path(@project, @commit.id, commit_diff.b_path))
|
= link_to("view file @ #{short_hash_id(@commit.id)}", blob_commit_path(@project, @commit.id, commit_diff.b_path.encode_to_default))
|
||||||
.clear
|
.clear
|
||||||
|
|
||||||
.diff_data
|
.diff_data
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
%table
|
%table
|
||||||
%tr
|
%tr
|
||||||
%td.committers
|
%td.committers
|
||||||
.author #{commit.author}, #{commit_date(commit.authored_date)}
|
.author #{commit.author.to_s.encode_to_default}, #{commit_date(commit.authored_date)}
|
||||||
- if commit.committer != commit.author
|
- if commit.committer != commit.author
|
||||||
.committer
|
.committer
|
||||||
(committed by: #{commit.committer}, #{commit_date(commit.committed_date)})
|
(committed by: #{commit.committer.to_s.encode_to_default}, #{commit_date(commit.committed_date)})
|
||||||
%td.message
|
%td.message
|
||||||
%p= link_to commit.message, commit_path(@project, commit.id)
|
%p= link_to commit.message.encode_to_default, commit_path(@project, commit.id)
|
||||||
%td.trees
|
%td.trees
|
||||||
.commit
|
.commit
|
||||||
Commit:
|
Commit:
|
||||||
|
@ -23,4 +23,4 @@
|
||||||
.parent
|
.parent
|
||||||
Parent:
|
Parent:
|
||||||
%span{ :style => "float: right;"}
|
%span{ :style => "float: right;"}
|
||||||
#{link_to short_hash_id(parent.id), tree_path(@project, :treeish => parent.id)}
|
#{link_to short_hash_id(parent.id), tree_path(@project, :treeish => parent.id)}
|
||||||
|
|
|
@ -37,10 +37,10 @@
|
||||||
= image_tag("git/icons/folder_16.png")
|
= image_tag("git/icons/folder_16.png")
|
||||||
%td.tree_element
|
%td.tree_element
|
||||||
- if entry.is_a?(Grit::Blob)
|
- if entry.is_a?(Grit::Blob)
|
||||||
= link_to entry.name, blob_path(@project, @treeish, File.join([@path, entry.name].compact))
|
= link_to entry.name.encode_to_default, blob_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact))
|
||||||
- else
|
- else
|
||||||
= link_to "#{entry.name}/", tree_path(@project, @treeish, File.join([@path, entry.name].compact))
|
= link_to "#{entry.name.encode_to_default}/", tree_path(@project, @treeish, File.join([@path, entry.name.encode_to_default].compact))
|
||||||
%td==
|
%td==
|
||||||
%td.last==
|
%td.last==
|
||||||
|
|
||||||
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
require './lib/ext/core/string'
|
|
@ -0,0 +1,13 @@
|
||||||
|
class WriteGitHookToProjects < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
origin_hook = File.join(::Rails.root.to_s, 'lib', 'post-receive-hook')
|
||||||
|
Project.all.each do |project|
|
||||||
|
hook_file = File.join(project.path, 'hooks', 'post-receive')
|
||||||
|
FileUtils.cp(origin_hook, hook_file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive')}
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class String
|
||||||
|
def encode_to_default
|
||||||
|
force_encoding(Encoding.default_internal || Encoding::UTF_8)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly.
|
||||||
|
|
||||||
|
pwd=`pwd`
|
||||||
|
reponame=`basename $pwd .git`
|
||||||
|
owner=`basename \`dirname $pwd\``
|
||||||
|
|
||||||
|
while read oldrev newrev ref
|
||||||
|
do
|
||||||
|
newrev_type=$(git cat-file -t $newrev 2> /dev/null)
|
||||||
|
oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null)
|
||||||
|
|
||||||
|
/bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'"
|
||||||
|
done
|
Loading…
Reference in New Issue