[issue #565] Merge branch 'master' into 565-feedback_form

Conflicts:
	app/assets/stylesheets/design/custom.scss
This commit is contained in:
George Vinogradov 2012-08-03 23:36:14 +04:00
commit a1b7bcac32
125 changed files with 2037 additions and 995 deletions

28
Gemfile
View File

@ -1,20 +1,20 @@
source 'http://rubygems.org'
gem 'rails', '3.2.6' #, :git => 'git://github.com/rails/rails.git'
gem 'rails', '3.2.7' #, :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.4'
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,10 +26,12 @@ 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.1.2', :require => 'linguist'
gem 'diff-display', '~> 0.0.1'
# Wiki
gem "gollum", "1.3.1"
gem "gollum", :git => 'git://github.com/github/gollum.git'
gem "redcarpet", "1.17.2"
gem 'creole'
gem 'rdiscount'
@ -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.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.6.0'
gem 'rr', '~> 1.0.4'
gem 'shoulda'
end

View File

@ -6,6 +6,23 @@ GIT
redhillonrails_core (2.0.0.pre)
activerecord (>= 3.1.0.rc)
GIT
remote: git://github.com/github/gollum.git
revision: 8422b712048656c8ea391c2d7ef27fb29f66746b
specs:
gollum (2.1.0)
github-markdown
github-markup (>= 0.7.0, < 1.0.0)
grit (~> 2.5.0)
mustache (>= 0.11.2, < 1.0.0)
nokogiri (~> 1.4)
posix-spawn (~> 0.3.0)
pygments.rb (~> 0.2.0)
sanitize (~> 2.0.0)
sinatra (~> 1.0)
stringex (~> 1.4.0)
useragent (~> 0.4.9)
GIT
remote: git://github.com/rdblue/grack.git
revision: 020be3fef3fb308b9d214252522aa5945bf6584a
@ -14,9 +31,9 @@ GIT
GIT
remote: git://github.com/warpc/grit.git
revision: 696b0967cb7e6bac044569d898e5acef431d4f97
revision: f04f779fb052725b964ba259f8073a34e493c0c7
specs:
grit (2.4.1)
grit (2.5.0)
diff-lcs (~> 1.1)
mime-types (~> 1.15)
posix-spawn (~> 0.3.6)
@ -25,38 +42,36 @@ GEM
remote: http://rubygems.org/
specs:
RedCloth (4.2.9)
actionmailer (3.2.6)
actionpack (= 3.2.6)
actionmailer (3.2.7)
actionpack (= 3.2.7)
mail (~> 2.4.4)
actionpack (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
actionpack (3.2.7)
activemodel (= 3.2.7)
activesupport (= 3.2.7)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
journey (~> 1.0.4)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
activemodel (3.2.6)
activesupport (= 3.2.6)
activemodel (3.2.7)
activesupport (= 3.2.7)
builder (~> 3.0.0)
activerecord (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
activerecord (3.2.7)
activemodel (= 3.2.7)
activesupport (= 3.2.7)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
activesupport (3.2.6)
activeresource (3.2.7)
activemodel (= 3.2.7)
activesupport (= 3.2.7)
activesupport (3.2.7)
i18n (~> 0.6)
multi_json (~> 1.0)
airbrake (3.1.1)
airbrake (3.1.2)
activesupport
builder
albino (1.3.3)
posix-spawn (>= 0.3.6)
ancestry (1.3.0)
activerecord (>= 2.3.14)
arel (3.0.2)
@ -88,43 +103,42 @@ 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.6.0)
activesupport (>= 3.0.0)
factory_girl_rails (3.4.0)
factory_girl (~> 3.4.0)
factory_girl_rails (3.6.0)
factory_girl (~> 3.6.0)
railties (>= 3.0.0)
ffi (1.0.11)
fssm (0.2.9)
github-markup (0.7.2)
gollum (1.3.1)
albino (~> 1.3.2)
github-markup (>= 0.4.0, < 1.0.0)
grit (~> 2.4.1)
mustache (>= 0.11.2, < 1.0.0)
nokogiri (~> 1.4)
redcarpet
sanitize (~> 2.0.0)
sinatra (~> 1.0)
github-linguist (2.1.2)
charlock_holmes (~> 0.6.6)
escape_utils (~> 0.2.3)
mime-types (~> 1.18)
pygments.rb (>= 0.2.13)
github-markdown (0.5.0)
github-markup (0.7.4)
haml (3.1.6)
haml-rails (0.3.4)
actionpack (~> 3.0)
@ -132,18 +146,18 @@ 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)
json (1.7.3)
json (1.7.4)
kgio (2.7.4)
libv8 (3.3.10.4)
macaddr (1.6.1)
@ -152,18 +166,18 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mailcatcher (0.5.6)
mailcatcher (0.5.8)
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 +187,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.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.4)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
@ -192,9 +206,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)
@ -207,14 +223,14 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.6)
actionmailer (= 3.2.6)
actionpack (= 3.2.6)
activerecord (= 3.2.6)
activeresource (= 3.2.6)
activesupport (= 3.2.6)
rails (3.2.7)
actionmailer (= 3.2.7)
actionpack (= 3.2.7)
activerecord (= 3.2.7)
activeresource (= 3.2.7)
activesupport (= 3.2.7)
bundler (~> 1.0)
railties (= 3.2.6)
railties (= 3.2.7)
rails-backbone (0.7.2)
coffee-script (~> 2.2.0)
ejs (~> 1.0.0)
@ -223,28 +239,28 @@ GEM
railties (>= 3.0.0)
rails3-jquery-autocomplete (1.0.7)
rails (~> 3.0)
railties (3.2.6)
actionpack (= 3.2.6)
activesupport (= 3.2.6)
railties (3.2.7)
actionpack (= 3.2.7)
activesupport (= 3.2.7)
rack-ssl (~> 1.3.2)
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 +270,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.1)
rspec-expectations (2.11.2)
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.5)
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.1)
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,31 +322,33 @@ GEM
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
state_machine (1.1.2)
systemu (2.5.1)
stringex (1.4.0)
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
raindrops (~> 0.7)
useragent (0.4.10)
uuid (2.3.5)
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,21 +363,22 @@ 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)
gollum (= 1.3.1)
factory_girl_rails (~> 3.6.0)
github-linguist (~> 2.1.2)
gollum!
grack!
grit!
haml-rails (~> 0.3.4)
@ -365,24 +388,24 @@ 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.1)
omniauth (~> 1.1.0)
omniauth-openid (~> 1.0.1)
paperclip (~> 3.0.4)
paperclip (~> 3.1.4)
perform_later (~> 1.3.0)
pg (~> 0.13.2)
rails (= 3.2.6)
pg (~> 0.14.0)
rails (= 3.2.7)
rails-backbone (~> 0.7.2)
rails3-generators
rails3-jquery-autocomplete (~> 1.0.7)
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

View File

