Merge branch 'master' into 151-grit_encodings_problems
This commit is contained in:
commit
a79a081fd1
|
@ -2,7 +2,7 @@
|
|||
class Git::CommitsController < Git::BaseController
|
||||
|
||||
def index
|
||||
@branch_name = (params[:branch] ? params[:branch] : "master")
|
||||
@branch_name = params[:treeish] || "master"
|
||||
@path = params[:path]
|
||||
|
||||
if @path.present?
|
||||
|
|
|
@ -37,7 +37,7 @@ module WikiHelper
|
|||
name == 'Home' ? project_wiki_index_path(project) : project_wiki_path(project, name)
|
||||
end
|
||||
|
||||
def formats
|
||||
def wiki_formats
|
||||
APP_CONFIG['wiki_formats'].map do |key, val|
|
||||
[ val, key.to_s ]
|
||||
end.sort do |a, b|
|
||||
|
|
|
@ -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
|
||||
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
|
||||
|
||||
def build_path(dir)
|
||||
|
@ -178,6 +183,7 @@ class Project < ActiveRecord::Base
|
|||
|
||||
def create_git_repo
|
||||
is_root? ? Grit::Repo.init_bare(path) : parent.git_repository.repo.delay.fork_bare(path)
|
||||
write_hook.delay
|
||||
end
|
||||
|
||||
def destroy_git_repo
|
||||
|
@ -205,4 +211,10 @@ class Project < ActiveRecord::Base
|
|||
FileUtils.rm_rf wiki_path
|
||||
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
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
%span= t("layout.wiki.editor.help")
|
||||
|
||||
#gollum-editor-format-selector
|
||||
= select_tag :format, options_for_select(formats, format), :id => "wiki_format"
|
||||
= select_tag :format, options_for_select(wiki_formats, format), :id => "wiki_format"
|
||||
= label_tag :format, t("layout.wiki.editor.format")
|
||||
#gollum-editor-help.jaws
|
||||
%ul#gollum-editor-help-parent
|
||||
|
|
|
@ -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,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