Update gems, fix conflicts. Raise 404 error instead of redirect. Refactor git controllers. Refactor git methods, move to modules. Cleanup git helpers, refactor and remove unused variables from views, refactor git templates. Refactor project load. Refactor git routes and links, refactor constraints. Fix branches with slashes and dots. Apply github linguist and libmagic for binary file detection. Other refactor and code cleanup. Fix specs and deprecations. Refs #263
This commit is contained in:
parent
d9755f295c
commit
611b22baa5
24
Gemfile
24
Gemfile
|
@ -2,19 +2,19 @@ source 'http://rubygems.org'
|
|||
|
||||
gem 'rails', '3.2.6' #, :git => 'git://github.com/rails/rails.git'
|
||||
|
||||
gem 'pg', '~> 0.13.2'
|
||||
gem 'pg', '~> 0.14.0'
|
||||
# gem 'silent-postgres', :git => 'git://github.com/dolzenko/silent-postgres.git' #'~> 0.1.1'
|
||||
gem 'redhillonrails_core', :git => 'git://github.com/chipiga/redhillonrails_core.git', :branch => 'rails31' # '~> 2.0.0.pre' # deprecated
|
||||
# gem 'schema_plus', '~> 0.2.1' # buggy shit!
|
||||
|
||||
gem 'devise', '~> 2.0.4'
|
||||
gem 'omniauth', '~> 1.0.3'
|
||||
gem 'devise', '~> 2.1.2'
|
||||
gem 'omniauth', '~> 1.1.0'
|
||||
gem 'omniauth-openid', '~> 1.0.1'
|
||||
gem 'cancan', '~> 1.6.7'
|
||||
gem 'cancan', '1.6.7' # 1.6.8 fail specs with strange error
|
||||
|
||||
gem 'ancestry', '~> 1.3.0'
|
||||
gem 'paperclip', '~> 3.0.4'
|
||||
gem 'resque', '~> 1.20.0'
|
||||
gem 'paperclip', '~> 3.1.3'
|
||||
gem 'resque', '~> 1.21.0'
|
||||
gem 'resque-status', '~> 0.3.3'
|
||||
gem 'resque_mailer', '~> 2.1.0'
|
||||
gem 'perform_later', '~> 1.3.0' # should be after resque_mailer
|
||||
|
@ -26,6 +26,8 @@ gem 'state_machine'
|
|||
gem 'grack', :git => 'git://github.com/rdblue/grack.git', :require => 'git_http'
|
||||
gem "grit", :git => 'git://github.com/warpc/grit.git' #, :path => '~/Sites/code/grit'
|
||||
gem 'charlock_holmes', '~> 0.6.8' #, :git => 'git://github.com/brianmario/charlock_holmes.git', :branch => 'bundle-icu'
|
||||
# gem 'ruby-filemagic', '~> 0.4.2', :require => 'filemagic/ext'
|
||||
gem 'github-linguist', '~> 2.0.1', :require => 'linguist'
|
||||
gem 'diff-display', '~> 0.0.1'
|
||||
|
||||
# Wiki
|
||||
|
@ -39,7 +41,7 @@ gem 'wikicloth'
|
|||
|
||||
gem 'unicorn', '~> 4.3.1', :platforms => [:mri, :rbx]
|
||||
gem 'trinidad', '~> 1.0.2', :platforms => :jruby
|
||||
gem 'newrelic_rpm', '~> 3.3.5', :platforms => [:mri, :rbx]
|
||||
gem 'newrelic_rpm', '~> 3.4.0.1', :platforms => [:mri, :rbx]
|
||||
gem 'whenever', '~> 0.7.3', :require => false
|
||||
|
||||
gem 'jbuilder', '~> 0.4.0'
|
||||
|
@ -54,14 +56,14 @@ gem 'rails-backbone', '~> 0.7.2'
|
|||
group :assets do
|
||||
gem 'sass-rails', '~> 3.2.5'
|
||||
gem 'coffee-rails', '~> 3.2.2'
|
||||
gem 'compass-rails', '~> 1.0.2'
|
||||
gem 'compass-rails', '~> 1.0.3'
|
||||
gem 'uglifier', '~> 1.2.4'
|
||||
gem 'therubyracer', '~> 0.10.1', :platforms => [:mri, :rbx]
|
||||
gem 'therubyrhino', '~> 1.73.1', :platforms => :jruby
|
||||
end
|
||||
|
||||
group :production do
|
||||
gem "airbrake", '~> 3.1.1'
|
||||
gem "airbrake", '~> 3.1.2'
|
||||
gem 'bluepill', '~> 0.0.60', :require => false
|
||||
end
|
||||
|
||||
|
@ -78,8 +80,8 @@ group :development do
|
|||
end
|
||||
|
||||
group :test do
|
||||
gem 'rspec-rails', '~> 2.10.1', :group => 'development'
|
||||
gem 'factory_girl_rails', '~> 3.4.0'
|
||||
gem 'rspec-rails', '~> 2.11.0', :group => 'development'
|
||||
gem 'factory_girl_rails', '~> 3.5.0'
|
||||
gem 'rr', '~> 1.0.4'
|
||||
gem 'shoulda'
|
||||
end
|
||||
|
|
138
Gemfile.lock
138
Gemfile.lock
|
@ -52,7 +52,7 @@ GEM
|
|||
activesupport (3.2.6)
|
||||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
airbrake (3.1.1)
|
||||
airbrake (3.1.2)
|
||||
activesupport
|
||||
builder
|
||||
albino (1.3.3)
|
||||
|
@ -88,33 +88,40 @@ GEM
|
|||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.3.3)
|
||||
compass (0.12.1)
|
||||
compass (0.12.2)
|
||||
chunky_png (~> 1.2)
|
||||
fssm (>= 0.2.7)
|
||||
sass (~> 3.1)
|
||||
compass-rails (1.0.2)
|
||||
compass (>= 0.12.0, < 0.14)
|
||||
compass-rails (1.0.3)
|
||||
compass (>= 0.12.2, < 0.14)
|
||||
creole (0.4.2)
|
||||
daemons (1.1.6)
|
||||
devise (2.0.4)
|
||||
devise (2.1.2)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.0.3)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (~> 3.1)
|
||||
warden (~> 1.1.1)
|
||||
warden (~> 1.2.1)
|
||||
diff-display (0.0.1)
|
||||
diff-lcs (1.1.3)
|
||||
ejs (1.0.0)
|
||||
erubis (2.7.0)
|
||||
escape_utils (0.2.4)
|
||||
eventmachine (0.12.10)
|
||||
execjs (1.4.0)
|
||||
multi_json (~> 1.0)
|
||||
expression_parser (0.9.0)
|
||||
factory_girl (3.4.0)
|
||||
factory_girl (3.5.0)
|
||||
activesupport (>= 3.0.0)
|
||||
factory_girl_rails (3.4.0)
|
||||
factory_girl (~> 3.4.0)
|
||||
factory_girl_rails (3.5.0)
|
||||
factory_girl (~> 3.5.0)
|
||||
railties (>= 3.0.0)
|
||||
ffi (1.0.11)
|
||||
fssm (0.2.9)
|
||||
github-linguist (2.0.1)
|
||||
charlock_holmes (~> 0.6.6)
|
||||
escape_utils (~> 0.2.3)
|
||||
mime-types (~> 1.18)
|
||||
pygments.rb (~> 0.2.13)
|
||||
github-markup (0.7.2)
|
||||
gollum (1.3.1)
|
||||
albino (~> 1.3.2)
|
||||
|
@ -132,14 +139,14 @@ GEM
|
|||
haml (~> 3.0)
|
||||
railties (~> 3.0)
|
||||
hashie (1.2.0)
|
||||
highline (1.6.12)
|
||||
highline (1.6.13)
|
||||
hike (1.2.1)
|
||||
hirb (0.6.2)
|
||||
hirb (0.7.0)
|
||||
i18n (0.6.0)
|
||||
jbuilder (0.4.0)
|
||||
activesupport (>= 3.0.0)
|
||||
blankslate (>= 2.1.2.4)
|
||||
journey (1.0.3)
|
||||
journey (1.0.4)
|
||||
jquery-rails (2.0.2)
|
||||
railties (>= 3.2.0, < 5.0)
|
||||
thor (~> 0.14)
|
||||
|
@ -152,18 +159,18 @@ GEM
|
|||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
mailcatcher (0.5.6)
|
||||
mailcatcher (0.5.7.2)
|
||||
activesupport (~> 3.0)
|
||||
eventmachine (~> 0.12)
|
||||
haml (~> 3.1)
|
||||
mail (~> 2.3)
|
||||
sinatra (~> 1.2)
|
||||
skinny (~> 0.2)
|
||||
skinny (~> 0.2, >= 0.2.1)
|
||||
sqlite3 (~> 1.3)
|
||||
thin (~> 1.2)
|
||||
meta-tags (1.2.6)
|
||||
actionpack
|
||||
mime-types (1.18)
|
||||
mime-types (1.19)
|
||||
multi_json (1.3.6)
|
||||
mustache (0.99.4)
|
||||
net-scp (1.0.4)
|
||||
|
@ -173,16 +180,16 @@ GEM
|
|||
net-ssh (2.5.2)
|
||||
net-ssh-gateway (1.1.0)
|
||||
net-ssh (>= 1.99.1)
|
||||
newrelic_rpm (3.3.5)
|
||||
nokogiri (1.5.4)
|
||||
omniauth (1.0.3)
|
||||
newrelic_rpm (3.4.0.1)
|
||||
nokogiri (1.5.5)
|
||||
omniauth (1.1.0)
|
||||
hashie (~> 1.2)
|
||||
rack
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
orm_adapter (0.0.7)
|
||||
paperclip (3.0.4)
|
||||
orm_adapter (0.4.0)
|
||||
paperclip (3.1.3)
|
||||
activemodel (>= 3.0.0)
|
||||
activerecord (>= 3.0.0)
|
||||
activesupport (>= 3.0.0)
|
||||
|
@ -192,9 +199,11 @@ GEM
|
|||
rails (~> 3.0)
|
||||
redis
|
||||
resque
|
||||
pg (0.13.2)
|
||||
pg (0.14.0)
|
||||
polyglot (0.3.3)
|
||||
posix-spawn (0.3.6)
|
||||
pygments.rb (0.2.13)
|
||||
rubypython (~> 0.5.3)
|
||||
rack (1.4.1)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
|
@ -230,21 +239,21 @@ GEM
|
|||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
raindrops (0.9.0)
|
||||
raindrops (0.10.0)
|
||||
rake (0.9.2.2)
|
||||
rdiscount (1.6.8)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
redcarpet (1.17.2)
|
||||
redis (2.2.2)
|
||||
redis-namespace (1.0.3)
|
||||
redis (< 3.0.0)
|
||||
redis (3.0.1)
|
||||
redis-namespace (1.2.0)
|
||||
redis (~> 3.0.0)
|
||||
redisk (0.2.2)
|
||||
redis (>= 0.1.1)
|
||||
redis-namespace (>= 0.1.0)
|
||||
resque (1.20.0)
|
||||
resque (1.21.0)
|
||||
multi_json (~> 1.0)
|
||||
redis-namespace (~> 1.0.2)
|
||||
redis-namespace (~> 1.0)
|
||||
sinatra (>= 0.9.2)
|
||||
vegas (~> 0.1.2)
|
||||
resque-status (0.3.3)
|
||||
|
@ -254,46 +263,50 @@ GEM
|
|||
resque_mailer (2.1.0)
|
||||
actionmailer (~> 3.0)
|
||||
rr (1.0.4)
|
||||
rspec (2.10.0)
|
||||
rspec-core (~> 2.10.0)
|
||||
rspec-expectations (~> 2.10.0)
|
||||
rspec-mocks (~> 2.10.0)
|
||||
rspec-core (2.10.1)
|
||||
rspec-expectations (2.10.0)
|
||||
rspec (2.11.0)
|
||||
rspec-core (~> 2.11.0)
|
||||
rspec-expectations (~> 2.11.0)
|
||||
rspec-mocks (~> 2.11.0)
|
||||
rspec-core (2.11.0)
|
||||
rspec-expectations (2.11.1)
|
||||
diff-lcs (~> 1.1.3)
|
||||
rspec-mocks (2.10.1)
|
||||
rspec-rails (2.10.1)
|
||||
rspec-mocks (2.11.1)
|
||||
rspec-rails (2.11.0)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
rspec (~> 2.10.0)
|
||||
rspec (~> 2.11.0)
|
||||
ruby-haml-js (0.0.3)
|
||||
execjs
|
||||
sprockets (>= 2.0.0)
|
||||
ruby-openid (2.1.8)
|
||||
ruby-openid (2.2.0)
|
||||
rubypython (0.5.3)
|
||||
blankslate (>= 2.1.2.3)
|
||||
ffi (~> 1.0.7)
|
||||
russian (0.6.0)
|
||||
i18n (>= 0.5.0)
|
||||
rvm-capistrano (1.2.2)
|
||||
rvm-capistrano (1.2.3)
|
||||
capistrano (>= 2.0.0)
|
||||
sanitize (2.0.3)
|
||||
nokogiri (>= 1.4.4, < 1.6)
|
||||
sass (3.1.19)
|
||||
sass (3.1.20)
|
||||
sass-rails (3.2.5)
|
||||
railties (~> 3.2.0)
|
||||
sass (>= 3.1.10)
|
||||
tilt (~> 1.3)
|
||||
shotgun (0.9)
|
||||
rack (>= 1.0)
|
||||
shoulda (3.0.1)
|
||||
shoulda-context (~> 1.0.0)
|
||||
shoulda-matchers (~> 1.0.0)
|
||||
shoulda (3.1.0)
|
||||
shoulda-context (~> 1.0)
|
||||
shoulda-matchers (~> 1.2)
|
||||
shoulda-context (1.0.0)
|
||||
shoulda-matchers (1.0.0)
|
||||
shoulda-matchers (1.2.0)
|
||||
activesupport (>= 3.0.0)
|
||||
sinatra (1.3.2)
|
||||
rack (~> 1.3, >= 1.3.6)
|
||||
rack-protection (~> 1.2)
|
||||
tilt (~> 1.3, >= 1.3.3)
|
||||
skinny (0.2.0)
|
||||
skinny (0.2.1)
|
||||
eventmachine (~> 0.12)
|
||||
thin (~> 1.2)
|
||||
sprockets (2.1.3)
|
||||
|
@ -302,22 +315,22 @@ GEM
|
|||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.6)
|
||||
state_machine (1.1.2)
|
||||
systemu (2.5.1)
|
||||
systemu (2.5.2)
|
||||
therubyracer (0.10.1)
|
||||
libv8 (~> 3.3.10)
|
||||
thin (1.3.1)
|
||||
thin (1.4.1)
|
||||
daemons (>= 1.0.9)
|
||||
eventmachine (>= 0.12.6)
|
||||
rack (>= 1.0.0)
|
||||
thor (0.15.2)
|
||||
thor (0.15.4)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.10)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.33)
|
||||
uglifier (1.2.4)
|
||||
uglifier (1.2.6)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (>= 1.0.2)
|
||||
multi_json (~> 1.3)
|
||||
unicorn (4.3.1)
|
||||
kgio (~> 2.6)
|
||||
rack
|
||||
|
@ -326,7 +339,7 @@ GEM
|
|||
macaddr (~> 1.0)
|
||||
vegas (0.1.11)
|
||||
rack (>= 1.0.0)
|
||||
warden (1.1.1)
|
||||
warden (1.2.1)
|
||||
rack (>= 1.0)
|
||||
whenever (0.7.3)
|
||||
activesupport (>= 2.3.4)
|
||||
|
@ -341,20 +354,21 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
RedCloth
|
||||
airbrake (~> 3.1.1)
|
||||
airbrake (~> 3.1.2)
|
||||
ancestry (~> 1.3.0)
|
||||
bluepill (~> 0.0.60)
|
||||
cancan (~> 1.6.7)
|
||||
cancan (= 1.6.7)
|
||||
cape
|
||||
capistrano
|
||||
capistrano_colors
|
||||
charlock_holmes (~> 0.6.8)
|
||||
coffee-rails (~> 3.2.2)
|
||||
compass-rails (~> 1.0.2)
|
||||
compass-rails (~> 1.0.3)
|
||||
creole
|
||||
devise (~> 2.0.4)
|
||||
devise (~> 2.1.2)
|
||||
diff-display (~> 0.0.1)
|
||||
factory_girl_rails (~> 3.4.0)
|
||||
factory_girl_rails (~> 3.5.0)
|
||||
github-linguist (~> 2.0.1)
|
||||
gollum (= 1.3.1)
|
||||
grack!
|
||||
grit!
|
||||
|
@ -365,12 +379,12 @@ DEPENDENCIES
|
|||
jquery-rails (~> 2.0.2)
|
||||
mailcatcher
|
||||
meta-tags (~> 1.2.5)
|
||||
newrelic_rpm (~> 3.3.5)
|
||||
omniauth (~> 1.0.3)
|
||||
newrelic_rpm (~> 3.4.0.1)
|
||||
omniauth (~> 1.1.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
paperclip (~> 3.0.4)
|
||||
paperclip (~> 3.1.3)
|
||||
perform_later (~> 1.3.0)
|
||||
pg (~> 0.13.2)
|
||||
pg (~> 0.14.0)
|
||||
rails (= 3.2.6)
|
||||
rails-backbone (~> 0.7.2)
|
||||
rails3-generators
|
||||
|
@ -378,11 +392,11 @@ DEPENDENCIES
|
|||
rdiscount
|
||||
redcarpet (= 1.17.2)
|
||||
redhillonrails_core!
|
||||
resque (~> 1.20.0)
|
||||
resque (~> 1.21.0)
|
||||
resque-status (~> 0.3.3)
|
||||
resque_mailer (~> 2.1.0)
|
||||
rr (~> 1.0.4)
|
||||
rspec-rails (~> 2.10.1)
|
||||
rspec-rails (~> 2.11.0)
|
||||
ruby-haml-js (~> 0.0.3)
|
||||
russian (~> 0.6.0)
|
||||
rvm-capistrano
|
||||
|
|
|
@ -17,6 +17,7 @@ class ApplicationController < ActionController::Base
|
|||
rescue_from CanCan::AccessDenied do |exception|
|
||||
redirect_to forbidden_url, :alert => t("flash.exception_message")
|
||||
end
|
||||
rescue_from Grit::NoSuchPathError, :with => :not_found
|
||||
|
||||
protected
|
||||
|
||||
|
@ -53,4 +54,8 @@ class ApplicationController < ActionController::Base
|
|||
"application"
|
||||
end
|
||||
end
|
||||
|
||||
def not_found
|
||||
raise ActionController::RoutingError.new('Not Found')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ class Projects::BuildListsController < Projects::BaseController
|
|||
Arch.where(:id => params[:arches]).each do |arch|
|
||||
Platform.main.where(:id => params[:build_for_platforms]).each do |build_for_platform|
|
||||
@build_list = @project.build_lists.build(params[:build_list])
|
||||
@build_list.commit_hash = @project.git_repository.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last || @build_list.project_version).first.id if @build_list.project_version
|
||||
@build_list.commit_hash = @project.repo.commits(@build_list.project_version.match(/^latest_(.+)/).to_a.last || @build_list.project_version).first.id if @build_list.project_version
|
||||
@build_list.build_for_platform = build_for_platform; @build_list.arch = arch; @build_list.user = current_user
|
||||
@build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i}
|
||||
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
|
||||
|
@ -98,7 +98,6 @@ class Projects::BuildListsController < Projects::BaseController
|
|||
else
|
||||
@build_list.fail_publish
|
||||
end
|
||||
|
||||
render :nothing => true, :status => 200
|
||||
end
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class Projects::CommentsController < Projects::BaseController
|
|||
|
||||
def find_commentable
|
||||
@commentable = params[:issue_id].present? && @project.issues.find_by_serial_id(params[:issue_id]) ||
|
||||
params[:commit_id].present? && @project.git_repository.commit(params[:commit_id])
|
||||
params[:commit_id].present? && @project.repo.commit(params[:commit_id])
|
||||
end
|
||||
|
||||
def find_or_build_comment
|
||||
|
|
|
@ -25,7 +25,7 @@ class Projects::CommitSubscribesController < Projects::BaseController
|
|||
protected
|
||||
|
||||
def find_commit
|
||||
@commit = @project.git_repository.commit(params[:commit_id])
|
||||
@commit = @project.repo.commit(params[:commit_id])
|
||||
@options = {:project_id => @project.id, :subscribeable_id => @commit.id.hex, :subscribeable_type => @commit.class.name, :user_id => current_user.id}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,36 +4,19 @@ class Projects::Git::BaseController < Projects::BaseController
|
|||
skip_before_filter :authenticate_user!, :only => [:show, :index, :blame, :raw, :archive] if APP_CONFIG['anonymous_access']
|
||||
load_and_authorize_resource :project
|
||||
|
||||
before_filter :find_git_repository
|
||||
before_filter :find_tags
|
||||
before_filter :find_branches
|
||||
before_filter :set_treeish
|
||||
before_filter :set_current_tag
|
||||
before_filter :set_current_branch
|
||||
before_filter :set_treeish_and_path
|
||||
before_filter :set_branch_and_tree
|
||||
|
||||
protected
|
||||
|
||||
def find_git_repository
|
||||
@git_repository = @project.git_repository
|
||||
end
|
||||
|
||||
def find_tags
|
||||
@tags = @git_repository.tags
|
||||
end
|
||||
|
||||
def find_branches
|
||||
@branches = @git_repository.branches
|
||||
end
|
||||
|
||||
def set_treeish
|
||||
def set_treeish_and_path
|
||||
@treeish = params[:treeish].presence || @project.default_branch
|
||||
@path = params[:path]
|
||||
end
|
||||
|
||||
def set_current_tag
|
||||
@current_tag = @tags.select{|t| t.name == @treeish }.first
|
||||
end
|
||||
|
||||
def set_current_branch
|
||||
@current_branch = @branches.select{|b| b.name == @treeish }.first
|
||||
def set_branch_and_tree
|
||||
@branch = @project.repo.branches.detect{|b| b.name == @treeish}
|
||||
@tree = @project.repo.tree(@treeish)
|
||||
# raise Grit::NoSuchPathError if @tree.blobs.blank?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,34 +1,17 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Projects::Git::BlobsController < Projects::Git::BaseController
|
||||
before_filter :find_tree
|
||||
before_filter :find_branch
|
||||
before_filter :set_path_blob
|
||||
before_filter :set_blob
|
||||
before_filter lambda {authorize! :write, @project}, :only => [:edit, :update]
|
||||
|
||||
def show
|
||||
redirect_to project_path(@project) and return unless @blob.present?
|
||||
if params[:raw]
|
||||
response.headers['Cache-Control'] = "public, max-age=#{12.hours.to_i}"
|
||||
response.headers['Content-Type'] = @blob.mime_type
|
||||
response.headers['Content-Disposition'] = 'inline'
|
||||
render(:text => @blob.data) and return
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
redirect_to project_path(@project) and return unless @blob.present?
|
||||
authorize! :write, @project
|
||||
end
|
||||
|
||||
def update
|
||||
redirect_to project_path(@project) and return unless @blob.present?
|
||||
authorize! :write, @project
|
||||
# Here might be callbacks for notification purposes:
|
||||
# @git_repository.after_update_file do |repo, sha|
|
||||
# end
|
||||
|
||||
res = @git_repository.update_file(params[:path], params[:content].gsub("\r", ''),
|
||||
if @project.update_file(params[:path], params[:content].gsub("\r", ''),
|
||||
:message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish)
|
||||
if res
|
||||
flash[:notice] = t("flash.blob.successfully_updated", :name => params[:path])
|
||||
else
|
||||
flash[:notice] = t("flash.blob.updating_error", :name => params[:path])
|
||||
|
@ -37,28 +20,17 @@ class Projects::Git::BlobsController < Projects::Git::BaseController
|
|||
end
|
||||
|
||||
def blame
|
||||
@blame = Grit::Blob.blame(@git_repository.repo, @commit.id, @path)
|
||||
@blame = Grit::Blob.blame(@project.repo, @commit.id, @path)
|
||||
end
|
||||
|
||||
def raw
|
||||
redirect_to project_path(@project) and return unless @blob.present?
|
||||
headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"]
|
||||
render :text => @blob.data, :content_type => @blob.mime_type
|
||||
send_data @blob.data, :type => @blob.content_type, :disposition => @blob.disposition
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_branch
|
||||
@branch = @project.branch(@treeish)
|
||||
end
|
||||
|
||||
def set_path_blob
|
||||
@path = params[:path]
|
||||
@blob = @tree / @path
|
||||
@commit = @git_repository.log(@treeish, @path, :max_count => 1).first
|
||||
end
|
||||
|
||||
def find_tree
|
||||
@tree = @git_repository.tree(@treeish)
|
||||
def set_blob
|
||||
@blob = @tree / @path or raise Grit::NoSuchPathError
|
||||
@commit = @project.repo.log(@treeish, @path, :max_count => 1).first
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,42 +1,19 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Projects::Git::CommitsController < Projects::Git::BaseController
|
||||
helper_method :split_commits_by_date
|
||||
|
||||
def index
|
||||
@branch_name = params[:treeish] || @project.default_branch
|
||||
@branch = @project.branch(@branch_name)
|
||||
@path = params[:path]
|
||||
|
||||
if @path.present?
|
||||
@commits = @git_repository.repo.log(@branch_name, @path)
|
||||
@render_paginate = false
|
||||
@commits = @project.repo.log(@treeish, @path)
|
||||
else
|
||||
@commits, @page, @last_page = @git_repository.paginate_commits(@branch_name, :page => params[:page])
|
||||
@render_paginate = true
|
||||
@commits, @page, @last_page = @project.paginate_commits(@treeish, :page => params[:page])
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@commit = @git_repository.commit(params[:id]) # @git_repository.commits(params[:id]).first
|
||||
|
||||
@commit = @project.repo.commit(params[:id])
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.diff { render :text => (@commit.diffs.map(&:diff).join("\n") rescue ''), :content_type => "text/plain" }
|
||||
format.patch { render :text => (@commit.to_patch rescue ''), :content_type => "text/plain" }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def split_commits_by_date(commits)
|
||||
res = commits.sort{|x, y| y.authored_date <=> x.authored_date}.inject({}) do |h, commit|
|
||||
dt = commit.authored_date
|
||||
h[dt.year] ||= {}
|
||||
h[dt.year][dt.month] ||= {}
|
||||
h[dt.year][dt.month][dt.day] ||= []
|
||||
h[dt.year][dt.month][dt.day] << commit
|
||||
h
|
||||
end
|
||||
return res
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,32 +1,21 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Projects::Git::TreesController < Projects::Git::BaseController
|
||||
before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => 'show'
|
||||
|
||||
def show
|
||||
redirect_to project_path(@project) and return if params[:treeish] == @project.default_branch and params[:path].blank?
|
||||
|
||||
@path = params[:path]
|
||||
@tree = @git_repository.tree(@treeish)
|
||||
@branch = @project.branch(@treeish)
|
||||
|
||||
# @commit = @git_repository.commits(@treeish, 1).first
|
||||
# Raises Grit::Git::GitTimeout
|
||||
@commit = @branch.present? ? @branch.commit() : @git_repository.log(@treeish, @path, :max_count => 1).first
|
||||
render "empty" and return unless @commit
|
||||
|
||||
@tree = @tree / @path if @path
|
||||
@tree = @tree / @path if @path.present?
|
||||
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first
|
||||
render 'empty' unless @commit
|
||||
end
|
||||
|
||||
def archive
|
||||
treeish = params[:treeish].presence || @project.default_branch
|
||||
format = params[:format] || 'tar'
|
||||
commit = @project.git_repository.log(treeish, nil, :max_count => 1).first
|
||||
if !commit or !['tar', 'zip'].include?(format)
|
||||
raise ActiveRecord::RecordNotFound#("Couldn't send Project archive with id=#{@project.id}, treeish=#{treeish} and format=#{format}")
|
||||
end
|
||||
name = "#{@project.owner.uname}-#{@project.name}#{@project.tags.include?(treeish) ? "-#{treeish}" : ''}-#{commit.id[0..19]}"
|
||||
fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}"
|
||||
@commit = @project.repo.log(@treeish, nil, :max_count => 1).first
|
||||
raise Grit::NoSuchPathError unless @commit
|
||||
name = "#{@project.owner.uname}-#{@project.name}#{@project.repo.tags.include?(@treeish) ? "-#{@treeish}" : ''}-#{@commit.id[0..19]}"
|
||||
fullname = "#{name}.#{params[:format] == 'tar' ? 'tar.gz' : 'zip'}"
|
||||
file = Tempfile.new fullname, 'tmp'
|
||||
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
|
||||
system("cd #{@project.path}; git archive --format=#{params[:format]} --prefix=#{name}/ #{@treeish} #{params[:format] == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
|
||||
file.close
|
||||
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
|
||||
send_file file.path, :disposition => 'attachment', :type => "application/#{params[:format] == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Projects::ProjectsController < Projects::BaseController
|
||||
before_filter :authenticate_user!
|
||||
load_and_authorize_resource
|
||||
# TODO WTF ? fork, update, sections not authorize
|
||||
before_filter do |controller|
|
||||
authorize! params[:action].to_sym, @project if params[:action] != 'index'
|
||||
end
|
||||
load_and_authorize_resource :id_param => :project_name # to force member actions load
|
||||
|
||||
def index
|
||||
@projects = Project.accessible_by(current_ability, :membered)
|
||||
|
|
|
@ -4,7 +4,7 @@ module GitHelper
|
|||
def render_path
|
||||
# TODO: Looks ugly, rewrite with clear mind.
|
||||
if @path.present?
|
||||
if @treeish == "master"
|
||||
if @treeish == @project.default_branch
|
||||
res = "#{link_to @project.name, tree_path(@project)} / "
|
||||
else
|
||||
res = "#{link_to @project.name, tree_path(@project, @treeish)} / "
|
||||
|
@ -36,22 +36,6 @@ module GitHelper
|
|||
res.html_safe
|
||||
end
|
||||
|
||||
def render_blob(blob)
|
||||
blob.data.split("\n").collect do |line|
|
||||
content_tag :div, line.present? ? h(line) : tag(:br)
|
||||
end.join.html_safe
|
||||
end
|
||||
|
||||
def choose_render_way(blob)
|
||||
case
|
||||
when blob.mime_type.match(/image/); :image
|
||||
when blob.binary?; :binary
|
||||
else
|
||||
@text = @blob.data.split("\n")
|
||||
:text
|
||||
end
|
||||
end
|
||||
|
||||
def iterate_path(path, &block)
|
||||
path.split(File::SEPARATOR).inject('') do |a, e|
|
||||
if e != '.' and e != '..'
|
||||
|
@ -71,10 +55,29 @@ module GitHelper
|
|||
current = url_for(p).split('?', 2).first
|
||||
|
||||
res = []
|
||||
res << [I18n.t('layout.git.repositories.commits'), [truncate(params[:treeish], :length => 20)]] unless (project.branches + project.tags).map(&:name).include?(params[:treeish] || project.default_branch)
|
||||
res << [I18n.t('layout.git.repositories.branches'), project.branches.map{|b| [truncate(b.name, :length => 20), url_for(p.merge :treeish => b.name).split('?', 2).first]}]
|
||||
res << [I18n.t('layout.git.repositories.tags'), project.tags.map{|t| [truncate(t.name, :length => 20), url_for(p.merge :treeish => t.name).split('?', 2).first]}]
|
||||
res << [I18n.t('layout.git.repositories.commits'), [truncate(params[:treeish], :length => 20)]] unless (project.repo.branches + project.repo.tags).map(&:name).include?(params[:treeish] || project.default_branch)
|
||||
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map{|b| [truncate(b.name, :length => 20), url_for(p.merge :treeish => b.name).split('?', 2).first]}]
|
||||
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map{|t| [truncate(t.name, :length => 20), url_for(p.merge :treeish => t.name).split('?', 2).first]}]
|
||||
|
||||
grouped_options_for_select(res, current)
|
||||
end
|
||||
|
||||
def versions_for_group_select(project)
|
||||
[
|
||||
['Branches', project.repo.branches.map{|b| "latest_#{b.name}"}],
|
||||
['Tags', project.repo.tags.map(&:name)]
|
||||
]
|
||||
end
|
||||
|
||||
def split_commits_by_date(commits)
|
||||
commits.sort{|x, y| y.authored_date <=> x.authored_date}.inject({}) do |h, commit|
|
||||
dt = commit.authored_date
|
||||
h[dt.year] ||= {}
|
||||
h[dt.year][dt.month] ||= {}
|
||||
h[dt.year][dt.month][dt.day] ||= []
|
||||
h[dt.year][dt.month][dt.day] << commit
|
||||
h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
change_type = record.change_type
|
||||
branch_name = record.refname.split('/').last
|
||||
|
||||
last_commits = record.project.git_repository.repo.log(branch_name, nil).first(3)
|
||||
last_commits = record.project.repo.log(branch_name, nil).first(3)
|
||||
first_commiter = User.find_by_email(last_commits[0].author.email) unless last_commits.blank?
|
||||
last_commits = last_commits.collect do |commit| #:author => 'author'
|
||||
[commit.sha, commit.message]
|
||||
|
@ -87,7 +87,7 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
else
|
||||
kind = 'git_new_push_notification'
|
||||
options = {:project_id => record.project.id, :project_name => record.project.name, :last_commits => last_commits, :branch_name => branch_name,
|
||||
:change_type => change_type, :user_email => record.project.git_repository.repo.log(branch_name, nil).first.author.email,
|
||||
:change_type => change_type, :user_email => record.project.repo.repo.log(branch_name, nil).first.author.email,
|
||||
:project_owner => record.project.owner.uname}
|
||||
options.merge!({:user_id => first_commiter.id, :user_name => first_commiter.name}) if first_commiter
|
||||
end
|
||||
|
|
|
@ -189,7 +189,7 @@ class BuildList < ActiveRecord::Base
|
|||
# TODO: remove 'return' after deployment ABF kernel 2.0
|
||||
return if pkg.nil? # For old client that does not sends data about packages
|
||||
self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}"
|
||||
system("cd #{self.project.git_repository.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit
|
||||
system("cd #{self.project.repo.path} && git tag #{self.package_version} #{self.commit_hash}") # TODO REDO through grit
|
||||
save
|
||||
end
|
||||
|
||||
|
|
|
@ -20,15 +20,7 @@ class BuildList::Filter
|
|||
build_lists = build_lists.scoped_to_is_circle(@options[:is_circle]) if @options[:is_circle].present?
|
||||
build_lists = build_lists.scoped_to_project_name(@options[:project_name]) if @options[:project_name]
|
||||
build_lists = build_lists.by_mass_build(@options[:mass_build_id]) if @options[:mass_build_id]
|
||||
|
||||
# TODO [BuildList#created_at filters] Uncomment here and in build_lists/_filter.html.haml to return filters
|
||||
#
|
||||
# if @options[:created_at_start] || @options[:created_at_end]
|
||||
# build_lists = build_lists.for_creation_date_period(@options[:created_at_start], @options[:created_at_end])
|
||||
# end
|
||||
if @options[:updated_at_start] || @options[:updated_at_end]
|
||||
build_lists = build_lists.for_notified_date_period(@options[:updated_at_start], @options[:updated_at_end])
|
||||
end
|
||||
build_lists = build_lists.for_notified_date_period(@options[:updated_at_start], @options[:updated_at_end]) if @options[:updated_at_start] || @options[:updated_at_end]
|
||||
end
|
||||
|
||||
build_lists
|
||||
|
@ -49,8 +41,6 @@ class BuildList::Filter
|
|||
@options = HashWithIndifferentAccess.new(options.reverse_merge({
|
||||
:ownership => nil,
|
||||
:status => nil,
|
||||
:created_at_start => nil,
|
||||
:created_at_end => nil,
|
||||
:updated_at_start => nil,
|
||||
:updated_at_end => nil,
|
||||
:arch_id => nil,
|
||||
|
@ -64,8 +54,6 @@ class BuildList::Filter
|
|||
|
||||
@options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'index' : 'owned')
|
||||
@options[:status] = @options[:status].present? ? @options[:status].to_i : nil
|
||||
@options[:created_at_start] = build_date_from_params(:created_at_start, @options)
|
||||
@options[:created_at_end] = build_date_from_params(:created_at_end, @options)
|
||||
@options[:updated_at_start] = build_date_from_params(:updated_at_start, @options)
|
||||
@options[:updated_at_end] = build_date_from_params(:updated_at_end, @options)
|
||||
@options[:project_version] = @options[:project_version].presence
|
||||
|
|
|
@ -15,7 +15,7 @@ class Comment < ActiveRecord::Base
|
|||
attr_accessible :body
|
||||
|
||||
def commentable
|
||||
commit_comment? ? project.git_repository.commit(commentable_id.to_s(16)) : super
|
||||
commit_comment? ? project.repo.commit(commentable_id.to_s(16)) : super
|
||||
end
|
||||
|
||||
def commentable=(c)
|
||||
|
|
|
@ -1,130 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class Git::Repository
|
||||
delegate :commits, :commit, :tree, :tags, :heads, :commit_count, :log, :branches, :to => :repo
|
||||
|
||||
attr_accessor :path, :name, :repo, :last_actor
|
||||
|
||||
def initialize(path)
|
||||
@path = path
|
||||
@update_callbacks = []
|
||||
end
|
||||
|
||||
def master
|
||||
commits('master', 1).first
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
def repo
|
||||
@repo ||= Grit::Repo.new(path) rescue Grit::Repo.new(GAP_REPO_PATH)
|
||||
end
|
||||
|
||||
# Adds a callback to be fired after update file.
|
||||
#
|
||||
# block - A block that expects this Git::Repository instance and the created
|
||||
# commit's SHA1 as the arguments.
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# after_update_file do |repo, sha|
|
||||
# # callback body
|
||||
# end
|
||||
#
|
||||
# Returns nothing.
|
||||
def after_update_file(&block)
|
||||
@update_callbacks << block
|
||||
end
|
||||
|
||||
# Writes file to repo and runs 'after_update_file' callbacks
|
||||
#
|
||||
# path - path to file in repository
|
||||
# data - new content of file
|
||||
# options - an optional Hash of options
|
||||
# :head - branch name to write this commit to
|
||||
# (Default: 'master')
|
||||
# :actor - author of this commit. (See Git::Repository#get_actor)
|
||||
# (Default: nil)
|
||||
# :message - commit message
|
||||
# (Default: "Updated file <filename>")
|
||||
#
|
||||
# Returns commits sha if committing was successful and false otherwise
|
||||
def update_file(path, data, options = {})
|
||||
head = options[:head].to_s || 'master'
|
||||
actor = get_actor(options[:actor])
|
||||
filename = File.split(path).last
|
||||
message = options[:message]
|
||||
message = "Updated file #{filename}" if message.nil? or message.empty?
|
||||
|
||||
# can not write to unexisted branch
|
||||
return false if branches.select{|b| b.name == head}.size != 1
|
||||
|
||||
parent = commits(head).first
|
||||
|
||||
index = repo.index
|
||||
index.read_tree(parent.tree.id)
|
||||
|
||||
# can not create new file
|
||||
return false if (index.current_tree / path).nil?
|
||||
|
||||
index.add(path, data)
|
||||
sha = index.commit(message, :parents => [parent], :actor => actor,
|
||||
:last_tree => parent.tree.id, :head => head)
|
||||
# call all defined callbacks
|
||||
@update_callbacks.each do |cb|
|
||||
cb.call(self, sha)
|
||||
end
|
||||
sha
|
||||
end
|
||||
|
||||
def self.create(path)
|
||||
repo = Grit::Repo.init_bare(path)
|
||||
repo.enable_daemon_serve
|
||||
end
|
||||
|
||||
def paginate_commits(treeish, options = {})
|
||||
options[:page] = 1 unless options[:page].present?
|
||||
options[:page] = options[:page].to_i
|
||||
|
||||
options[:per_page] = 20 unless options[:per_page].present?
|
||||
options[:per_page] = options[:per_page].to_i
|
||||
|
||||
skip = options[:per_page] * (options[:page] - 1)
|
||||
last_page = (skip + options[:per_page]) >= commit_count(treeish)
|
||||
|
||||
[commits(treeish, options[:per_page], skip), options[:page], last_page]
|
||||
end
|
||||
|
||||
# Pretty object inspection
|
||||
def inspect
|
||||
%Q{#<Git::Repository "#{@path}">}
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Creates new Grit::Actor instance
|
||||
#
|
||||
# Might be:
|
||||
# * A Hash containing :name and :email
|
||||
# * An instance of Grit::Actor
|
||||
# * A String like "John Doe <j.doe@example.com>
|
||||
# * Any object that responds to `name` and `email` methods
|
||||
def get_actor(actor = nil)
|
||||
@last_actor = case actor.class.to_s
|
||||
when 'Grit::Actor' then options[:actor]
|
||||
when 'Hash' then Grit::Actor.new(actor[:name], actor[:email])
|
||||
when 'String' then Grit::Actor.from_stirng(actor)
|
||||
else begin
|
||||
if actor.respond_to?(:name) and actor.respond_to?(:email)
|
||||
Grit::Actor.new(actor.name, actor.email)
|
||||
else
|
||||
config = Grit::Config.new(repo)
|
||||
Grit::Actor.new(config['user.name'], config['user.email'])
|
||||
end
|
||||
end
|
||||
end
|
||||
@last_actor
|
||||
end
|
||||
|
||||
end
|
|
@ -25,9 +25,6 @@ class Project < ActiveRecord::Base
|
|||
validates :owner, :presence => true
|
||||
validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS }
|
||||
|
||||
validates_attachment_size :srpm, :less_than => 500.megabytes
|
||||
validates_attachment_content_type :srpm, :content_type => ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], :message => I18n.t('layout.invalid_content_type')
|
||||
|
||||
attr_accessible :name, :description, :visibility, :srpm, :is_package, :default_branch, :has_issues, :has_wiki
|
||||
attr_readonly :name
|
||||
|
||||
|
@ -40,35 +37,51 @@ class Project < ActiveRecord::Base
|
|||
scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id = #{ repository_id }))") }
|
||||
|
||||
after_create :attach_to_personal_repository
|
||||
after_create :create_git_repo
|
||||
after_save :create_wiki
|
||||
after_commit(:on => :create) {|p| p.fork_git_repo unless p.is_root?} # later with resque
|
||||
|
||||
after_destroy :destroy_git_repo
|
||||
after_destroy :destroy_wiki
|
||||
after_commit(:on => :create) {|p| p.import_attached_srpm if p.srpm?}# later with resque # should be after create_git_repo
|
||||
# after_rollback lambda { destroy_git_repo rescue true if new_record? }
|
||||
|
||||
has_ancestry
|
||||
|
||||
has_attached_file :srpm
|
||||
|
||||
include Modules::Models::Owner
|
||||
include Modules::Models::Git
|
||||
include Modules::Models::Wiki
|
||||
|
||||
def to_param
|
||||
name
|
||||
end
|
||||
|
||||
def self.find_by_owner_and_name(owner_name, project_name)
|
||||
class << self
|
||||
def find_by_owner_and_name(owner_name, project_name)
|
||||
owner = User.find_by_uname(owner_name) || Group.find_by_uname(owner_name) || User.by_uname(owner_name).first || Group.by_uname(owner_name).first and
|
||||
scoped = where(:owner_id => owner.id, :owner_type => owner.class) and
|
||||
scoped.find_by_name(project_name) || scoped.by_name(project_name).first
|
||||
# owner.projects.find_by_name(project_name) || owner.projects.by_name(project_name).first # TODO force this work?
|
||||
end
|
||||
|
||||
def self.find_by_owner_and_name!(owner_name, project_name)
|
||||
def find_by_owner_and_name!(owner_name, project_name)
|
||||
find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
def to_param
|
||||
name
|
||||
end
|
||||
|
||||
def members
|
||||
collaborators + groups.map(&:members).flatten
|
||||
end
|
||||
|
||||
def platforms
|
||||
@platforms ||= repositories.map(&:platform).uniq
|
||||
end
|
||||
|
||||
def owner_and_admin_ids
|
||||
recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
|
||||
recipients = recipients | [self.owner_id] if self.owner_type == 'User'
|
||||
recipients
|
||||
end
|
||||
|
||||
def public?
|
||||
visibility == 'open'
|
||||
end
|
||||
|
||||
def owner?(user)
|
||||
owner == user
|
||||
end
|
||||
|
||||
def build_for(platform, user, arch = 'i586', auto_publish = false, mass_build_id = nil, priority = 0)
|
||||
# Select main and project platform repository(contrib, non-free and etc)
|
||||
|
@ -93,85 +106,6 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def tags
|
||||
self.git_repository.tags #.sort_by{|t| t.name.gsub(/[a-zA-Z.]+/, '').to_i}
|
||||
end
|
||||
|
||||
def branches
|
||||
self.git_repository.branches
|
||||
end
|
||||
|
||||
def last_active_branch
|
||||
@last_active_branch ||= branches.inject do |r, c|
|
||||
r_last = r.commit.committed_date || r.commit.authored_date unless r.nil?
|
||||
c_last = c.commit.committed_date || c.commit.authored_date
|
||||
if r.nil? or r_last < c_last
|
||||
r = c
|
||||
end
|
||||
r
|
||||
end
|
||||
@last_active_branch
|
||||
end
|
||||
|
||||
def branch(name = nil)
|
||||
name = default_branch if name.blank?
|
||||
branches.select{|b| b.name == name}.first
|
||||
end
|
||||
|
||||
def tree_info(tree, treeish = nil, path = nil)
|
||||
treeish = tree.id unless treeish.present?
|
||||
# initialize result as hash of <tree_entry> => nil
|
||||
res = (tree.trees.sort + tree.blobs.sort).inject({}){|h, e| h.merge!({e => nil})}
|
||||
# fills result vith commits that describes this file
|
||||
res = res.inject(res) do |h, (entry, commit)|
|
||||
# only if commit == nil ...
|
||||
if commit.nil? and entry.respond_to? :name
|
||||
# ... find last commit corresponds to this file ...
|
||||
c = git_repository.log(treeish, File.join([path, entry.name].compact), :max_count => 1).first
|
||||
# ... and add it to result.
|
||||
h[entry] = c
|
||||
# find another files, that linked to this commit and set them their commit
|
||||
# c.diffs.map{|diff| diff.b_path.split(File::SEPARATOR, 2).first}.each do |name|
|
||||
# h.each_pair do |k, v|
|
||||
# h[k] = c if k.name == name and v.nil?
|
||||
# end
|
||||
# end
|
||||
end
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
def versions
|
||||
tags.map(&:name) + branches.map{|b| "latest_#{b.name}"}
|
||||
end
|
||||
|
||||
def versions_for_group_select
|
||||
[
|
||||
['Branches', branches.map{|b| "latest_#{b.name}"}],
|
||||
['Tags', tags.map(&:name)]
|
||||
]
|
||||
end
|
||||
|
||||
def members
|
||||
collaborators + groups.map(&:members).flatten
|
||||
end
|
||||
|
||||
def git_repository
|
||||
@git_repository ||= Git::Repository.new(path)
|
||||
end
|
||||
|
||||
def git_repo_name
|
||||
File.join owner.uname, name
|
||||
end
|
||||
|
||||
def wiki_repo_name
|
||||
File.join owner.uname, "#{name}.wiki"
|
||||
end
|
||||
|
||||
def public?
|
||||
visibility == 'open'
|
||||
end
|
||||
|
||||
def fork(new_owner)
|
||||
dup.tap do |c|
|
||||
c.parent_id = id
|
||||
|
@ -181,12 +115,8 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def path
|
||||
build_path(git_repo_name)
|
||||
end
|
||||
|
||||
def wiki_path
|
||||
build_wiki_path(git_repo_name)
|
||||
def human_average_build_time
|
||||
I18n.t("layout.projects.human_average_build_time", {:hours => (average_build_time/3600).to_i, :minutes => (average_build_time%3600/60).to_i})
|
||||
end
|
||||
|
||||
def xml_rpc_create(repository)
|
||||
|
@ -207,97 +137,9 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def platforms
|
||||
@platforms ||= repositories.map(&:platform).uniq
|
||||
end
|
||||
|
||||
def import_srpm(srpm_path = srpm.path, branch_name = 'import')
|
||||
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm_path} #{path} #{branch_name} >> /dev/null 2>&1")
|
||||
end
|
||||
|
||||
def owner?(user)
|
||||
owner == user
|
||||
end
|
||||
|
||||
def owner_and_admin_ids
|
||||
recipients = self.relations.by_role('admin').where(:actor_type => 'User').map { |rel| rel.read_attribute(:actor_id) }
|
||||
recipients = recipients | [self.owner_id] if self.owner_type == 'User'
|
||||
recipients
|
||||
end
|
||||
|
||||
def human_average_build_time
|
||||
time = average_build_time
|
||||
I18n.t("layout.projects.human_average_build_time", {:hours => (time/3600).to_i, :minutes => (time%3600/60).to_i})
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def build_path(dir)
|
||||
File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.git")
|
||||
end
|
||||
|
||||
def build_wiki_path(dir)
|
||||
File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.wiki.git")
|
||||
end
|
||||
|
||||
def attach_to_personal_repository
|
||||
repositories << self.owner.personal_repository if !repositories.exists?(:id => self.owner.personal_repository)
|
||||
end
|
||||
|
||||
def create_git_repo
|
||||
if is_root?
|
||||
Grit::Repo.init_bare(path)
|
||||
write_hook
|
||||
end
|
||||
end
|
||||
|
||||
def fork_git_repo
|
||||
dummy = Grit::Repo.new(path) rescue parent.git_repository.repo.fork_bare(path)
|
||||
write_hook
|
||||
end
|
||||
later :fork_git_repo, :queue => :fork_import
|
||||
|
||||
def destroy_git_repo
|
||||
FileUtils.rm_rf path
|
||||
end
|
||||
|
||||
def import_attached_srpm
|
||||
if srpm?
|
||||
import_srpm # srpm.path
|
||||
self.srpm = nil; save # clear srpm
|
||||
end
|
||||
end
|
||||
later :import_attached_srpm, :queue => :fork_import
|
||||
|
||||
def create_wiki
|
||||
if has_wiki && !FileTest.exist?(wiki_path)
|
||||
Grit::Repo.init_bare(wiki_path)
|
||||
wiki = Gollum::Wiki.new(wiki_path, {:base_path => Rails.application.routes.url_helpers.project_wiki_index_path(owner, self)})
|
||||
wiki.write_page('Home', :markdown, I18n.t("wiki.seed.welcome_content"),
|
||||
{:name => owner.name, :email => owner.email, :message => 'Initial commit'})
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_wiki
|
||||
FileUtils.rm_rf wiki_path
|
||||
end
|
||||
|
||||
def write_hook
|
||||
is_production = Rails.env == "production"
|
||||
hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook")
|
||||
FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook)
|
||||
File.open(hook, 'a') do |f|
|
||||
s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rake hook:enqueue[$owner,$reponame,$newrev,$oldrev,$ref,$newrev_type,$oldrev_type]\""
|
||||
s << " > /dev/null 2>&1" if is_production
|
||||
s << "\ndone\n"
|
||||
f.write(s)
|
||||
f.chmod(0755)
|
||||
end
|
||||
|
||||
hook_file = File.join(path, 'hooks', 'post-receive')
|
||||
FileUtils.cp(hook, hook_file)
|
||||
FileUtils.rm_rf(hook)
|
||||
|
||||
rescue Exception # FIXME
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
=image_tag 'zip.png', :alt => 'ZIP'
|
||||
%b.caret
|
||||
%ul.dropdown-menu
|
||||
%li=link_to "tar.gz", archive_path(project, 'tar', @treeish)
|
||||
%li=link_to "zip", archive_path(project, 'zip', @treeish)
|
||||
%li=link_to "tar.gz", archive_path(project, @treeish, 'tar')
|
||||
%li=link_to "zip", archive_path(project, @treeish, 'zip')
|
||||
|
||||
= text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name', :spellcheck => 'false', :readonly => true
|
||||
.git_help ?
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
- content_for :submenu do
|
||||
- act = action_name.to_sym; contr = controller_name.to_sym
|
||||
- act = action_name.to_sym; contr = controller_name.to_sym; treeish = params[:treeish].presence || @project.default_branch
|
||||
.left
|
||||
.table-sort-left=image_tag visibility_icon(@project.visibility)
|
||||
.table-sort-right=@project.name
|
||||
%nav
|
||||
%ul
|
||||
%li= link_to t("project_menu.project"), project_path(@project), :class => (act.in?([:show, :edit]) && contr.in?([:trees, :blobs]) ? 'active' : nil)
|
||||
%li= link_to t("project_menu.commits"), commits_path(@project), :class => (act.in?([:index, :show]) && contr == :commits ? 'active' : nil)
|
||||
%li= link_to t("project_menu.project"), tree_path(@project, treeish), :class => (act.in?([:show, :edit]) && contr.in?([:trees, :blobs]) ? 'active' : nil)
|
||||
%li= link_to t("project_menu.commits"), commits_path(@project, treeish), :class => (act.in?([:index, :show]) && contr == :commits ? 'active' : nil)
|
||||
- if @project.is_package and can?(:read, @project => BuildList)
|
||||
%li= link_to t("project_menu.builds"), project_build_lists_path(@project), :class => (contr == :build_lists ? 'active' : nil)
|
||||
- if @project.has_issues
|
||||
|
|
|
@ -13,10 +13,7 @@
|
|||
%h3= t("activerecord.attributes.build_list.save_to_platform")
|
||||
.lineForm= f.select :save_to_platform_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.platform.id]}
|
||||
%h3= t("activerecord.attributes.build_list.project_version")
|
||||
- if controller.action_name == 'new'
|
||||
.lineForm= f.select :project_version, @project.versions_for_group_select, :selected => "latest_" + @project.default_branch
|
||||
- else
|
||||
.lineForm= f.select :project_version, @project.versions_for_group_select
|
||||
.lineForm= f.select :project_version, versions_for_group_select(@project), :selected => params[:build_list].try(:fetch, :project_version) || "latest_" + @project.default_branch
|
||||
%h3= t("activerecord.attributes.build_list.arch")
|
||||
- Arch.recent.each do |arch|
|
||||
.both
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
= render 'fork'
|
||||
.both
|
||||
|
||||
= form_tag blob_path(@project, @treeish, @path), :name => 'blob-editor', :method => :put do
|
||||
= form_tag edit_blob_path(@project, @treeish, @path), :name => 'blob-editor', :method => :put do
|
||||
.file= text_area_tag :content, @blob.data, :id => 'code'
|
||||
|
||||
.both
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
%table.table.blob
|
||||
%tr
|
||||
%td.lines
|
||||
%td.blob
|
||||
:plain
|
||||
<br/>
|
||||
<pre>#{link_to @blob.basename, raw_path(@project, @treeish, @path)}</pre>
|
||||
<br/>
|
|
@ -0,0 +1,8 @@
|
|||
%table.table.blob
|
||||
%tr
|
||||
%td.lines
|
||||
%td.blob
|
||||
:plain
|
||||
<br/>
|
||||
<center><img src='#{raw_path(@project, @treeish, @path)}'/></center>
|
||||
<br/>
|
|
@ -0,0 +1,6 @@
|
|||
.gutter= render_line_numbers(@blob.loc)
|
||||
#output.formatted.cm-s-default
|
||||
%pre#code
|
||||
:preserve
|
||||
#{h(@blob.data).html_safe}
|
||||
.both
|
|
@ -1,40 +1,14 @@
|
|||
/ - raise @blob.file_mime_type.inspect
|
||||
%h3= t("layout.projects.files_in_project")
|
||||
.files
|
||||
.l= render 'whereami'
|
||||
= render 'fork'
|
||||
.both
|
||||
|
||||
- render_way = choose_render_way(@blob)
|
||||
.file
|
||||
.top= render 'top', :render_way => render_way
|
||||
.data
|
||||
- case render_way
|
||||
- when :image
|
||||
%table.table.blob
|
||||
%tr
|
||||
%td.lines
|
||||
%td.blob
|
||||
:plain
|
||||
<br/>
|
||||
<center> <img src='?raw=true'/></center>
|
||||
<br/>
|
||||
- when :text
|
||||
.gutter= render_line_numbers(@text.length)
|
||||
#output.formatted.cm-s-default
|
||||
%pre#code
|
||||
=#{render_blob(@blob)}
|
||||
:preserve
|
||||
#{h(@blob.data).html_safe}
|
||||
.both
|
||||
- when :binary
|
||||
%table.table.blob
|
||||
%tr
|
||||
%td.lines
|
||||
%td.blob
|
||||
:plain
|
||||
<br/>
|
||||
<pre>#{ link_to @blob.basename, raw_path(@project, @treeish, @path) }</pre>
|
||||
<br/>
|
||||
.top= render 'top'
|
||||
.data= render "render_as_#{@blob.render_as}"
|
||||
|
||||
:javascript
|
||||
$(document).ready(function() {
|
||||
var text = $('#code').text().replace(/&/gi, '&');
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
.l
|
||||
= @blob.mode
|
||||
\|
|
||||
- if render_way == :text
|
||||
#{@text.length} lines (#{@text.select{|s| s.strip.length > 0}.length} sloc)
|
||||
- if @blob.render_as == :text
|
||||
#{@blob.loc} lines (#{@blob.sloc} sloc)
|
||||
\|
|
||||
= number_to_human_size @blob.size
|
||||
.r
|
||||
- if render_way == :text and can? :write, @project and @treeish.in? @project.branches.map(&:name)
|
||||
- if @blob.render_as == :text and can? :write, @project and @branch.present?
|
||||
= link_to "Edit", edit_blob_path(@project, @treeish, @path)
|
||||
\|
|
||||
- if render_way == :text and params[:action] != 'show'
|
||||
- if @blob.render_as == :text and params[:action] != 'show'
|
||||
= link_to "Normal", blob_path(@project, @treeish, @path)
|
||||
\|
|
||||
= link_to "Raw", raw_path(@project, @treeish, @path)
|
||||
\|
|
||||
- if render_way == :text and params[:action] != 'blame'
|
||||
- if @blob.render_as == :text and params[:action] != 'blame'
|
||||
= link_to "Blame", blame_path(@project, @treeish, @path)
|
||||
\|
|
||||
= link_to "History", commits_path(@project, @treeish, @path)
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
.l= render 'whereami'
|
||||
.both
|
||||
|
||||
- render_way = choose_render_way(@blob)
|
||||
.file
|
||||
.top= render 'top', :render_way => render_way
|
||||
.top= render 'top'
|
||||
.blame_data= render 'blame_table' if @blame.first.first.present?
|
||||
|
|
|
@ -7,4 +7,4 @@
|
|||
.r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path)
|
||||
.clear
|
||||
|
||||
.diff_data= render_diff(commit_diff) unless (@git_repository.tree(commit_id) / commit_diff.b_path).binary?
|
||||
.diff_data= render_diff(commit_diff) unless (@project.repo.tree(commit_id) / commit_diff.b_path).binary?
|
|
@ -3,4 +3,4 @@
|
|||
= render 'repo_block', :project => @project
|
||||
|
||||
= render :partial => 'commits', :object => @commits
|
||||
= render 'paginate' if @render_paginate
|
||||
= render 'paginate' if @path.blank?
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
.both
|
||||
- if [:edit, :update].include? act
|
||||
.leftlist= t("activerecord.attributes.project.default_branch")
|
||||
.rightlist= f.select :default_branch, options_from_collection_for_select(@project.branches, :name, :name, @project.default_branch), :class => 'sel80', :id => 'branch_selector'
|
||||
.rightlist= f.select :default_branch, options_from_collection_for_select(@project.repo.branches, :name, :name, @project.default_branch), :class => 'sel80', :id => 'branch_selector'
|
||||
.both
|
||||
- if [:edit, :update].include? act
|
||||
.leftlist
|
||||
|
|
|
@ -33,7 +33,7 @@ Rosa::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
resources :event_logs, :only => :index
|
||||
constraints AdminAccess do
|
||||
constraints Rosa::Constraints::AdminAccess do
|
||||
mount Resque::Server => 'resque'
|
||||
end
|
||||
end
|
||||
|
@ -132,7 +132,6 @@ Rosa::Application.routes.draw do
|
|||
end
|
||||
|
||||
resources :projects, :only => [:index, :new, :create]
|
||||
|
||||
scope ':owner_name/:project_name', :constraints => {:project_name => Project::NAME_REGEXP} do # project
|
||||
scope :as => 'project' do
|
||||
resources :wiki do
|
||||
|
@ -176,7 +175,7 @@ Rosa::Application.routes.draw do
|
|||
end
|
||||
end
|
||||
# Resource
|
||||
get '/edit' => 'projects#edit', :as => :edit_project
|
||||
get '/modify' => 'projects#edit', :as => :edit_project
|
||||
put '/' => 'projects#update'
|
||||
delete '/' => 'projects#destroy'
|
||||
# Member
|
||||
|
@ -184,12 +183,13 @@ Rosa::Application.routes.draw do
|
|||
get '/sections' => 'projects#sections', :as => :sections_project
|
||||
post '/sections' => 'projects#sections'
|
||||
delete '/remove_user' => 'projects#remove_user', :as => :remove_user_project
|
||||
constraints :treeish => /[^\/]+/ do
|
||||
constraints :treeish => /.+/ do
|
||||
constraints Rosa::Constraints::Treeish do
|
||||
# Tree
|
||||
get '/' => "git/trees#show", :as => :project
|
||||
get '/tree/:treeish(/*path)' => "git/trees#show", :defaults => {:treeish => :master}, :as => :tree, :format => false
|
||||
get '/tree/:treeish(/*path)' => "git/trees#show", :as => :tree, :format => false
|
||||
# Commits
|
||||
get '/commits/:treeish(/*path)' => "git/commits#index", :defaults => {:treeish => :master}, :as => :commits, :format => false
|
||||
get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false
|
||||
get '/commit/:id(.:format)' => "git/commits#show", :as => :commit
|
||||
# Commit comments
|
||||
post '/commit/:commit_id/comments(.:format)' => "comments#create", :as => :project_commit_comments
|
||||
|
@ -200,25 +200,26 @@ Rosa::Application.routes.draw do
|
|||
post '/commit/:commit_id/subscribe' => "commit_subscribes#create", :as => :subscribe_commit
|
||||
delete '/commit/:commit_id/unsubscribe' => "commit_subscribes#destroy", :as => :unsubscribe_commit
|
||||
# Editing files
|
||||
get '/blob/:treeish/*path/edit' => "git/blobs#edit", :defaults => {:treeish => :master}, :as => :edit_blob
|
||||
put '/blob/:treeish/*path' => "git/blobs#update", :defaults => {:treeish => :master}, :format => false
|
||||
get '/edit/:treeish/*path' => "git/blobs#edit", :as => :edit_blob, :format => false
|
||||
put '/edit/:treeish/*path' => "git/blobs#update", :format => false
|
||||
# Blobs
|
||||
get '/blob/:treeish/*path' => "git/blobs#show", :defaults => {:treeish => :master}, :as => :blob, :format => false
|
||||
get '/blob/:treeish/*path' => "git/blobs#show", :as => :blob, :format => false
|
||||
# Blame
|
||||
get '/blame/:treeish/*path' => "git/blobs#blame", :defaults => {:treeish => :master}, :as => :blame, :format => false
|
||||
get '/blame/:treeish/*path' => "git/blobs#blame", :as => :blame, :format => false
|
||||
# Raw
|
||||
get '/raw/:treeish/*path' => "git/blobs#raw", :defaults => {:treeish => :master}, :as => :raw, :format => false
|
||||
get '/raw/:treeish/*path' => "git/blobs#raw", :as => :raw, :format => false
|
||||
# Archive
|
||||
get '/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/
|
||||
get '/archive/:treeish.:format' => "git/trees#archive", :as => :archive, :format => /zip|tar/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scope ':uname' do # project owner profile
|
||||
constraints OwnerConstraint.new(User) do
|
||||
constraints Rosa::Constraints::Owner.new(User) do
|
||||
get '/' => 'users/profile#show', :as => :user
|
||||
end
|
||||
constraints OwnerConstraint.new(Group, true) do
|
||||
constraints Rosa::Constraints::Owner.new(Group, true) do
|
||||
get '/' => 'groups/profile#show', :as => :group
|
||||
end
|
||||
end
|
||||
|
|
95
db/schema.rb
95
db/schema.rb
|
@ -53,8 +53,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "arches", ["name"], :name => "index_arches_on_name", :unique => true
|
||||
|
@ -63,8 +63,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.integer "user_id"
|
||||
t.string "provider"
|
||||
t.string "uid"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
add_index "authentications", ["provider", "uid"], :name => "index_authentications_on_provider_and_uid", :unique => true
|
||||
|
@ -75,8 +75,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.integer "level"
|
||||
t.integer "status"
|
||||
t.integer "build_list_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "version"
|
||||
end
|
||||
|
||||
|
@ -107,8 +107,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.integer "project_id"
|
||||
t.integer "arch_id"
|
||||
t.datetime "notified_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "is_circle", :default => false
|
||||
t.text "additional_repos"
|
||||
t.string "name"
|
||||
|
@ -137,8 +137,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "commentable_type"
|
||||
t.integer "user_id"
|
||||
t.text "body"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.decimal "commentable_id", :precision => 50, :scale => 0
|
||||
t.integer "project_id"
|
||||
end
|
||||
|
@ -155,14 +155,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "controller"
|
||||
t.string "action"
|
||||
t.text "message"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "groups", :force => true do |t|
|
||||
t.integer "owner_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "uname"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.text "description"
|
||||
|
@ -175,8 +175,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "title"
|
||||
t.text "body"
|
||||
t.string "status", :default => "open"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "user_id"
|
||||
t.datetime "closed_at"
|
||||
t.integer "closed_by"
|
||||
|
@ -225,14 +225,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "description"
|
||||
t.string "name", :null => false
|
||||
t.integer "parent_platform_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "released", :default => false, :null => false
|
||||
t.integer "owner_id"
|
||||
t.string "owner_type"
|
||||
t.string "visibility", :default => "open", :null => false
|
||||
t.string "platform_type", :default => "main", :null => false
|
||||
t.string "distrib_type"
|
||||
t.string "distrib_type", :null => false
|
||||
end
|
||||
|
||||
add_index "platforms", ["name"], :name => "index_platforms_on_name", :unique => true, :case_sensitive => false
|
||||
|
@ -241,8 +241,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.integer "platform_id"
|
||||
t.string "login"
|
||||
t.string "password"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
|
@ -258,8 +258,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
create_table "products", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.integer "platform_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.text "build_script"
|
||||
t.text "counter"
|
||||
t.text "ks"
|
||||
|
@ -278,8 +278,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "name"
|
||||
t.string "version"
|
||||
t.datetime "file_mtime"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "platform_id"
|
||||
end
|
||||
|
||||
|
@ -288,25 +288,25 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
create_table "project_to_repositories", :force => true do |t|
|
||||
t.integer "project_id"
|
||||
t.integer "repository_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "projects", :force => true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "owner_id"
|
||||
t.string "owner_type"
|
||||
t.string "visibility", :default => "open"
|
||||
t.text "description"
|
||||
t.string "ancestry"
|
||||
t.boolean "has_issues", :default => true
|
||||
t.boolean "has_wiki", :default => false
|
||||
t.string "srpm_file_name"
|
||||
t.string "srpm_content_type"
|
||||
t.integer "srpm_file_size"
|
||||
t.datetime "srpm_updated_at"
|
||||
t.boolean "has_wiki", :default => false
|
||||
t.string "default_branch", :default => "master"
|
||||
t.boolean "is_package", :default => true, :null => false
|
||||
t.integer "average_build_time", :default => 0, :null => false
|
||||
|
@ -321,8 +321,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "token"
|
||||
t.boolean "approved", :default => false
|
||||
t.boolean "rejected", :default => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "interest"
|
||||
t.text "more"
|
||||
end
|
||||
|
@ -335,16 +335,16 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "actor_type"
|
||||
t.integer "target_id"
|
||||
t.string "target_type"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "role"
|
||||
end
|
||||
|
||||
create_table "repositories", :force => true do |t|
|
||||
t.string "description", :null => false
|
||||
t.integer "platform_id", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "name", :null => false
|
||||
end
|
||||
|
||||
|
@ -355,8 +355,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.boolean "new_comment_reply", :default => true
|
||||
t.boolean "new_issue", :default => true
|
||||
t.boolean "issue_assign", :default => true
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "new_comment_commit_owner", :default => true
|
||||
t.boolean "new_comment_commit_repo_owner", :default => true
|
||||
t.boolean "new_comment_commit_commentor", :default => true
|
||||
|
@ -365,8 +365,8 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
create_table "subscribes", :force => true do |t|
|
||||
t.string "subscribeable_type"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "status", :default => true
|
||||
t.integer "project_id"
|
||||
t.decimal "subscribeable_id", :precision => 50, :scale => 0
|
||||
|
@ -376,21 +376,15 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.string "name"
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
||||
t.string "password_salt", :default => "", :null => false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.text "ssh_key"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "uname"
|
||||
t.string "role"
|
||||
t.string "language", :default => "en"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.integer "own_projects_count", :default => 0, :null => false
|
||||
t.text "professional_experience"
|
||||
t.string "site"
|
||||
t.string "company"
|
||||
|
@ -402,6 +396,9 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
|
|||
t.integer "failed_attempts", :default => 0
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "authentication_token"
|
||||
t.integer "build_priority", :default => 50
|
||||
end
|
||||
|
|
|
@ -21,4 +21,8 @@ Add to /etc/rc.d/rc.sysinit
|
|||
sudo urpmi lib64icu-devel # mandriva
|
||||
gem install charlock_holmes -- --with-icu-dir=/opt/local # macports
|
||||
|
||||
sudo urpmi lib64magic-devel # mandriva
|
||||
brew install libmagic; brew link libmagic # brew
|
||||
gem install ruby-filemagic
|
||||
|
||||
git config --global core.quotepath false
|
||||
|
|
|
@ -1,11 +1,49 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Grit
|
||||
class Blob
|
||||
include Linguist::BlobHelper
|
||||
|
||||
MAX_VIEW_SIZE = 2.megabytes
|
||||
MAX_DATA_SIZE = 50.megabytes
|
||||
|
||||
def data_with_limit
|
||||
size <= MAX_DATA_SIZE ? data_without_limit : nil # 'Error: blob is too big'
|
||||
end
|
||||
alias_method_chain :data, :limit
|
||||
|
||||
def large?
|
||||
size.to_i > MAX_VIEW_SIZE
|
||||
end
|
||||
|
||||
def render_as
|
||||
@render_as ||= case
|
||||
when large?; :binary
|
||||
when image?; :image
|
||||
when text?; :text
|
||||
else
|
||||
:binary
|
||||
end
|
||||
end
|
||||
|
||||
# def file_mime_type
|
||||
# @file_mime_type ||= data.file_type(:mime_type)
|
||||
# end
|
||||
#
|
||||
# def text?
|
||||
# file_mime_type =~ /^text\// # not binary?
|
||||
# end
|
||||
#
|
||||
# def binary?
|
||||
# not text? # file_mime_type !~ /^text\//
|
||||
# # s = data.split(//); ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30 # works only for latin chars
|
||||
# end
|
||||
#
|
||||
# def image?
|
||||
# mime_type.match(/image/)
|
||||
# end
|
||||
|
||||
DEFAULT_RAW_MIME_TYPE = MIME::Types[DEFAULT_MIME_TYPE].first
|
||||
|
||||
delegate :binary?, :ascii?, :encoding, :to => :raw_mime_type
|
||||
|
||||
def mime_type_with_class_store
|
||||
set_associated_mimes
|
||||
@associated_mimes.first.simplified
|
||||
|
@ -43,11 +81,11 @@ module Grit
|
|||
return -1 if a.media_type == 'text' and !a.registered?
|
||||
return 1
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Grit::Git.git_timeout = 60
|
||||
# Grit::Git.git_max_size = 5.megabytes
|
||||
# Grit.debug = true
|
||||
GAP_REPO_PATH = '/tmp/gap_repo.git'
|
||||
unless File.directory? GAP_REPO_PATH
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class OwnerConstraint
|
||||
def initialize(class_name, bang = false)
|
||||
@class_name = class_name
|
||||
@finder = 'find_by_insensitive_uname'
|
||||
@finder << '!' if bang
|
||||
end
|
||||
|
||||
def matches?(request)
|
||||
@class_name.send(@finder, request.params[:uname]).present?
|
||||
end
|
||||
end
|
||||
|
||||
class AdminAccess
|
||||
def self.matches?(request)
|
||||
!!request.env['warden'].user.try(:admin?)
|
||||
end
|
||||
end
|
||||
|
||||
class TreeishConstraint
|
||||
def self.matches?(request)
|
||||
# raise request.params.inspect
|
||||
# params = request.env['action_dispatch.request.path_parameters'] || request.params
|
||||
params = request.path_parameters
|
||||
if params[:treeish] # parse existing branch (tag) and path
|
||||
branch_or_tag = begin
|
||||
(p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) &&
|
||||
(p.repo.branches + p.repo.tags).detect{|t| params[:treeish].start_with?(t.name)}.try(:name) ||
|
||||
params[:treeish].split('/').first
|
||||
end
|
||||
if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present?
|
||||
params[:path] = File.join([path, params[:path]].compact)
|
||||
end
|
||||
params[:treeish] = branch_or_tag
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
# def set_treeish_and_path
|
||||
# if params[:treeish] and params[:path] and # try to correct branch with slashes
|
||||
# treeish_with_path = File.join(params[:treeish], params[:path]) and
|
||||
# branch_name = @project.repo.branches.detect{|t| treeish_with_path.start_with?(t.name)}.try(:name)
|
||||
# params[:treeish] = branch_name
|
||||
# params[:path] = treeish_with_path.sub(branch_name, '')[1..-1]
|
||||
# end
|
||||
# @treeish = params[:treeish].presence || @project.default_branch
|
||||
# @path = params[:path]
|
||||
# end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
class OwnerConstraint
|
||||
def initialize(class_name, bang = false)
|
||||
@class_name = class_name
|
||||
@finder = 'find_by_insensitive_uname'
|
||||
@finder << '!' if bang
|
||||
end
|
||||
|
||||
def matches?(request)
|
||||
@class_name.send(@finder, request.params[:uname]).present?
|
||||
end
|
||||
end
|
||||
|
||||
class AdminAccess
|
||||
def self.matches?(request)
|
||||
!!request.env['warden'].user.try(:admin?)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
# class ParamsParser
|
||||
# DEFAULT_PARSERS = {
|
||||
# Mime::XML => :xml_simple,
|
||||
# Mime::JSON => :json
|
||||
# }
|
||||
#
|
||||
# def initialize(app, parsers = {})
|
||||
# @app, @parsers = app, DEFAULT_PARSERS.merge(parsers)
|
||||
# end
|
||||
#
|
||||
# def call(env)
|
||||
# if params = parse_formatted_parameters(env)
|
||||
# env["action_dispatch.request.request_parameters"] = params
|
||||
# end
|
||||
#
|
||||
# @app.call(env)
|
||||
# end
|
||||
# end
|
|
@ -0,0 +1,42 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Rosa
|
||||
module Constraints
|
||||
class Owner
|
||||
def initialize(class_name, bang = false)
|
||||
@class_name = class_name
|
||||
@finder = 'find_by_insensitive_uname'
|
||||
@finder << '!' if bang
|
||||
end
|
||||
|
||||
def matches?(request)
|
||||
@class_name.send(@finder, request.params[:uname]).present?
|
||||
end
|
||||
end
|
||||
|
||||
class AdminAccess
|
||||
def self.matches?(request)
|
||||
!!request.env['warden'].user.try(:admin?)
|
||||
end
|
||||
end
|
||||
|
||||
class Treeish
|
||||
def self.matches?(request)
|
||||
# raise request.params.inspect
|
||||
# params = request.env['action_dispatch.request.path_parameters'] || request.params
|
||||
params = request.path_parameters
|
||||
if params[:treeish] # parse existing branch (tag) and path
|
||||
branch_or_tag = begin
|
||||
(p = Project.find_by_owner_and_name params[:owner_name], params[:project_name]) &&
|
||||
(p.repo.branches + p.repo.tags).detect{|t| params[:treeish].start_with?(t.name)}.try(:name) ||
|
||||
params[:treeish].split('/').first
|
||||
end
|
||||
if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present?
|
||||
params[:path] = File.join([path, params[:path]].compact)
|
||||
end
|
||||
params[:treeish] = branch_or_tag
|
||||
end
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,187 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Modules
|
||||
module Models
|
||||
module Git
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
validates_attachment_size :srpm, :less_than => 500.megabytes
|
||||
validates_attachment_content_type :srpm, :content_type => ['application/octet-stream', "application/x-rpm", "application/x-redhat-package-manager"], :message => I18n.t('layout.invalid_content_type')
|
||||
|
||||
has_attached_file :srpm
|
||||
# attr_accessible :srpm
|
||||
|
||||
after_create :create_git_repo
|
||||
after_commit(:on => :create) {|p| p.fork_git_repo unless p.is_root?} # later with resque
|
||||
after_commit(:on => :create) {|p| p.import_attached_srpm if p.srpm?} # later with resque # should be after create_git_repo
|
||||
after_destroy :destroy_git_repo
|
||||
# after_rollback lambda { destroy_git_repo rescue true if new_record? }
|
||||
|
||||
later :import_attached_srpm, :queue => :fork_import
|
||||
later :fork_git_repo, :queue => :fork_import
|
||||
end
|
||||
|
||||
def repo
|
||||
@repo ||= Grit::Repo.new(path) rescue Grit::Repo.new(GAP_REPO_PATH)
|
||||
end
|
||||
|
||||
def path
|
||||
build_path(git_repo_name)
|
||||
end
|
||||
|
||||
def git_repo_name
|
||||
File.join owner.uname, name
|
||||
end
|
||||
|
||||
def versions
|
||||
repo.tags.map(&:name) + repo.branches.map{|b| "latest_#{b.name}"}
|
||||
end
|
||||
|
||||
def update_file(path, data, options = {})
|
||||
head = options[:head].to_s || default_branch
|
||||
actor = get_actor(options[:actor])
|
||||
filename = File.split(path).last
|
||||
message = options[:message]
|
||||
message = "Updated file #{filename}" if message.nil? or message.empty?
|
||||
|
||||
# can not write to unexisted branch
|
||||
return false if repo.branches.select{|b| b.name == head}.size != 1
|
||||
|
||||
parent = repo.commits(head).first
|
||||
|
||||
index = repo.index
|
||||
index.read_tree(parent.tree.id)
|
||||
|
||||
# can not create new file
|
||||
return false if (index.current_tree / path).nil?
|
||||
|
||||
index.add(path, data)
|
||||
index.commit(message, :parents => [parent], :actor => actor, :last_tree => parent.tree.id, :head => head)
|
||||
end
|
||||
|
||||
def paginate_commits(treeish, options = {})
|
||||
options[:page] = 1 unless options[:page].present?
|
||||
options[:page] = options[:page].to_i
|
||||
|
||||
options[:per_page] = 20 unless options[:per_page].present?
|
||||
options[:per_page] = options[:per_page].to_i
|
||||
|
||||
skip = options[:per_page] * (options[:page] - 1)
|
||||
last_page = (skip + options[:per_page]) >= repo.commit_count(treeish)
|
||||
|
||||
[repo.commits(treeish, options[:per_page], skip), options[:page], last_page]
|
||||
end
|
||||
|
||||
def last_active_branch
|
||||
@last_active_branch ||= repo.branches.inject do |r, c|
|
||||
r_last = r.commit.committed_date || r.commit.authored_date unless r.nil?
|
||||
c_last = c.commit.committed_date || c.commit.authored_date
|
||||
if r.nil? or r_last < c_last
|
||||
r = c
|
||||
end
|
||||
r
|
||||
end
|
||||
@last_active_branch
|
||||
end
|
||||
|
||||
def tree_info(tree, treeish = nil, path = nil)
|
||||
treeish = tree.id unless treeish.present?
|
||||
# initialize result as hash of <tree_entry> => nil
|
||||
res = (tree.trees.sort + tree.blobs.sort).inject({}){|h, e| h.merge!({e => nil})}
|
||||
# fills result vith commits that describes this file
|
||||
res = res.inject(res) do |h, (entry, commit)|
|
||||
# only if commit == nil ...
|
||||
if commit.nil? and entry.respond_to? :name
|
||||
# ... find last commit corresponds to this file ...
|
||||
c = repo.log(treeish, File.join([path, entry.name].compact), :max_count => 1).first
|
||||
# ... and add it to result.
|
||||
h[entry] = c
|
||||
# find another files, that linked to this commit and set them their commit
|
||||
# c.diffs.map{|diff| diff.b_path.split(File::SEPARATOR, 2).first}.each do |name|
|
||||
# h.each_pair do |k, v|
|
||||
# h[k] = c if k.name == name and v.nil?
|
||||
# end
|
||||
# end
|
||||
end
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
def import_srpm(srpm_path = srpm.path, branch_name = 'import')
|
||||
system("#{Rails.root.join('bin', 'import_srpm.sh')} #{srpm_path} #{path} #{branch_name} >> /dev/null 2>&1")
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def build_path(dir)
|
||||
File.join(APP_CONFIG['root_path'], 'git_projects', "#{dir}.git")
|
||||
end
|
||||
|
||||
def import_attached_srpm
|
||||
if srpm?
|
||||
import_srpm # srpm.path
|
||||
self.srpm = nil; save # clear srpm
|
||||
end
|
||||
end
|
||||
|
||||
def create_git_repo
|
||||
if is_root?
|
||||
Grit::Repo.init_bare(path)
|
||||
write_hook
|
||||
end
|
||||
end
|
||||
|
||||
def fork_git_repo
|
||||
dummy = Grit::Repo.new(path) rescue parent.repo.fork_bare(path)
|
||||
write_hook
|
||||
end
|
||||
|
||||
def destroy_git_repo
|
||||
FileUtils.rm_rf path
|
||||
end
|
||||
|
||||
def write_hook
|
||||
is_production = Rails.env == "production"
|
||||
hook = File.join(::Rails.root.to_s, 'tmp', "post-receive-hook")
|
||||
FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook.partial"), hook)
|
||||
File.open(hook, 'a') do |f|
|
||||
s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rake hook:enqueue[$owner,$reponame,$newrev,$oldrev,$ref,$newrev_type,$oldrev_type]\""
|
||||
s << " > /dev/null 2>&1" if is_production
|
||||
s << "\ndone\n"
|
||||
f.write(s)
|
||||
f.chmod(0755)
|
||||
end
|
||||
|
||||
hook_file = File.join(path, 'hooks', 'post-receive')
|
||||
FileUtils.cp(hook, hook_file)
|
||||
FileUtils.rm_rf(hook)
|
||||
|
||||
rescue Exception # FIXME
|
||||
end
|
||||
|
||||
def get_actor(actor = nil)
|
||||
@last_actor = case actor.class.to_s
|
||||
when 'Grit::Actor' then options[:actor]
|
||||
when 'Hash' then Grit::Actor.new(actor[:name], actor[:email])
|
||||
when 'String' then Grit::Actor.from_stirng(actor)
|
||||
else begin
|
||||
if actor.respond_to?(:name) and actor.respond_to?(:email)
|
||||
Grit::Actor.new(actor.name, actor.email)
|
||||
else
|
||||
config = Grit::Config.new(repo)
|
||||
Grit::Actor.new(config['user.name'], config['user.email'])
|
||||
end
|
||||
end
|
||||
end
|
||||
@last_actor
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def 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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,16 +8,9 @@ module Modules
|
|||
after_create lambda { relations.create :actor_id => owner.id, :actor_type => owner.class.to_s, :role => 'admin' }
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def name_with_owner
|
||||
"#{owner.respond_to?(:uname) ? owner.uname : owner.name}/#{self.name}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
module Modules
|
||||
module Models
|
||||
module Wiki
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_create :create_wiki
|
||||
after_destroy :destroy_wiki
|
||||
end
|
||||
|
||||
def wiki_path
|
||||
build_path(wiki_repo_name)
|
||||
end
|
||||
|
||||
def wiki_repo_name
|
||||
File.join owner.uname, "#{name}.wiki"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def create_wiki
|
||||
if has_wiki && !FileTest.exist?(wiki_path)
|
||||
Grit::Repo.init_bare(wiki_path)
|
||||
wiki = Gollum::Wiki.new(wiki_path, {:base_path => Rails.application.routes.url_helpers.project_wiki_index_path(owner, self)})
|
||||
wiki.write_page('Home', :markdown, I18n.t("wiki.seed.welcome_content"),
|
||||
{:name => owner.name, :email => owner.email, :message => 'Initial commit'})
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_wiki
|
||||
FileUtils.rm_rf wiki_path
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,7 +9,7 @@ task :add_branch => :environment do
|
|||
Platform.find_by_name(dst_branch).repositories.each do |r|
|
||||
say "=== Process #{r.name} repo"
|
||||
r.projects.find_each do |p|
|
||||
next if p.branches.map(&:name).include?(dst_branch)
|
||||
next if p.repo.branches.map(&:name).include?(dst_branch)
|
||||
say "===== Process #{p.name} project"
|
||||
tmp_path = Rails.root.join('tmp', p.name)
|
||||
system("git clone #{p.path} #{tmp_path}")
|
||||
|
|
|
@ -76,6 +76,7 @@ describe Platforms::MassBuildsController do
|
|||
before(:each) do
|
||||
stub_symlink_methods
|
||||
|
||||
FactoryGirl.create(:arch)
|
||||
@platform = FactoryGirl.create(:platform)
|
||||
@repository = FactoryGirl.create(:repository, :platform => @platform)
|
||||
@personal_platform = FactoryGirl.create(:platform, :platform_type => 'personal')
|
||||
|
@ -91,13 +92,18 @@ describe Platforms::MassBuildsController do
|
|||
end
|
||||
|
||||
context 'for guest' do
|
||||
[:index, :create, :cancel, :failed_builds_list].each do |action|
|
||||
[:index, :create].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action, :platform_id => @platform
|
||||
response.should redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
it "should not be able to perform failed_builds_list action" do
|
||||
get :failed_builds_list, :platform_id => @platform, :id => @mass_build
|
||||
response.should redirect_to(new_user_session_path)
|
||||
end
|
||||
|
||||
it 'should not change objects count on create success' do
|
||||
lambda { post :create, @create_params }.should change{ MassBuild.count }.by(0)
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ end
|
|||
|
||||
shared_examples_for 'registered user' do
|
||||
it 'should be able to perform index action' do
|
||||
get :index
|
||||
get :index, :platform_id => @platform.id
|
||||
response.should render_template(:index)
|
||||
end
|
||||
|
||||
|
@ -80,7 +80,7 @@ describe Platforms::RepositoriesController do
|
|||
context 'for guest' do
|
||||
[:index, :create].each do |action|
|
||||
it "should not be able to perform #{ action } action" do
|
||||
get action
|
||||
get action, :platform_id => @platform
|
||||
response.should redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,13 +42,13 @@ describe Projects::BuildListsController do
|
|||
|
||||
it 'should save correct commit_hash for branch based build' do
|
||||
post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "latest_master"})
|
||||
@project.build_lists.last.commit_hash.should == @project.git_repository.commits('master').last.id
|
||||
@project.build_lists.last.commit_hash.should == @project.repo.commits('master').last.id
|
||||
end
|
||||
|
||||
it 'should save correct commit_hash for tag based build' do
|
||||
system("cd #{@project.git_repository.path} && git tag 4.7.5.3") # TODO REDO through grit
|
||||
system("cd #{@project.repo.path} && git tag 4.7.5.3") # TODO REDO through grit
|
||||
post :create, {:owner_name => @project.owner.uname, :project_name => @project.name}.merge(@create_params).deep_merge(:build_list => {:project_version => "4.7.5.3"})
|
||||
@project.build_lists.last.commit_hash.should == @project.git_repository.commits('4.7.5.3').last.id
|
||||
@project.build_lists.last.commit_hash.should == @project.repo.commits('4.7.5.3').last.id
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -283,7 +283,7 @@ describe Projects::BuildListsController do
|
|||
@build_list1 = FactoryGirl.create(:build_list_core)
|
||||
@build_list2 = FactoryGirl.create(:build_list_core)
|
||||
@build_list3 = FactoryGirl.create(:build_list_core)
|
||||
@build_list4 = FactoryGirl.create(:build_list_core, :created_at => (Time.now - 1.day),
|
||||
@build_list4 = FactoryGirl.create(:build_list_core, :updated_at => (Time.now - 1.day),
|
||||
:project => @build_list3.project, :save_to_platform => @build_list3.save_to_platform,
|
||||
:arch => @build_list3.arch)
|
||||
end
|
||||
|
@ -305,9 +305,9 @@ describe Projects::BuildListsController do
|
|||
|
||||
it 'should filter by project_name and start_date' do
|
||||
get :index, :filter => {:project_name => @build_list3.project.name, :ownership => 'index',
|
||||
"created_at_start(1i)" => @build_list3.created_at.year.to_s,
|
||||
"created_at_start(2i)" => @build_list3.created_at.month.to_s,
|
||||
"created_at_start(3i)" => @build_list3.created_at.day.to_s}
|
||||
:"updated_at_start(1i)" => @build_list3.updated_at.year.to_s,
|
||||
:"updated_at_start(2i)" => @build_list3.updated_at.month.to_s,
|
||||
:"updated_at_start(3i)" => @build_list3.updated_at.day.to_s}
|
||||
assigns[:build_lists].should_not include(@build_list1)
|
||||
assigns[:build_lists].should_not include(@build_list2)
|
||||
assigns[:build_lists].should include(@build_list3)
|
||||
|
@ -326,7 +326,7 @@ describe Projects::BuildListsController do
|
|||
describe 'publish_build' do
|
||||
before {
|
||||
test_git_commit(build_list.project)
|
||||
build_list.update_attribute :commit_hash, build_list.project.git_repository.commits('master').last.id
|
||||
build_list.update_attribute :commit_hash, build_list.project.repo.commits('master').last.id
|
||||
build_list.update_attribute(:status, BuildList::BUILD_PUBLISH)
|
||||
build_list_package
|
||||
}
|
||||
|
@ -343,8 +343,8 @@ describe Projects::BuildListsController do
|
|||
}
|
||||
it 'should create correct git tag for correct commit' do
|
||||
do_get(BuildServer::SUCCESS)
|
||||
build_list.project.git_repository.tags.last.name.should == build_list.package_version
|
||||
build_list.project.git_repository.commits(build_list.package_version).last.id.should == build_list.commit_hash
|
||||
build_list.project.repo.tags.last.name.should == build_list.package_version
|
||||
build_list.project.repo.commits(build_list.package_version).last.id.should == build_list.commit_hash
|
||||
end
|
||||
it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :status).to(BuildList::BUILD_PUBLISHED) }
|
||||
it(:passes) { lambda{ do_get(BuildServer::SUCCESS) }.should change(build_list, :package_version).to("#{ build_list_package.platform.name }-4.7.5.3-1") }
|
||||
|
|
|
@ -78,8 +78,8 @@ describe Projects::CommentsController do
|
|||
before(:each) do
|
||||
stub_symlink_methods
|
||||
@project = FactoryGirl.create(:project)
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
|
||||
@commit = @project.git_repository.commits.first
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ?
|
||||
@commit = @project.repo.commits.first
|
||||
|
||||
@create_params = {:comment => {:body => 'I am a comment!'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
|
||||
@update_params = {:comment => {:body => 'updated'}, :owner_name => @project.owner.uname, :project_name => @project.name, :commit_id => @commit.id}
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'spec_helper'
|
|||
describe Projects::Git::TreesController do
|
||||
|
||||
def fill_project
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ?
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
|
@ -12,7 +12,7 @@ describe Projects::Git::TreesController do
|
|||
|
||||
@project = FactoryGirl.create(:project)
|
||||
@another_user = FactoryGirl.create(:user)
|
||||
@params = {:owner_name => @project.owner.uname, :project_name => @project.name}
|
||||
@params = {:owner_name => @project.owner.uname, :project_name => @project.name, :treeish => 'master'}
|
||||
end
|
||||
|
||||
context 'for guest' do
|
||||
|
@ -35,21 +35,21 @@ describe Projects::Git::TreesController do
|
|||
it 'should not be able to archive empty project' do
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
expect { get :archive, @params.merge(:format => 'tar') }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { get :archive, @params.merge(:format => 'tar') }.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
|
||||
it 'should not be able to injection code with format' do
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
fill_project
|
||||
expect { get :archive, @params.merge(:format => "tar master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { get :archive, @params.merge(:format => "tar master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
|
||||
it 'should not be able to injection code with treeish' do
|
||||
@user = FactoryGirl.create(:user)
|
||||
set_session_for(@user)
|
||||
fill_project
|
||||
expect { get :archive, @params.merge(:treeish => "master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect { get :archive, @params.merge(:treeish => "master > /dev/null; echo 'I am hacker!';\#") }.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
|
||||
it 'should be able to perform archive action' do
|
||||
|
|
|
@ -16,7 +16,7 @@ describe Users::ProfileController do
|
|||
|
||||
context 'for guest' do
|
||||
it 'should not be able to view profile' do
|
||||
get :show, :owner_name => @simple_user.uname
|
||||
get :show, :uname => @simple_user.uname
|
||||
response.should redirect_to(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ FactoryGirl.define do
|
|||
association :owner, :factory => :user
|
||||
|
||||
factory :platform_with_repos do
|
||||
after_create {|p| FactoryGirl.create_list(:repository, 1, platform: p)}
|
||||
after(:create) {|p| FactoryGirl.create_list(:repository, 1, platform: p)}
|
||||
end
|
||||
|
||||
factory :personal_platform do
|
||||
|
|
|
@ -10,8 +10,8 @@ def set_comments_data_for_commit
|
|||
@ability = Ability.new(@user)
|
||||
|
||||
@project = FactoryGirl.create(:project, :owner => @user)
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.git_repository.path}) # maybe FIXME ?
|
||||
@commit = @project.git_repository.commits.first
|
||||
%x(cp -Rf #{Rails.root}/spec/tests.git/* #{@project.repo.path}) # maybe FIXME ?
|
||||
@commit = @project.repo.commits.first
|
||||
|
||||
@comment = create_comment(@user)
|
||||
@stranger_comment = create_comment(@stranger)
|
||||
|
|
|
@ -39,6 +39,7 @@ describe Projects::Git::TreesController do
|
|||
get("/import/glib2.0-mib/tree/lib2safe-0.03").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'lib2safe-0.03')
|
||||
get("/import/glib2.0-mib/tree/branch-with.dot/folder_with.dot/path-with.dot").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'branch-with.dot', :path => 'folder_with.dot/path-with.dot')
|
||||
# get("/import/glib2.0-mib/tree/ветка-с.точкой/папка_с.точкой/путь-с.точкой").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'ветка-с.точкой', :path => 'папка_с.точкой/путь-с.точкой')
|
||||
get("/import/glib2.0-mib/tree/tag13.52-5").should route_to("projects/git/trees#show", :owner_name => 'import', :project_name => 'glib2.0-mib', :treeish => 'tag13.52-5')
|
||||
end
|
||||
|
||||
# TODO write more specs also with slash in branch name!
|
||||
|
|
|
@ -39,8 +39,8 @@ def stub_symlink_methods
|
|||
end
|
||||
|
||||
def test_git_commit(project)
|
||||
project.git_repository.repo.index.add('test', 'TEST')
|
||||
project.git_repository.repo.index.commit('Test commit')
|
||||
project.repo.index.add('test', 'TEST')
|
||||
project.repo.index.commit('Test commit')
|
||||
end
|
||||
|
||||
Resque.inline = true
|
||||
|
|
Loading…
Reference in New Issue