@ -0,0 +1,18 @@
function setCookie (name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
$(document).ready(function() {
if ($(".alert").size()) {
$(".alert").alert()
}
$('#close-alert').click(function () {
setCookie("flash_notify_hash", FLASH_HASH_ID, FLASH_EXPIRES_AT);
});
});

View File

@ -1324,3 +1324,63 @@ hr.bootstrap {
.modal-body-fork {
max-height: 280px;
}
/* Flash Notifies */
.flash_notify {
.alert-success {
color: #468847;
background-color: #DFF0D8;
border-color: #D6E9C6;
}
.alert {
padding: 8px 35px 8px 14px;
margin-bottom: 18px;
color: #C09853;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
background-color: #FCF8E3;
border: 1px solid #FBEED5;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.alert-danger, .alert-error {
color: #B94A48;
background-color: #F2DEDE;
border-color: #EED3D7;
}
.alert-info {
color: #3A87AD;
background-color: #D9EDF7;
border-color: #BCE8F1;
}
.alert .close {
position: relative;
top: -2px;
right: -21px;
line-height: 18px;
}
button.close {
padding: 0;
cursor: pointer;
background: transparent;
border: 0;
-webkit-appearance: none;
}
.close {
float: right;
font-size: 20px;
font-weight: bold;
line-height: 18px;
color: black;
text-shadow: 0 1px 0 white;
opacity: 0.2;
filter: alpha(opacity=20);
}
}

View File

@ -0,0 +1,41 @@
class Admin::FlashNotifiesController < Admin::BaseController
def index
@flash_notifies = FlashNotify.paginate(:page => params[:page], :per_page => 20)
end
def new
@flash_notify = FlashNotify.new(:published => true)
end
def create
@flash_notify = FlashNotify.new(params[:flash_notify])
if @flash_notify.save
flash[:notice] = t("flash.flash_notify.saved")
redirect_to admin_flash_notifies_path
else
flash[:error] = t("flash.flash_notify.save_error")
flash[:warning] = @flash_notify.errors.full_messages.join('. ')
render :new
end
end
def update
if @flash_notify.update_attributes(params[:flash_notify])
flash[:notice] = t("flash.flash_notify.saved")
redirect_to admin_flash_notifies_path
else
flash[:error] = t("flash.flash_notify.save_error")
flash[:warning] = @flash_notify.errors.full_messages.join('. ')
render :edit
end
end
def destroy
if @flash_notify.destroy
flash[:notice] = t("flash.flash_notify.destroyed")
else
flash[:error] = t("flash.flash_notify.destroy_error")
end
redirect_to admin_flash_notifies_path
end
end

View File

@ -12,7 +12,7 @@ class Admin::UsersController < Admin::BaseController
def create
@user.role = params[:role]
@user.confirmed_at = Time.now.utc
if @user.save
if (@user.save rescue false)
flash[:notice] = t('flash.user.saved')
redirect_to admin_users_path
else
@ -60,7 +60,6 @@ class Admin::UsersController < Admin::BaseController
end
@filter = params[:filter] || 'all'
@users = @users.send(@filter) if ['real', 'admin', 'banned'].include? @filter
@total_user = @users.count
@users = @users.order(order)
render :partial => 'users_ajax', :layout => false

View File

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

View File

@ -49,7 +49,7 @@ class Groups::ProfileController < Groups::BaseController
end
def remove_user
Relation.by_object(current_user).by_target(@group).destroy_all
Relation.by_actor(current_user).by_target(@group).destroy_all
redirect_to groups_path
end
end

View File

@ -0,0 +1,29 @@
class Platforms::KeyPairsController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :platform, :only => [:index]
load_and_authorize_resource :only => [:create, :destroy]
def create
@key_pair.user_id = current_user.id
if @key_pair.save
flash[:notice] = t('flash.key_pairs.saved')
else
flash[:error] = t('flash.key_pairs.save_error')
flash[:warning] = @key_pair.errors.full_messages.join('. ') unless @key_pair.errors.blank?
end
redirect_to platform_key_pairs_path(@key_pair.repository.platform)
end
def destroy
if @key_pair.destroy
flash[:notice] = t('flash.key_pairs.destroyed')
else
flash[:error] = t('flash.key_pairs.destroy_error')
end
redirect_to platform_key_pairs_path(@key_pair.repository.platform)
end
end

View File

@ -76,11 +76,13 @@ class Platforms::RepositoriesController < Platforms::BaseController
@projects = Project.joins(owner_subquery).addable_to_repository(@repository.id)
@projects = @projects.by_visibilities('open') if @repository.platform.platform_type == 'main'
end
@projects = @projects.paginate(:page => (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, :per_page => params[:iDisplayLength])
@projects = @projects.paginate(
:page => (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1,
:per_page => params[:iDisplayLength].present? ? params[:iDisplayLength] : 25
)
@total_projects = @projects.count
@total_projects_count = @projects.count
@projects = @projects.search(params[:sSearch]).search_order if params[:sSearch].present?
@total_project = @projects.count
@projects = @projects.order(order)
render :partial => (params[:added] == "true") ? 'project' : 'proj_ajax', :layout => false

View File

@ -41,12 +41,17 @@ class Projects::BuildListsController < Projects::BaseController
def create
notices, errors = [], []
@platform = Platform.find params[:build_list][:save_to_platform_id]
@repository = Repository.find params[:build_list][:save_to_repository_id]
@platform = @repository.platform
params[:build_list][:save_to_platform_id] = @platform.id
params[:build_list][:auto_publish] = false if @platform.released
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 +103,6 @@ class Projects::BuildListsController < Projects::BaseController
else
@build_list.fail_publish
end
render :nothing => true, :status => 200
end

View File

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

View File

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

View File

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

View File

@ -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", ''),
:message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish)
if res
if @project.update_file(params[:path], params[:content].gsub("\r", ''),
:message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish)
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

View File

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

View File

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

View File

@ -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)
@ -85,7 +81,7 @@ class Projects::ProjectsController < Projects::BaseController
end
def remove_user
@project.relations.by_object(current_user).destroy_all
@project.relations.by_actor(current_user).destroy_all
flash[:notice] = t("flash.project.user_removed")
redirect_to projects_path
end

View File

@ -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 != '..'
@ -63,7 +47,6 @@ module GitHelper
end
end
# TODO This is very dirty hack. Maybe need to be changed.
def branch_selector_options(project)
p = params.dup
p.delete(:path) if p[:path].present? # to root path
@ -71,10 +54,30 @@ 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]}]
if params[:treeish].present? && !project.repo.branches_and_tags.map(&:name).include?(params[:treeish])
res << [I18n.t('layout.git.repositories.commits'), [params[:treeish].truncate(20)]]
end
linking = Proc.new {|t| [t.name.truncate(20), url_for(p.merge :treeish => t.name).split('?', 2).first]}
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&linking)]
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&linking)]
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

View File

@ -17,7 +17,7 @@ class Ability
can :archive, Project, :visibility => 'open'
can :read, Issue, :project => {:visibility => 'open'}
can :search, BuildList
can :read, BuildList, :project => {:visibility => 'open'}
can [:read, :everything], BuildList, :project => {:visibility => 'open'}
can :read, ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work
can :read, Advisory
can(:advisories, Platform) {APP_CONFIG['anonymous_access']}
@ -62,10 +62,10 @@ class Ability
can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin')}
can :remove_user, Project
can [:read, :owned], BuildList, :user_id => user.id
can [:read, :related], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
can [:read, :related], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
can(:read, BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can [:read, :owned, :everything], BuildList, :user_id => user.id
can [:read, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}
can [:read, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
can([:read, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can([:create, :update], BuildList) {|build_list| build_list.project.is_package && can?(:write, build_list.project)}
can(:publish, BuildList) do |build_list|
@ -97,6 +97,8 @@ class Ability
can(:clear, Platform) {|platform| local_admin?(platform) && platform.personal?}
can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform}
can([:create, :destroy], KeyPair) {|key_pair| owner?(key_pair.repository.platform) || local_admin?(key_pair.repository.platform)}
can :read, Product, :platform => {:visibility => 'open'}
can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id, :platform_type => 'main'}
can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids, :platform_type => 'main'}

View File

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

View File

@ -3,6 +3,7 @@ class BuildList < ActiveRecord::Base
belongs_to :project
belongs_to :arch
belongs_to :save_to_platform, :class_name => 'Platform'
belongs_to :save_to_repository, :class_name => 'Repository'
belongs_to :build_for_platform, :class_name => 'Platform'
belongs_to :user
belongs_to :advisory
@ -13,7 +14,8 @@ class BuildList < ActiveRecord::Base
UPDATE_TYPES = %w[security bugfix enhancement recommended newpackage]
RELEASE_UPDATE_TYPES = %w[security bugfix]
validates :project_id, :project_version, :arch, :include_repos, :presence => true
validates :project_id, :project_version, :arch, :include_repos,
:build_for_platform_id, :save_to_platform_id, :save_to_repository_id, :presence => true
validates_numericality_of :priority, :greater_than_or_equal_to => 0
validates :update_type, :inclusion => UPDATE_TYPES,
:unless => Proc.new { |b| b.advisory.present? }
@ -22,6 +24,12 @@ class BuildList < ActiveRecord::Base
validate lambda {
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.platform_type == 'main' && save_to_platform_id != build_for_platform_id
}
validate lambda {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) unless save_to_repository_id.in? save_to_platform.repositories.map(&:id)
}
validate lambda {
errors.add(:save_to_repository, I18n.t('flash.build_list.cannot_write')) unless current_user.can?(:write, save_to_repository)
}
LIVE_TIME = 3.week
@ -106,14 +114,16 @@ class BuildList < ActiveRecord::Base
# WTF? around_transition -> infinite loop
before_transition do |build_list, transition|
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status)
MassBuild.decrement_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id
status = BuildList::HUMAN_STATUSES[build_list.status]
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status)
MassBuild.decrement_counter "#{status.to_s}_count", build_list.mass_build_id
end
end
after_transition do |build_list, transition|
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(build_list.status)
MassBuild.increment_counter "#{BuildList::HUMAN_STATUSES[build_list.status].to_s}_count", build_list.mass_build_id
status = BuildList::HUMAN_STATUSES[build_list.status]
if build_list.mass_build && MassBuild::COUNT_STATUSES.include?(status)
MassBuild.increment_counter "#{status.to_s}_count", build_list.mass_build_id
end
end
@ -189,7 +199,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

View File

@ -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,
@ -62,15 +52,15 @@ class BuildList::Filter
:mass_build_id => nil
}))
@options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'index' : 'owned')
@options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'everything' : '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
@options[:arch_id] = @options[:arch_id].present? ? @options[:arch_id].to_i : nil
@options[:platform_id] = @options[:platform_id].present? ? @options[:platform_id].to_i : nil
@options[:arch_id] = @options[:arch_id].try(:to_i)
@options[:platform_id] = @options[:platform_id].try(:to_i)
@options[:is_circle] = @options[:is_circle].present? ? @options[:is_circle] == "1" : nil
@options[:bs_id] = @options[:bs_id].presence
@options[:project_name] = @options[:project_name].presence

View File

@ -15,7 +15,9 @@ class Comment < ActiveRecord::Base
attr_accessible :body
def commentable
commit_comment? ? project.git_repository.commit(commentable_id.to_s(16)) : super
# raise commentable_id.inspect
# raise commentable_id.to_s(16).inspect
commit_comment? ? project.repo.commit(commentable_id.to_s(16)) : super # TODO leading zero problem
end
def commentable=(c)

View File

@ -0,0 +1,24 @@
require 'digest/md5'
class FlashNotify < ActiveRecord::Base
# attr_accessible :title, :body
STATUSES = %w[error success info]
validates :status, :inclusion => {:in => STATUSES}
validates :body_ru, :body_en, :status, :presence => true
scope :published, where(:published => true)
def hash_id
@digest ||= Digest::MD5.hexdigest("#{self.id}-#{self.updated_at}")
end
def body(language)
read_attribute("body_#{language}")
end
def should_show?(cookie_hash_id)
cookie_hash_id != hash_id && published
end
end

View File

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

35
app/models/key_pair.rb Normal file
View File

@ -0,0 +1,35 @@
class KeyPair < ActiveRecord::Base
belongs_to :repository
belongs_to :user
attr_accessor :secret
attr_accessible :public, :secret, :repository_id
validates :repository_id, :public, :user_id, :presence => true
validates :secret, :presence => true, :on => :create
validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pair.repo_key_exists")}
before_create :key_create_call
before_destroy :rm_key_call
protected
def key_create_call
result, self.key_id = BuildServer.import_gpg_key_pair(public, secret)
raise "Failed to create key_pairs for repository #{repository_id} with code #{result}." if result == 4
if result != 0 || self.key_id.nil?
errors.add(:public, I18n.t("activerecord.errors.key_pair.rpc_error_#{result}"))
return false
end
result = BuildServer.set_repository_key(repository.platform.name, repository.name, self.key_id)
raise "Failed to sign repository #{repository.name} in platform #{repository.platform.name}
using key_id #{self.key_id} with code #{result}." unless result.zero?
end
def rm_key_call
result = BuildServer.rm_repository_key(repository.platform.name, repository.name)
raise "Failed to desroy repository key #{repository.name} in platform
#{repository.platform.name} with code #{result}." unless result.zero?
end
end

View File

@ -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,34 +37,50 @@ 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
has_ancestry :orphan_strategy => :rootify #:adopt not available yet
include Modules::Models::Owner
include Modules::Models::Git
include Modules::Models::Wiki
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 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 self.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?
def members
collaborators + groups.map(&:members).flatten
end
def self.find_by_owner_and_name!(owner_name, project_name)
find_by_owner_and_name(owner_name, project_name) or raise ActiveRecord::RecordNotFound
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)
@ -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

View File

@ -4,6 +4,7 @@ class Repository < ActiveRecord::Base
has_many :project_to_repositories, :dependent => :destroy, :validate => true
has_many :projects, :through => :project_to_repositories
has_one :key_pair, :dependent => :destroy
validates :description, :presence => true
validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/}

View File

@ -35,6 +35,8 @@ class User < ActiveRecord::Base
has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy
has_many :key_pairs
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /^[a-z0-9_]+$/}, :reserved_name => true
validate { errors.add(:uname, :taken) if Group.by_uname(uname).present? }
validates :role, :inclusion => {:in => ROLES}, :allow_blank => true

View File

@ -0,0 +1,21 @@
.leftlist= f.label :body_ru, t("activerecord.attributes.flash_notify.body_ru"), :class => :label
.rightlist= f.text_area :body_ru, :class => 'text_field'
.both
.leftlist= f.label :body_en, t("activerecord.attributes.flash_notify.body_en"), :class => :label
.rightlist= f.text_area :body_en, :class => 'text_field'
.both
.leftlist= f.label :status, t("activerecord.attributes.flash_notify.status"), :class => :label
.rightlist= f.select :status, FlashNotify::STATUSES
.both
.leftlist= f.label :published, t("activerecord.attributes.flash_notify.published"), :class => :label
.rightlist= f.check_box :published
.both
.button_block
= submit_tag t("layout.save")
%span.text_button_padding= t("layout.or")
= link_to t("layout.cancel"), admin_flash_notifies_path, :class => "button"

View File

@ -0,0 +1,6 @@
%h3= t("layout.flash_notifies.edit_header")
= form_for @flash_notify, :url => admin_flash_notify_path(@flash_notify), :html => { :class => :form } do |f|
= render "form", :f => f
= render 'submenu'

View File

@ -0,0 +1,22 @@
= link_to t("layout.flash_notifies.new"), new_admin_flash_notify_path, :class => 'button' if can? :create, FlashNotify
%table#myTable.tablesorter.flash_notifys{:cellspacing => "0", :cellpadding => "0"}
%thead
%tr
%th.th1= t("activerecord.attributes.flash_notify.body_en")
%th.th2= t("activerecord.attributes.flash_notify.body_ru")
%th.th3= t("activerecord.attributes.flash_notify.published")
%th.th3= t("layout.flash_notifies.actions")
%tbody
- @flash_notifies.each do |flash_notify|
%tr{:class => cycle("odd", "even")}
%td= flash_notify.body_en.truncate 18
%td= flash_notify.body_ru.truncate 18
%td= flash_notify.published
%td
= link_to t("layout.flash_notifies.edit"), edit_admin_flash_notify_path(flash_notify)
= link_to t("layout.flash_notifies.delete"), admin_flash_notify_path(flash_notify), :method => :delete, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:delete, flash_notify)
= will_paginate @flash_notifies
= render 'submenu'

View File

@ -0,0 +1,6 @@
%h3= t("layout.flash_notifies.new_header")
= form_for @flash_notify, :url => admin_flash_notifies_path, :html => { :class => :form } do |f|
= render "form", :f => f
= render 'submenu'

View File

@ -1,19 +0,0 @@
{
"sEcho": <%=h params[:sEcho].to_i || -1 %>,
"iTotalRecords": <%= @total_users %>,
"iTotalDisplayRecords": <%= @total_user %>,
"aaData": [
<% @users.each do |user| %>
[
"<%= user.name %>",
"<%= user.uname %>",
"<%= user.email %>",
"<span style='<%=user.access_locked? ? 'background: #FEDEDE' : ''%>'><%= user.role %></span>",
"<%= j raw [(link_to t('layout.show'), user if can? :read, user),
(link_to t('layout.edit'), edit_admin_user_path(user) if can? :edit, user),
(link_to t('layout.delete'), admin_user_path(user), :method => :delete, :confirm => t('layout.users.confirm_delete') if can? :destroy, user)
].compact.join('&nbsp;|&nbsp;') %>"
]<%= user == @users.last ? '' : ',' %>
<% end %>
]
}

View File

@ -0,0 +1,21 @@
users = @users.map do |user|
link_block = [
(link_to t('layout.show'), user if can? :read, user),
(link_to t('layout.edit'), edit_admin_user_path(user) if can? :edit, user),
(link_to t('layout.delete'), admin_user_path(user), :method => :delete, :confirm => t('layout.users.confirm_delete') if can? :destroy, user)
].compact.join('&nbsp;|&nbsp;').html_safe
[
user.name,
user.uname,
user.email,
content_tag(:span, user.role, :style => user.access_locked? ? 'background: #FEDEDE' : ''),
link_block
]
end
json.sEcho params[:sEcho].to_i || -1
json.iTotalRecords @total_users
json.iTotalDisplayRecords @users.count
json.aaData users

View File

@ -0,0 +1,10 @@
- if current_user || APP_CONFIG['anonymous_access']
.flash_notify
- if (flash_notify = FlashNotify.published.first) && flash_notify.should_show?(cookies[:flash_notify_hash])
.alert{:class => "alert-#{flash_notify.status}"}
= flash_notify.body I18n.locale
%a.close#close-alert{:'data-dismiss'=>"alert", :href=>"#"} &times;
:javascript
var FLASH_HASH_ID = "#{flash_notify.hash_id}";
var FLASH_EXPIRES_AT = "#{Date.today + 1.year}";

View File

@ -47,6 +47,7 @@
= yield :feed_tabs
.both
= render "layouts/flashes"
= render "layouts/notifies"
%article
- if content_for?(:sidebar)
%aside= yield :sidebar

View File

@ -25,6 +25,9 @@
- if can? :members, @platform
%li{:class => (act == :members && contr == :platforms) ? 'active' : nil}
= link_to t("layout.platforms.members"), members_platform_path(@platform)
- if can? :edit, @platform
%li{:class => (act == :index && contr == :key_pairs) ? 'active' : ''}
= link_to t("layout.key_pairs.header"), platform_key_pairs_path(@platform)
-#- if current_user.owner_of? @platform or current_user.admin?
%li{:class => (act == :index && contr == :private_users) ? 'active' : ''}
= link_to t("layout.platforms.private_users"), platform_private_users_path(@platform)

View File

@ -0,0 +1,18 @@
%table#myTable.tablesorter.platform-repos{:cellspacing => "0", :cellpadding => "0"}
%thead
%tr
%th.th1= t("activerecord.attributes.key_pair.repository_id")
%th.th2= t("activerecord.attributes.key_pair.key_id")
%th.th3= t("activerecord.attributes.key_pair.user_id")
%th= t("layout.delete")
%tbody
- @platform.repositories.each do |repository|
- if repository.key_pair
%tr{:class => cycle("odd", "even")}
%td= repository.name
%td= repository.key_pair.key_id
%td= link_to repository.key_pair.user.fullname, user_path(repository.key_pair.user)
%td.buttons
- if can? :destroy, repository.key_pair
= link_to platform_key_pair_path(@platform, repository.key_pair), :method => :delete, :confirm => t("layout.key_pairs.confirm_delete") do
%span.delete &nbsp;

View File

@ -0,0 +1,17 @@
= render 'platforms/base/sidebar'
%h3= t("layout.key_pairs.header")
= form_for :key_pair, :url => platform_key_pairs_path(@platform), :method => :post, :html => { :class => :form } do |f|
.leftlist= f.label :public, t("activerecord.attributes.key_pair.public"), :class => :label
.rightlist= f.text_area :public, :class => 'text_field resizable', :cols => 80
.both
.leftlist= f.label :secret, t("activerecord.attributes.key_pair.secret"), :class => :label
.rightlist= f.text_area :secret, :class => 'text_field resizable', :cols => 80
.both
.leftlist= f.label :repository_id, t("activerecord.attributes.key_pair.repository_id"), :class => :label
.rightlist= f.select :repository_id, options_from_collection_for_select(@platform.repositories, 'id', 'name')
.both
.button_block
= submit_tag t("layout.save")

View File

@ -0,0 +1,2 @@
= render 'new' if can? :edit, @platform
= render 'list'

View File

@ -37,13 +37,13 @@
- @mass_builds.each do |mass_build|
%tr
%td= mass_build.id
%td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id})
%td= link_to mass_build.name, build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'everything'})
%td.min_width_120
- MassBuild::COUNT_STATUSES.each do |status|
= link_to t("layout.build_lists.statuses.#{status}") + ": ", build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'index'}.merge(status != :build_lists ? {:status => BuildList.status_by_human(status)} : {}))
= link_to t("layout.build_lists.statuses.#{status}") + ": ", build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'everything'}.merge(status != :build_lists ? {:status => BuildList.status_by_human(status)} : {}))
= mass_build.read_attribute "#{status}_count"
.both
%td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platform_mass_build_path(@platform, mass_build.id), :target => "_blank" if can?(:failed_builds_list, mass_build)
%td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platform_mass_build_path(@platform, mass_build.id, :format => :txt), :target => "_blank" if can?(:failed_builds_list, mass_build)
%td= link_to image_tag('x.png'), cancel_platform_mass_build_path(@platform, mass_build.id), :method => :post, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:cancel, mass_build)
%td
%a.toggle_btn{:href => "#toggle_#{ mass_build.id }", :'data-target' => "#toggle_#{ mass_build.id }"}= t("layout.mass_builds.extended_data")

View File

@ -1,15 +0,0 @@
{
"sEcho": <%=h params[:sEcho].to_i || -1 %>,
"iTotalRecords": <%= @total_projects %>,
"iTotalDisplayRecords": <%= @total_project %>,
"aaData": [
<% @projects.each do |project| %>
[
"<%=j link_to(project.name_with_owner, project) %>",
"<%= truncate(project.description || '', :length => 60).gsub(/\n|\r|\t/, ' ') %>",
"<%=j link_to t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id) %>"
]<%= project == @projects.last ? '' : ',' %>
<% end %>
]
}

View File

@ -0,0 +1,12 @@
projs = @projects.map do |project|
[
link_to(project.name_with_owner, project),
truncate(project.description || '', :length => 60).gsub(/\n|\r|\t/, ' '),
link_to(t("layout.add"), url_for(:controller => :repositories, :action => :add_project, :project_id => project.id))
]
end
json.sEcho params[:sEcho] || -1
json.iTotalRecords @total_projects
json.iTotalDisplayRecords @projects.count
json.aaData projs

View File

@ -1,31 +0,0 @@
{
"sEcho": <%=h params[:sEcho].to_i || -1 %>,
"iTotalRecords": <%= @total_projects %>,
"iTotalDisplayRecords": <%= @total_project %>,
"aaData": [
<% @projects.each do |project| %>
[
"<%=(
"<div class='table-sort-left'>" +
j(image_tag(visibility_icon(project.visibility))) +
"</div>" +
"<div class='table-sort-right'>" +
j(link_to("#{project.owner.respond_to?(:uname) ? project.owner.uname : project.owner.name} / #{project.name}", project)) +
"</div>").html_safe
%>",
"<%= truncate(project.description || '', :length => 60).gsub(/\n|\r|\t/, ' ') %>",
"<%=
if can? :remove_project, @repository
j(link_to('<span class="delete">&nbsp;</span>'.html_safe,
remove_project_platform_repository_path(@platform, @repository, :project_id => project.id),
:method => :delete, :confirm => t("layout.confirm")
)
)
else
''
end
%>"
]<%= project == @projects.last ? '' : ',' %>
<% end %>
]
}

View File

@ -0,0 +1,23 @@
projs = @projects.map do |pr|
[
content_tag(:div, image_tag(visibility_icon(pr.visibility)), :class => 'table-sort-left') +
content_tag(:div, link_to(pr.name_with_owner, pr), :class => 'table-sort-right'),
truncate(pr.description || '', :length => 60).gsub(/\n|\r|\t/, ' '),
if can? :remove_project, @repository
link_to(
remove_project_platform_repository_path(@platform, @repository, :project_id => pr.id),
:method => :delete, :confirm => t("layout.confirm")) do
content_tag(:span, "&nbsp;".html_safe, :class => 'delete')
end
else
''
end
]
end
json.sEcho params[:sEcho].to_i || -1
json.iTotalRecords @total_projects
json.iTotalDisplayRecords @projects.count
json.aaData projs

View File

@ -0,0 +1,6 @@
- if project.description.present?
.description
%h3= t("layout.projects.about_subheader")
%p
= project.description
-# link_to t('layout.read_more'), '#'

View File

@ -1,11 +1,6 @@
= render 'submenu'
= render 'repo_block', :project => @project
.description
%h3= t("layout.projects.about_subheader")
%p
= @project.description
= link_to t('layout.read_more'), '#'
= render 'about_block', :project => @project
%h3= t("layout.projects.last_commit")
- GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch, :project => @project) do |presenter|

View File

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

View File

@ -1,18 +1,18 @@
- 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
%li= link_to t("project_menu.tracker"), project_issues_path(@project), :class => (contr == :issues ? 'active' : nil)
- if @project.has_wiki
%li= link_to t("project_menu.wiki"), project_wiki_index_path(@project), :class => (contr == :wiki ? 'active' : nil)
%li= link_to t("project_menu.readme"), "#" #pending
%li=# link_to t("project_menu.readme"), "#" #pending
- if can? :update, @project
%li= link_to t("project_menu.settings"), edit_project_path(@project), :class => (act == :edit && contr == :projects ? 'active' : nil)

View File

@ -31,8 +31,8 @@
.lefter= t("layout.build_lists.ownership.related")
.both
.table
.lefter= f.radio_button :ownership, 'index', :class => 'niceRadio', :id => 'myradio3'
.lefter= t("layout.build_lists.ownership.index")
.lefter= f.radio_button :ownership, 'everything', :class => 'niceRadio', :id => 'myradio3'
.lefter= t("layout.build_lists.ownership.everything")
.both
%br
= f.submit t("layout.search.header")

View File

@ -11,12 +11,9 @@
.offset25{:style => 'padding-left: 25px'}= render 'include_repos', :platform => pl
%section.right
%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]}
.lineForm= f.select :save_to_repository_id, @project.repositories.collect{|r| ["#{r.platform.name}/#{r.name}", r.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

View File

@ -29,13 +29,15 @@
.leftlist= t("activerecord.attributes.build_list.save_to_platform")
.rightlist
= link_to @build_list.save_to_platform.name, @build_list.save_to_platform
\/
= link_to @build_list.save_to_repository.name, [@build_list.save_to_platform, @build_list.save_to_repository]
.both
.leftlist= t("activerecord.attributes.build_list.include_repos")
.rightlist= (@build_list.include_repos||[]).map{|r| Repository.find(r).name}.join(', ')
.both
.leftlist= t("activerecord.attributes.build_list.update_type")
.rightlist
- if @build_list.can_publish? and can?(:publish, @build_list)
- if @build_list.can_publish? && can?(:publish, @build_list)
= f.select :update_type, options_for_select(build_list_classified_update_types, @build_list.update_type)
- else
= @build_list.update_type
@ -81,11 +83,11 @@
= "#{@build_list.human_current_duration} / #{@build_list.project.human_average_build_time}"
.both
- if @build_list.can_cancel? and can?(:cancel, @build_list)
- if @build_list.can_cancel? && can?(:cancel, @build_list)
= link_to t("layout.build_lists.cancel"), cancel_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'
- if @build_list.can_publish? and @build_list.save_to_platform.released and @build_list.advisory.nil?
- if @build_list.can_publish? && @build_list.save_to_platform.released && @build_list.advisory.nil? && can?(:publish, @build_list)
#advisory_block
.leftlist= label_tag :attach_advisory, t("layout.build_lists.attached_advisory")
.rightlist
@ -123,8 +125,8 @@
var r = new Rosa.Routers.BuildListsAdvisoriesRouter();
});
= submit_tag t("layout.publish"), :confirm => t("layout.confirm"), :name => 'publish' if @build_list.can_publish? and can?(:publish, @build_list)
= submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish' if @build_list.can_reject_publish? and can?(:reject_publish, @build_list)
= submit_tag t("layout.publish"), :confirm => t("layout.confirm"), :name => 'publish' if @build_list.can_publish? && can?(:publish, @build_list)
= submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish' if @build_list.can_reject_publish? && can?(:reject_publish, @build_list)
.hr
%h3= t("layout.build_lists.items_header")

View File

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

View File

@ -0,0 +1,8 @@
%table.table.blob
%tr
%td.lines
%td.blob
:plain
<br/>
<pre>#{link_to_unless @blob.huge?, @blob.basename, raw_path(@project, @treeish, @path)}</pre>
<br/>

View File

@ -0,0 +1,8 @@
%table.table.blob
%tr
%td.lines
%td.blob
:plain
<br/>
<center><img src='#{raw_path(@project, @treeish, @path)}'/></center>
<br/>

View File

@ -0,0 +1,6 @@
.gutter= render_line_numbers(@blob.loc)
#output.formatted.cm-s-default
%pre#code
:preserve
#{h(@blob.data).html_safe}
.both

View File

@ -4,37 +4,10 @@
= 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(/&amp;/gi, '&');

View File

@ -1,20 +1,21 @@
.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 && can?(:write, @project) && @branch.present?
= link_to "Edit", edit_blob_path(@project, @treeish, @path)
\|
- if render_way == :text and params[:action] != 'show'
- if @blob.render_as == :text && 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'
- unless @blob.huge?
= link_to "Raw", raw_path(@project, @treeish, @path)
\|
- if @blob.render_as == :text && params[:action] != 'blame'
= link_to "Blame", blame_path(@project, @treeish, @path)
\|
= link_to "History", commits_path(@project, @treeish, @path)

View File

@ -1,12 +1,8 @@
-set_meta_tags :title => "#{title_object @project} #{t('at') if @branch} #{@branch.try :name}"
= render 'submenu'
= render 'repo_block', :project => @project
= render 'about_block', :project => @project
.description
%h3= t("layout.projects.about_subheader")
%p
= @project.description
= link_to t('layout.read_more'), '#'
%h3= t("layout.projects.last_commit")
- GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch, :project => @project) do |presenter|
@ -20,7 +16,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?

View File

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

View File

@ -13,7 +13,6 @@
-begin
= render_commit_stats(stats)
= render :partial => 'commit_diff', :collection => @commit.diffs
- rescue Grit::Git::GitTimeout
%p= t 'layout.git.repositories.commit_diff_too_big'

View File

@ -3,4 +3,4 @@
= render 'repo_block', :project => @project
= render :partial => 'commits', :object => @commits
= render 'paginate' if @render_paginate
= render 'paginate' if @path.blank?

View File

@ -1,11 +1,7 @@
-set_meta_tags :title => [title_object(@project), shortest_hash_id(@commit.id), @commit.message]
= render 'submenu'
= render 'about_block', :project => @project
.description
%h3= t("layout.projects.about_subheader")
%p
= @project.description
= link_to t('layout.read_more'), '#'
%h3= t("layout.projects.last_commit")
- GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch, :project => @project) do |presenter|

View File

@ -31,7 +31,7 @@
.pic= image_tag 'folder.png'
.name= link_to(entry.name, tree_path(@project, @treeish, entry_path), :class => 'files-see')
%td
%span{:style => "display: none;"}= commit.committed_date || commit.authored_date
= l(commit.committed_date || commit.authored_date, :format => :short)
%span{:style => "display: none;"}= date = commit.committed_date || commit.authored_date
= l(date, :format => :short)
%td= commit.short_message
%td= (commit.committer || commit.author).name

View File

@ -1,29 +1,64 @@
-set_meta_tags :title => title_object(@project)
= render 'submenu'
= render 'repo_block', :project => @project
= render 'about_block', :project => @project
.description
%h3= t("layout.projects.about_subheader")
%p
= @project.description
= link_to t('layout.read_more'), '#'
.both
#repo-wrapper
- if @project.parent_id.present? || @project.srpm.exists?
.both
#repo-wrapper
%h3= t("layout.projects.files_in_project")
.files
.l= render 'whereami'
.both
%table#myTable.tablesorter.project{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
%th.th1= t("layout.projects.filename")
%th.th2= t("layout.projects.age")
%th.th3= t("layout.projects.message")
%th.th4= t("layout.projects.author")
%tbody
%tr
%td.centered{:colspan => 4}
%h3= I18n.t("layout.git.repositories.empty")
- else
- if current_user
%h3= t("layout.projects.git_global_setup")
%p
%code
= "git config --global user.name #{current_user.fullname}"
%br/
= "git config --global user.email #{current_user.email}"
%br/
git config --global http.postBuffer 524288000
%h3= t("layout.projects.create_repository")
%p
%code
= "git clone #{git_repo_url(@project.git_repo_name)}"
%br/
= "cd #{@project.name}"
%br/
%br/
%p= t("layout.projects.move_files_to_folder")
%br/
%code
git add .
%br/
git commit -m 'description message'
%br/
git push -u origin master
%h3= t("layout.projects.existing_git_repo")
%p
%code
cd existing_git_repo
%br/
= "git remote add origin #{git_repo_url(@project.git_repo_name)}"
%br/
git push -u origin master
%table#myTable.tablesorter.project{:cellpadding => "0", :cellspacing => "0"}
%thead
%tr
%th.th1= t("layout.projects.filename")
%th.th2= t("layout.projects.age")
%th.th3= t("layout.projects.message")
%th.th4= t("layout.projects.author")
%tbody
%tr
%td.centered{:colspan => 4}
%h3= I18n.t("layout.git.repositories.empty")

View File

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

View File

@ -43,5 +43,5 @@
.both
.leftlist
\ 
.rightlist= submit_tag t("layout.save")
.rightlist= submit_tag t("layout.save"), :data => {:"disable-with" => t("layout.saving")}
.both

View File

@ -48,7 +48,7 @@ module Rosa
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
config.filter_parameters += [:password, :secret]
# Enable the asset pipeline
config.assets.enabled = true

View File

@ -62,7 +62,7 @@ Rosa::Application.configure do
config.assets.digest = true
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w(login.css login.js reg_session.css tour.css tour.js)
config.assets.precompile += %w(login.css login.js reg_session.css tour.css tour.js gollum/editor/langs/*.js)
end
# require 'stub_xml_rpc'

View File

@ -26,6 +26,7 @@ en:
delete: Erase
delete_selected: Remove selected
save: Save
saving: Saving
clone: Clone
search_by_name: Filter by name
are_you_sure: "Sure?"

View File

@ -38,5 +38,6 @@ en:
admins_menu:
users: Users
register_requests: Invites
flash_notifies: Notifies
event_logs: Event log
resque_server: Resque

View File

@ -38,5 +38,6 @@ ru:
admins_menu:
users: Пользователи
register_requests: Инвайты
flash_notifies: Оповещения
event_logs: Лог событий
resque_server: Resque

View File

@ -80,7 +80,7 @@ en:
header: Build list ownership
owned: My
related: Related
index: All
everything: All
build_server_status:
header: Build server status
@ -125,5 +125,7 @@ en:
no_project_version_found: Project version '%{project_version}' not found
no_arch_or_platform_selected: At least one of architecture of platform must selected
wrong_platform: Only the primary platform can be selected for the main repository!
wrong_repository: Repository to save package to must belongs to platform.
cannot_write: You can't build project to this repository.
can_not_published: Build can only be published with status "Build complete"
frozen_platform: In case of a repository for package storage with frozen platform allowed only bugfix and security updates

View File

@ -79,7 +79,7 @@ ru:
header: Принадлежность заданий
owned: Мне
related: Связанные со мной
index: Все
everything: Все
build_server_status:
header: Статус сборочного сервера
@ -124,5 +124,7 @@ ru:
no_project_version_found: Выбранная версия '%{project_version}' не найдена
no_arch_or_platform_selected: Выберите хотя бы одну архитектуру и платформу
wrong_platform: Для основного репозитория (main) может быть выбран только его же основная платформа!
wrong_repository: Репозиторий для сохранения должен принадлежать платформе.
cannot_write: Вы не можете собирать пакет в этот репозиторий.
can_not_published: Опубликовать сборку можно только со статусом "Собран"
frozen_platform: В случае выбора репозитория для сохранения пакетов из замороженнной платформы разрешены только bugfix и security обновления

View File

@ -0,0 +1,28 @@
en:
layout:
flash_notifies:
list_header: Notifies
new: New notify
new_header: New notify
actions: Actions
edit: Edit
edit_header: Edit notify
delete: Delete
flash:
flash_notify:
saved: Notify added
save_error: Unable to add notify
destroyed: Notify deleted
activerecord:
models:
flash_notify: Notify
attributes:
flash_notify:
body_ru: Body Ru
body_en: Body En
published: Published
status: Status
created_at: Created
updated_at: Updated

View File

@ -0,0 +1,28 @@
ru:
layout:
flash_notifies:
list_header: Оповещения
new: Новое оповещение
new_header: Новое оповещение
actions: Действия
edit: Редактирование
edit_header: Редактировать оповещение
delete: Удалить
flash:
flash_notify:
saved: Оповещение сохранено
save_error: Не получилось сохранить оповещение
destroyed: Оповещение удалено
activerecord:
models:
flash_notify: Оповещение
attributes:
flash_notify:
body_ru: Текст Ru
body_en: Текст En
published: Опубликовано
status: Статус
created_at: Создано
updated_at: Обновлено

View File

@ -0,0 +1,35 @@
en:
layout:
key_pairs:
repository_id: Repository
user_id: User
public: Public key
secret: Secret key
confirm_delete: Are you sure you want to delete this signature?
header: Signatures
flash:
key_pairs:
saved: Repository successfully signed
save_error: Signature save error
destroyed: Signature succefully destroyed
destroy_error: Signature destroy error
activerecord:
errors:
key_pair:
repo_key_exists: Repository has been signed already! Please remove old signature and try again
rpc_error_0: an unexpected error
rpc_error_1: could not import public key
rpc_error_2: could not import secret key
rpc_error_3: keys are imported, but it is not a key pair (ids differ)
models:
key_pair: Key Pair
attributes:
key_pair:
id: Id
created_at: Created
updated_at: Updated
user_id: User
repository_id: Repository
public: Public key
secret: Secret key
key_id: Signature

View File

@ -0,0 +1,35 @@
ru:
layout:
key_pairs:
repository_id: Репозиторий
user_id: Пользователь
public: Публичный ключ
secret: Секретный ключ
confirm_delete: Вы уверены, что хотите удалить подпись?
header: Подписи
flash:
key_pairs:
saved: Репозиторий успешно подписан
save_error: Ошибка создания подписи
destroyed: Подпись успешно удалена
destroy_error: Ошибка удаления подписи
activerecord:
errors:
key_pair:
repo_key_exists: Репозиторий уже подписан! Пожалуйста, удалите старую подпись и попробуйте снова
rpc_error_0: Неизвестная ошибка
rpc_error_1: Проблемы с импортром публичного ключа
rpc_error_2: Проблемы с импортром секретного ключа
rpc_error_3: Ключи импортированы, но не являются парой (идентификаторы не совпадают)
models:
key_pair: Подпись
attributes:
key_pair:
id: Id
created_at: Создано
updated_at: Обновлено
user_id: Пользователь
repository_id: Репозиторий
public: Публичный ключ
secret: Секретный ключ
key_id: Подпись

View File

@ -34,6 +34,10 @@ en:
has_issue_description: Tracker adds a lightweight issue management system tightly integrated with your repository.
has_wiki_description: Wikis are the simplest way to allow other users to contribute content. Any user can create and edit pages for documentation, examples, support or anything you wish.
human_average_build_time: Expected time is %{hours} h. %{minutes} min.
git_global_setup: Git global setup
create_repository: Create Repository
move_files_to_folder: Move files you need to the project or create them.
existing_git_repo: Git repo already exist?
git_help:
cloning: Cloning the repository

View File

@ -34,6 +34,10 @@ ru:
has_issue_description: Трэкер предоставляет лекговесный менеджер для задач по разработке Вашего проекта.
has_wiki_description: Wiki - это самый простой способ предоставить другим вносить свой вклад в развитие Вашего проекта. Каждый пользователь нашего сервиса может использовать Wiki для документирования, примеров, поддержки или всего другого, в чем у Вас появится необходимость.
human_average_build_time: 'Ожидаемое время: %{hours} ч. %{minutes} мин.'
git_global_setup: Общие настройки Git
create_repository: Создание репозитория
move_files_to_folder: Переместите нужные файлы в проект или создайте их.
existing_git_repo: Git репозиторий уже существует?
diff_show_header: "%{files} с %{additions} и %{deletions}."
about_subheader: "О проекте"

View File

@ -26,6 +26,7 @@ ru:
delete: Удалить
delete_selected: Удалить выбранное
save: Сохранить
saving: Сохранение...
clone: Клонировать
search_by_name: Фильтр по имени
are_you_sure: "Вы уверены?"

View File

@ -37,8 +37,9 @@ Rosa::Application.routes.draw do
get :reject
end
end
resources :flash_notifies
resources :event_logs, :only => :index
constraints AdminAccess do
constraints Rosa::Constraints::AdminAccess do
mount Resque::Server => 'resque'
end
end
@ -76,6 +77,7 @@ Rosa::Application.routes.draw do
get :projects_list
end
end
resources :key_pairs, :only => [:create, :index, :destroy]
resources :products do
resources :product_build_lists, :only => [:create, :destroy]
end
@ -137,7 +139,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
@ -181,7 +182,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
@ -189,41 +190,43 @@ 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
# Tree
get '/' => "git/trees#show", :as => :project
get '/tree/:treeish(/*path)' => "git/trees#show", :defaults => {:treeish => :master}, :as => :tree, :format => false
# Commits
get '/commits/:treeish(/*path)' => "git/commits#index", :defaults => {:treeish => :master}, :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
get '/commit/:commit_id/comments/:id(.:format)' => "comments#edit", :as => :edit_project_commit_comment
put '/commit/:commit_id/comments/:id(.:format)' => "comments#update", :as => :project_commit_comment
delete '/commit/:commit_id/comments/:id(.:format)' => "comments#destroy"
# Commit subscribes
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
# Blobs
get '/blob/:treeish/*path' => "git/blobs#show", :defaults => {:treeish => :master}, :as => :blob, :format => false
# Blame
get '/blame/:treeish/*path' => "git/blobs#blame", :defaults => {:treeish => :master}, :as => :blame, :format => false
# Raw
get '/raw/:treeish/*path' => "git/blobs#raw", :defaults => {:treeish => :master}, :as => :raw, :format => false
# Archive
get '/archive/:format/tree/:treeish' => "git/trees#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/
constraints :treeish => /.+/ do
constraints Rosa::Constraints::Treeish do
# Tree
get '/' => "git/trees#show", :as => :project
get '/tree/:treeish(/*path)' => "git/trees#show", :as => :tree, :format => false
# Commits
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
get '/commit/:commit_id/comments/:id(.:format)' => "comments#edit", :as => :edit_project_commit_comment
put '/commit/:commit_id/comments/:id(.:format)' => "comments#update", :as => :project_commit_comment
delete '/commit/:commit_id/comments/:id(.:format)' => "comments#destroy"
# Commit subscribes
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 '/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", :as => :blob, :format => false
# Blame
get '/blame/:treeish/*path' => "git/blobs#blame", :as => :blame, :format => false
# Raw
get '/raw/:treeish/*path' => "git/blobs#raw", :as => :raw, :format => false
# Archive
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

View File

@ -0,0 +1,11 @@
class CreateKeyPairs < ActiveRecord::Migration
def change
create_table :key_pairs do |t|
t.integer :repository_id
t.integer :user_id
t.integer :key_id
t.string :public
t.timestamps
end
end
end

View File

@ -0,0 +1,11 @@
class CreateFlashNotifies < ActiveRecord::Migration
def change
create_table :flash_notifies do |t|
t.text :body_ru, :null => false
t.text :body_en, :null => false
t.string :status, :null => false
t.boolean :published, :null => false, :default => true
t.timestamps
end
end
end

View File

@ -0,0 +1,24 @@
class AddSaveToRepositoryToBuildLists < ActiveRecord::Migration
def self.up
add_column :build_lists, :save_to_repository_id, :integer
BuildList.scoped.find_in_batches do |batch|
batch.each do |bl|
begin
project = bl.project
platform = bl.save_to_platform
rep = (project.repositories.map(&:id) & platform.repositories.map(&:id)).first
bl.save_to_repository_id = rep
bl.save
rescue
false
end
end
end
end
def self.down
remove_column :build_lists, :save_to_repository_id
end
end

View File

@ -0,0 +1,9 @@
class SetTextTypeForKeyPairsPublic < ActiveRecord::Migration
def up
change_column :key_pairs, :public, :text
end
def down
change_column :key_pairs, :public, :string
end
end

View File

@ -0,0 +1,9 @@
class SetStringTypeForKeyPairsKeyid < ActiveRecord::Migration
def up
change_column :key_pairs, :key_id, :string
end
def down
change_column :key_pairs, :key_id, :integer
end
end

View File

@ -0,0 +1,17 @@
class DisableNullValueForKeyPairs < ActiveRecord::Migration
def up
change_column_null :key_pairs, :repository_id, false
change_column_null :key_pairs, :user_id, false
change_column_null :key_pairs, :key_id, false
change_column_null :key_pairs, :public, false
add_index :key_pairs, :repository_id, :unique => true
end
def down
change_column_null :key_pairs, :repository_id, true
change_column_null :key_pairs, :user_id, true
change_column_null :key_pairs, :key_id, true
change_column_null :key_pairs, :public, true
remove_index :key_pairs, :repository_id
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120703101719) do
ActiveRecord::Schema.define(:version => 20120730214052) do
create_table "activity_feeds", :force => true do |t|
t.integer "user_id", :null => false
@ -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"
@ -126,6 +126,7 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.integer "duration"
t.integer "advisory_id"
t.integer "mass_build_id"
t.integer "save_to_repository_id"
end
add_index "build_lists", ["advisory_id"], :name => "index_build_lists_on_advisory_id"
@ -137,8 +138,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 +156,25 @@ 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 "flash_notifies", :force => true do |t|
t.text "body_ru", :null => false
t.text "body_en", :null => false
t.string "status", :null => false
t.boolean "published", :default => true, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "projects", ["owner_id"], :name => "index_projects_on_name_and_owner_id_and_owner_type", :unique => true, :case_sensitive => false
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", :null => false
t.datetime "updated_at", :null => false
t.string "uname"
t.integer "own_projects_count", :default => 0, :null => false
t.text "description"
@ -175,8 +187,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", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.datetime "closed_at"
t.integer "closed_by"
@ -184,6 +196,17 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
add_index "issues", ["project_id", "serial_id"], :name => "index_issues_on_project_id_and_serial_id", :unique => true
create_table "key_pairs", :force => true do |t|
t.integer "repository_id", :null => false
t.integer "user_id", :null => false
t.string "key_id", :null => false
t.text "public", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "key_pairs", ["repository_id"], :name => "index_key_pairs_on_repository_id", :unique => true
create_table "labelings", :force => true do |t|
t.integer "label_id", :null => false
t.integer "issue_id"
@ -225,14 +248,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,16 +264,16 @@ 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", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
end
create_table "product_build_lists", :force => true do |t|
t.integer "product_id"
t.integer "status", :default => 2, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "product_build_lists", ["product_id"], :name => "index_product_build_lists_on_product_id"
@ -258,8 +281,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", :null => false
t.datetime "updated_at", :null => false
t.text "build_script"
t.text "counter"
t.text "ks"
@ -278,8 +301,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", :null => false
t.datetime "updated_at", :null => false
t.integer "platform_id"
end
@ -288,14 +311,14 @@ 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", :null => false
t.datetime "updated_at", :null => false
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", :null => false
t.datetime "updated_at", :null => false
t.integer "owner_id"
t.string "owner_type"
t.string "visibility", :default => "open"
@ -321,8 +344,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", :null => false
t.datetime "updated_at", :null => false
t.string "interest"
t.text "more"
end
@ -335,16 +358,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", :null => false
t.datetime "updated_at", :null => false
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", :null => false
t.datetime "updated_at", :null => false
t.string "name", :null => false
end
@ -355,8 +378,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", :null => false
t.datetime "updated_at", :null => false
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 +388,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", :null => false
t.datetime "updated_at", :null => false
t.boolean "status", :default => true
t.integer "project_id"
t.decimal "subscribeable_id", :precision => 50, :scale => 0
@ -380,17 +403,12 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
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", :null => false
t.datetime "updated_at", :null => false
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.text "professional_experience"
t.string "site"
t.string "company"
@ -399,11 +417,14 @@ ActiveRecord::Schema.define(:version => 20120703101719) do
t.string "avatar_content_type"
t.integer "avatar_file_size"
t.datetime "avatar_updated_at"
t.integer "failed_attempts", :default => 0
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
t.integer "build_priority", :default => 50
end
add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token"

View File

@ -21,4 +21,10 @@ 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
sudo urpmi python-devel
git config --global core.quotepath false

View File

@ -87,11 +87,11 @@ class BuildServer
# raise include_repos_hash.inspect
self.client.call('add_build_list', project_name, project_version, plname, arch, bplname, update_type, build_requires, id_web, include_repos_hash, priority)
end
def self.delete_build_list idlist
self.client.call('delete_build_list', idlist)
end
def self.get_status
self.client.call('get_status')
end
@ -99,4 +99,17 @@ class BuildServer
def self.freeze platform_name
self.client.call('freeze_platform', platform_name)
end
# Repository key pair calls
def self.import_gpg_key_pair key_pub, key_secret
self.client.call('import_gpg_key_pair', key_pub, key_secret)
end
def self.set_repository_key platform, repository, key_id
self.client.call('set_repository_key', platform, repository, key_id)
end
def self.rm_repository_key platform, repository
self.client.call('rm_repository_key', platform, repository)
end
end

View File

@ -1,27 +1,24 @@
# -*- encoding : utf-8 -*-
require 'charlock_holmes/string'
# require 'iconv'
class String
def default_encoding!
if ascii_only?
force_encoding(Encoding.default_internal || Encoding::UTF_8)
else
force_encoding((detected = detect_encoding and detected[:encoding]) || Encoding.default_internal || Encoding::UTF_8).encode!
default_encoding = Encoding.default_internal || Encoding::UTF_8
if ascii_only? # no need to encode if ascii
force_encoding(default_encoding)
else # should encode
options = {:invalid => :replace, :undef => :replace, :replace => ''}
if (detected = detect_encoding) && detected[:encoding]
force_encoding(detected[:encoding]).encode!(default_encoding, detected[:encoding], options)
end
# re-encode through UTF-16 to filter incorrect symbols
encode!(Encoding::UTF_16, default_encoding, options).encode!(default_encoding, Encoding::UTF_16)
raise unless valid_encoding? # check result
end
self
rescue
replace "--broken encoding: #{detect_encoding[:encoding] || 'unknown'}"
# ensure
# return self
end
# def enforce_utf8(from = nil)
# begin
# is_utf8? ? self : ::Iconv.iconv('utf8', from, self).first
# rescue
# converter = ::Iconv.new('UTF-8//IGNORE//TRANSLIT', 'ASCII//IGNORE//TRANSLIT')
# # If Ruby 1.9, else another RubyEngine (ree, Ruby 1.8)
# begin
# converter.iconv(self).unpack('U*').select{|cp| cp < 127}.pack('U*').force_encoding('utf-8')
# rescue
# converter.iconv(self).unpack('U*').select{|cp| cp < 127}.pack('U*')
# end
# end
# end
end

View File

@ -1,11 +1,53 @@
# -*- encoding : utf-8 -*-
module Grit
class Blob
include Linguist::BlobHelper
MAX_VIEW_SIZE = 2.megabytes
MAX_DATA_SIZE = 50.megabytes
def data_with_limit
!huge? ? 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 huge?
size.to_i > MAX_DATA_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
@ -25,29 +67,35 @@ module Grit
protected
# store all associated MIME::Types inside class
def set_associated_mimes
@associated_mimes ||= []
if @associated_mimes.empty?
guesses = MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE]
guesses = [DEFAULT_RAW_MIME_TYPE] if guesses.empty?
# store all associated MIME::Types inside class
def set_associated_mimes
@associated_mimes ||= []
if @associated_mimes.empty?
guesses = MIME::Types.type_for(self.name) rescue [DEFAULT_RAW_MIME_TYPE]
guesses = [DEFAULT_RAW_MIME_TYPE] if guesses.empty?
@associated_mimes = guesses.sort{|a,b| mime_sort(a, b)}
end
@associated_mimes
@associated_mimes = guesses.sort{|a,b| mime_sort(a, b)}
end
@associated_mimes
end
# TODO make more clever function
def mime_sort(a,b)
return 0 if a.media_type == b.media_type and a.registered? == b.registered?
return -1 if a.media_type == 'text' and !a.registered?
return 1
end
# TODO make more clever function
def mime_sort(a,b)
return 0 if a.media_type == b.media_type and a.registered? == b.registered?
return -1 if a.media_type == 'text' and !a.registered?
return 1
end
end
class Repo
def branches_and_tags
branches + tags # @branches_and_tags ||= # ???
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

View File

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

View File

@ -0,0 +1,39 @@
# -*- 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)
if (params = request.path_parameters) && 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_and_tags.map(&:name).sort{|a,b| b.length <=> a.length}.detect{|b| params[:treeish].start_with?(b)} ||
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

171
lib/modules/models/git.rb Normal file
View File

@ -0,0 +1,171 @@
# -*- 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] = options[:page].try(:to_i) || 1
options[:per_page] = options[:per_page].try(:to_i) || 20
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 tree_info(tree, treeish = nil, path = nil)
treeish ||= tree.id
# 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)|
if commit.nil? and entry.respond_to?(:name) # only if commit == nil
# ... 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

View File

@ -8,15 +8,8 @@ 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
def name_with_owner
"#{owner.respond_to?(:uname) ? owner.uname : owner.name}/#{self.name}"
end
end
end

View File

@ -9,19 +9,25 @@ module Modules
end
def create_personal_repository
pl = own_platforms.build
pl.owner = self
pl.name = "#{self.uname}_personal"
pl.description = "#{self.uname}_personal"
pl.platform_type = 'personal'
pl.distrib_type = APP_CONFIG['distr_types'].first
pl.visibility = 'open'
pl.save!
begin
pl = own_platforms.build
pl.owner = self
pl.name = "#{self.uname}_personal"
pl.description = "#{self.uname}_personal"
pl.platform_type = 'personal'
pl.distrib_type = APP_CONFIG['distr_types'].first
pl.visibility = 'open'
pl.save!
rep = pl.repositories.build
rep.name = 'main'
rep.description = 'main'
rep.save!
rep = pl.repositories.build
rep.name = 'main'
rep.description = 'main'
rep.save!
rescue Exception => e
pl.now_destroy rescue false
raise e
end
return true
end
def personal_platform

Some files were not shown because too many files have changed in this diff Show More