From 85723f7da6a5d2ed31466888149da014ec8d5e0d Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Tue, 14 Feb 2012 18:54:18 +0400 Subject: [PATCH 01/33] [issue #64] Fixed encodings bugs --- app/helpers/diff_helper.rb | 2 +- app/views/wiki/_diff_data.html.haml | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 0addc764b..646135d1e 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -8,7 +8,7 @@ module DiffHelper res += "" res += "" - res += diff_display.render(Git::Diff::InlineCallback.new) + res += diff_display.render(Git::Diff::InlineCallback.new).encode_to_default res += "" res += "
" diff --git a/app/views/wiki/_diff_data.html.haml b/app/views/wiki/_diff_data.html.haml index cd8fb1f9a..d4f405c30 100644 --- a/app/views/wiki/_diff_data.html.haml +++ b/app/views/wiki/_diff_data.html.haml @@ -1,8 +1,7 @@ .blob_header - .size= h(diff.deleted_file ? diff.a_path : diff.b_path) - - puts 'in view' - - puts diff.a_path - - puts diff.b_path + .size= h(diff.deleted_file ? diff.a_path : diff.b_path).encode_to_default + - puts diff.a_path.encode_to_default + - puts diff.b_path.encode_to_default .clear .diff_data.highlight From e9c52731362b7af114111769bbbb8249fbf671a8 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Tue, 14 Feb 2012 18:54:44 +0400 Subject: [PATCH 02/33] [issue #64] Added possibility to diff and revert last commit --- app/controllers/wiki_controller.rb | 48 +++++++++++++++++++++--------- app/views/wiki/_compare.html.haml | 2 +- lib/gollum/wiki.rb | 10 +++++++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index b334262e3..b36613385 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -117,19 +117,37 @@ class WikiController < ApplicationController def compare_wiki if request.post? @versions = params[:versions] || [] - if @versions.size < 2 - redirect_to history_project_wiki_index_path(@project) - else - redirect_to compare_versions_project_wiki_index_path(@project, - sprintf('%s...%s', @versions.last, @versions.first)) + versions_string = case @versions.size + when 1 then @versions.first + when 2 then sprintf('%s...%s', @versions.last, @versions.first) + else begin + redirect_to history_project_wiki_index_path(@project) and return + end end + redirect_to compare_versions_project_wiki_index_path(@project, versions_string) +# if @versions.size < 2 +# redirect_to history_project_wiki_index_path(@project) +# else +# redirect_to compare_versions_project_wiki_index_path(@project, +# sprintf('%s...%s', @versions.last, @versions.first)) +# end elsif request.get? - @versions = params[:versions].split(/\.{2,3}/) - if @versions.size < 2 - redirect_to history_project_wiki_index_path(@project) - return + @versions = params[:versions].split(/\.{2,3}/) || [] + @diffs = case @versions.size + when 1 then @wiki.repo.commit_diff(@versions.first) + when 2 then @wiki.repo.diff(@versions.first, @versions.last) + else begin + redirect_to history_project_wiki_index_path(@project) + return + end end - @diffs = @wiki.repo.diff(@versions.first, @versions.last) + puts 'DIFFS' + puts @diffs.inspect +# if @versions.size < 2 +# redirect_to history_project_wiki_index_path(@project) +# return +# end +# @diffs = @wiki.repo.diff(@versions.first, @versions.last) render :compare else redirect_to project_wiki_path(@project, CGI.escape(@name)) @@ -141,8 +159,9 @@ class WikiController < ApplicationController @page = @wiki.page(@name) sha1 = params[:sha1] sha2 = params[:sha2] + sha2 = nil if params[:sha2] == 'prev' - if @wiki.revert_page(@page, sha1, sha2, {:committer => committer}).commit + if c = @wiki.revert_page(@page, sha1, sha2, {:committer => committer}) and c.commit flash[:notice] = t("flash.wiki.revert_success") redirect_to project_wiki_path(@project, CGI.escape(@name)) else @@ -162,14 +181,15 @@ class WikiController < ApplicationController def revert_wiki sha1 = params[:sha1] sha2 = params[:sha2] - if @wiki.revert_commit(sha1, sha2, {:committer => committer}).commit + sha2 = nil if sha2 == 'prev' + if c = @wiki.revert_commit(sha1, sha2, {:committer => committer}) and c.commit flash[:notice] = t("flash.wiki.revert_success") redirect_to project_wiki_index_path(@project) else sha2, sha1 = sha1, "#{sha1}^" if !sha2 @versions = [sha1, sha2] - diffs = @wiki.repo.diff(@versions.first, @versions.last) - @diffs = [diffs.first] + @diffs = @wiki.repo.diff(@versions.first, @versions.last) +# @diffs = [diffs.first] flash[:error] = t("flash.wiki.patch_does_not_apply") render :compare end diff --git a/app/views/wiki/_compare.html.haml b/app/views/wiki/_compare.html.haml index 0b58242e7..4796ba908 100644 --- a/app/views/wiki/_compare.html.haml +++ b/app/views/wiki/_compare.html.haml @@ -5,7 +5,7 @@ - if action_name != 'revert' %ul.actions %li.minibutton - = form_tag revert_path(@project, @versions[0][0..6], @versions[1][0..6], @name), + = form_tag revert_path(@project, @versions.first[0..6], (@versions.size == 1) ? 'prev' : @versions.last[0..6], @name), :name => "gollum-revert", :id => "gollum-revert-form" do = revert_button if can? :write, @project diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 14e8ae614..1c2b53d27 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -47,6 +47,8 @@ module Gollum multi_commit = false patch = full_reverse_diff_for(page, sha1, sha2) + puts 'patch' + puts patch committer = if obj = commit[:committer] multi_commit = true obj @@ -83,10 +85,18 @@ module Gollum end end + puts 'IN MY RELOADED FILE' + multi_commit ? committer : committer.commit end alias_method_chain :revert_page, :committer + def revert_commit_with_committer(sha1, sha2 = nil, commit = {}) + puts "i'm here" + revert_page_with_committer(nil, sha1, sha2, commit) + end + alias_method_chain :revert_commit, :committer + private def force_grit_encoding(str) From 2c493cdbb7e26344d2f9d16fdca9ebc7c4232826 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 14 Feb 2012 20:15:52 +0200 Subject: [PATCH 03/33] Apply approved and rejected filters for register requests. Tune abilities. Link to user profile if user have already registered. Refs #174 --- app/controllers/register_requests_controller.rb | 2 +- app/models/ability.rb | 2 ++ app/views/register_requests/index.html.haml | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/register_requests_controller.rb b/app/controllers/register_requests_controller.rb index 74ddd6627..85c915a52 100644 --- a/app/controllers/register_requests_controller.rb +++ b/app/controllers/register_requests_controller.rb @@ -5,7 +5,7 @@ class RegisterRequestsController < ApplicationController before_filter :find_register_request, :only => [:approve, :reject] def index - @register_requests = @register_requests.unprocessed.paginate(:page => params[:page]) + @register_requests = @register_requests.send((params[:scope] || 'unprocessed').to_sym).paginate(:page => params[:page]) end def new diff --git a/app/models/ability.rb b/app/models/ability.rb index 113b50dd1..2b58c1329 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,6 +17,8 @@ class Ability cannot :destroy, Subscribe cannot :create, Subscribe cannot :create, RegisterRequest + cannot :approve, RegisterRequest, :approved => true + cannot :reject, RegisterRequest, :rejected => true else # Shared rights between guests and registered users can :forbidden, Platform diff --git a/app/views/register_requests/index.html.haml b/app/views/register_requests/index.html.haml index a860887aa..9df74cd1b 100644 --- a/app/views/register_requests/index.html.haml +++ b/app/views/register_requests/index.html.haml @@ -5,6 +5,10 @@ %li= link_to t("layout.users.new"), new_user_path %li.active= link_to t("layout.users.register_requests"), register_requests_path .content + %div{:style => 'float: right; margin: 20px'} + = link_to t("layout.register_request.approved"), register_requests_path(:scope => :approved) + \| + = link_to t("layout.register_request.rejected"), register_requests_path(:scope => :rejected) %h2.title = t("layout.register_request.list_header") .inner @@ -23,7 +27,8 @@ %tr{:class => cycle("odd", "even")} %td= check_box_tag 'request_ids[]', request.id %td= request.name - %td= request.email + - @user = User.find_by_email(request.email) if request.approved + %td= link_to_if @user, request.email, @user %td= request.interest %td= request.more %td= request.created_at From 3690d6966323ed5552d625749e52578724d16a83 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 00:50:55 +0600 Subject: [PATCH 04/33] remove broken migration --- db/migrate/20120206194328_remove_orphan_platforms.rb | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 db/migrate/20120206194328_remove_orphan_platforms.rb diff --git a/db/migrate/20120206194328_remove_orphan_platforms.rb b/db/migrate/20120206194328_remove_orphan_platforms.rb deleted file mode 100644 index aa922710a..000000000 --- a/db/migrate/20120206194328_remove_orphan_platforms.rb +++ /dev/null @@ -1,8 +0,0 @@ -class RemoveOrphanPlatforms < ActiveRecord::Migration - def self.up - Platform.all.each {|x| x.destroy unless x.owner.present?} - end - - def self.down - end -end From 5b7d1a79d0d01b6e2f506a0a87f6bb7ffd562550 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 15 Feb 2012 02:13:52 +0400 Subject: [PATCH 05/33] [issue #64] Removed debug methods and unnecessary comments. --- app/controllers/wiki_controller.rb | 17 ++--------------- lib/gollum/wiki.rb | 5 ----- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index b36613385..7364f1943 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -121,16 +121,11 @@ class WikiController < ApplicationController when 1 then @versions.first when 2 then sprintf('%s...%s', @versions.last, @versions.first) else begin - redirect_to history_project_wiki_index_path(@project) and return + redirect_to history_project_wiki_index_path(@project) + return end end redirect_to compare_versions_project_wiki_index_path(@project, versions_string) -# if @versions.size < 2 -# redirect_to history_project_wiki_index_path(@project) -# else -# redirect_to compare_versions_project_wiki_index_path(@project, -# sprintf('%s...%s', @versions.last, @versions.first)) -# end elsif request.get? @versions = params[:versions].split(/\.{2,3}/) || [] @diffs = case @versions.size @@ -141,13 +136,6 @@ class WikiController < ApplicationController return end end - puts 'DIFFS' - puts @diffs.inspect -# if @versions.size < 2 -# redirect_to history_project_wiki_index_path(@project) -# return -# end -# @diffs = @wiki.repo.diff(@versions.first, @versions.last) render :compare else redirect_to project_wiki_path(@project, CGI.escape(@name)) @@ -189,7 +177,6 @@ class WikiController < ApplicationController sha2, sha1 = sha1, "#{sha1}^" if !sha2 @versions = [sha1, sha2] @diffs = @wiki.repo.diff(@versions.first, @versions.last) -# @diffs = [diffs.first] flash[:error] = t("flash.wiki.patch_does_not_apply") render :compare end diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 1c2b53d27..70ef08e46 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -47,8 +47,6 @@ module Gollum multi_commit = false patch = full_reverse_diff_for(page, sha1, sha2) - puts 'patch' - puts patch committer = if obj = commit[:committer] multi_commit = true obj @@ -85,14 +83,11 @@ module Gollum end end - puts 'IN MY RELOADED FILE' - multi_commit ? committer : committer.commit end alias_method_chain :revert_page, :committer def revert_commit_with_committer(sha1, sha2 = nil, commit = {}) - puts "i'm here" revert_page_with_committer(nil, sha1, sha2, commit) end alias_method_chain :revert_commit, :committer From 00e2043f519aff3dab95ea4724e88902535d663b Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Wed, 15 Feb 2012 14:36:45 +0400 Subject: [PATCH 06/33] Change nginx log rotate period to 1 day --- config/locales/en.yml | 2 +- config/locales/ru.yml | 2 +- config/schedule.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index ed0aa44c9..05f7ca5f0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -59,7 +59,7 @@ en: downloads: title: Downloads statistic - message: Automatically updated every 5 minutes + message: Automatically updated every 24 hours refresh_btn: Refresh auto_build_lists: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 219bfbaa8..9b55c3059 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -60,7 +60,7 @@ ru: downloads: title: Статистика закачек пакетов - message: Обновляется автоматически каждые 5 минут + message: Обновляется автоматически каждые 24 часа refresh_btn: Обновить auto_build_lists: diff --git a/config/schedule.rb b/config/schedule.rb index f966ecc1d..f1d6faa22 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -7,7 +7,7 @@ # runner "Download.parse_and_remove_nginx_log" #end -every 5.minutes do +every 1.day, :at => '5:00' do #rake "sudo_test:projects" runner "Download.rotate_nginx_log" runner "Download.parse_and_remove_nginx_log" From 20836e88643ee54c3a6774039de901aaa8c0ec59 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 17:12:49 +0600 Subject: [PATCH 07/33] [refs #134] fixed git hook --- app/models/project.rb | 2 +- bin/post-receive-hook_dev | 15 ++++++++++++ bin/post-receive-hook_prod | 15 ++++++++++++ ...120131141651_write_git_hook_to_projects.rb | 13 ----------- lib/tasks/hook.rake | 23 +++++++++++++++++++ 5 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 bin/post-receive-hook_dev create mode 100644 bin/post-receive-hook_prod delete mode 100644 db/migrate/20120131141651_write_git_hook_to_projects.rb create mode 100644 lib/tasks/hook.rake diff --git a/app/models/project.rb b/app/models/project.rb index c15332d5e..3970650fe 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -213,7 +213,7 @@ class Project < ActiveRecord::Base def write_hook hook_file = File.join(path, 'hooks', 'post-receive') - FileUtils.cp(File.join(::Rails.root.to_s, 'lib', 'post-receive-hook'), hook_file) + FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}"), hook_file) #File.chmod(0775, hook_file) # need? rescue Exception # FIXME end diff --git a/bin/post-receive-hook_dev b/bin/post-receive-hook_dev new file mode 100644 index 000000000..b577daa5b --- /dev/null +++ b/bin/post-receive-hook_dev @@ -0,0 +1,15 @@ +#!/bin/bash + +# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. + +pwd=`pwd` +reponame=`basename $pwd .git` +owner=`basename \`dirname $pwd\`` + +while read oldrev newrev ref +do + newrev_type=$(git cat-file -t $newrev 2> /dev/null) + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) + + /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" +done \ No newline at end of file diff --git a/bin/post-receive-hook_prod b/bin/post-receive-hook_prod new file mode 100644 index 000000000..6e9fb4bd8 --- /dev/null +++ b/bin/post-receive-hook_prod @@ -0,0 +1,15 @@ +#!/bin/bash + +# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. + +pwd=`pwd` +reponame=`basename $pwd .git` +owner=`basename \`dirname $pwd\`` + +while read oldrev newrev ref +do + newrev_type=$(git cat-file -t $newrev 2> /dev/null) + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) + + /bin/bash -l -c "cd /srv/rosa_build/current && RAILS_ENV=production bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" > /dev/null 2>&1 +done \ No newline at end of file diff --git a/db/migrate/20120131141651_write_git_hook_to_projects.rb b/db/migrate/20120131141651_write_git_hook_to_projects.rb deleted file mode 100644 index d8dded706..000000000 --- a/db/migrate/20120131141651_write_git_hook_to_projects.rb +++ /dev/null @@ -1,13 +0,0 @@ -class WriteGitHookToProjects < ActiveRecord::Migration - def self.up - origin_hook = File.join(::Rails.root.to_s, 'lib', 'post-receive-hook') - Project.all.each do |project| - hook_file = File.join(project.path, 'hooks', 'post-receive') - FileUtils.cp(origin_hook, hook_file) - end - end - - def self.down - Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive')} - end -end diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake new file mode 100644 index 000000000..9b4a0212b --- /dev/null +++ b/lib/tasks/hook.rake @@ -0,0 +1,23 @@ +namespace :hook do + desc "Inserting hook to all repos" + task :install => :environment do + origin_hook = File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}") + say "process.. #{origin_hook}" + count = 0 + Project.all.each do |project| + hook_file = File.join(project.path, 'hooks', 'post-receive') + FileUtils.cp(origin_hook, hook_file) + count = count + 1 + end + say "Done! Writing to #{count.to_s} repo(s)" + end + + desc "remove with git hook" + task :remove => :environment do + say "process.." + count = 0 + Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive'); count = count + 1} + say "Done! Removing from #{count.to_s} repo(s)" + end +end + From fbaa9949df9da91da77462d1bcb5c84142d4aae0 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 17:23:49 +0600 Subject: [PATCH 08/33] [refs #134] clean --- lib/post-receive-hook | 15 --------------- lib/tasks/hook.rake | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100755 lib/post-receive-hook diff --git a/lib/post-receive-hook b/lib/post-receive-hook deleted file mode 100755 index b577daa5b..000000000 --- a/lib/post-receive-hook +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. - -pwd=`pwd` -reponame=`basename $pwd .git` -owner=`basename \`dirname $pwd\`` - -while read oldrev newrev ref -do - newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" -done \ No newline at end of file diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 9b4a0212b..1eeae0774 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -12,7 +12,7 @@ namespace :hook do say "Done! Writing to #{count.to_s} repo(s)" end - desc "remove with git hook" + desc "remove git hook from all repos" task :remove => :environment do say "process.." count = 0 From a8f507737f5850333c4df54a19f88d4593d8ed6f Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Wed, 15 Feb 2012 19:06:25 +0600 Subject: [PATCH 09/33] [refs #134] rails root --- ...ive-hook_dev => post-receive-hook.partial} | 5 +---- bin/post-receive-hook_prod | 15 ------------- lib/tasks/hook.rake | 22 ++++++++++++++----- 3 files changed, 18 insertions(+), 24 deletions(-) rename bin/{post-receive-hook_dev => post-receive-hook.partial} (51%) delete mode 100644 bin/post-receive-hook_prod diff --git a/bin/post-receive-hook_dev b/bin/post-receive-hook.partial similarity index 51% rename from bin/post-receive-hook_dev rename to bin/post-receive-hook.partial index b577daa5b..b1e39a205 100644 --- a/bin/post-receive-hook_dev +++ b/bin/post-receive-hook.partial @@ -9,7 +9,4 @@ owner=`basename \`dirname $pwd\`` while read oldrev newrev ref do newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" -done \ No newline at end of file + oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) \ No newline at end of file diff --git a/bin/post-receive-hook_prod b/bin/post-receive-hook_prod deleted file mode 100644 index 6e9fb4bd8..000000000 --- a/bin/post-receive-hook_prod +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# This file was placed here by rosa-team. It makes sure that your pushed commits will be processed properly. - -pwd=`pwd` -reponame=`basename $pwd .git` -owner=`basename \`dirname $pwd\`` - -while read oldrev newrev ref -do - newrev_type=$(git cat-file -t $newrev 2> /dev/null) - oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null) - - /bin/bash -l -c "cd /srv/rosa_build/current && RAILS_ENV=production bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'" > /dev/null 2>&1 -done \ No newline at end of file diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 1eeae0774..baf1e458a 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -1,15 +1,28 @@ namespace :hook do desc "Inserting hook to all repos" task :install => :environment do - origin_hook = File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}") - say "process.. #{origin_hook}" + is_production = ENV['RAILS_ENV'] == 'production' + say "Generate temporary file..." + 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} && \ + bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + end + + say "Install process.." count = 0 Project.all.each do |project| hook_file = File.join(project.path, 'hooks', 'post-receive') - FileUtils.cp(origin_hook, hook_file) + FileUtils.cp(hook, hook_file) count = count + 1 end - say "Done! Writing to #{count.to_s} repo(s)" + say "Writing to #{count.to_s} repo(s)" + say "Removing temporary file" + FileUtils.rm_rf(hook) end desc "remove git hook from all repos" @@ -20,4 +33,3 @@ namespace :hook do say "Done! Removing from #{count.to_s} repo(s)" end end - From 5dac20bac5850c70cc2c5f51b6ec12a6586a9dc5 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 15 Feb 2012 20:30:56 +0400 Subject: [PATCH 10/33] Some fixes: * Changed default visibility to personal platforms to 'open' * Changed 'Erase' button to simple link in comments partial * Probably added domain name to links in mail notifications * Fixed protocol in repo links form 'http' to 'https' --- app/helpers/projects_helper.rb | 4 ++-- app/views/comments/_list.html.haml | 3 ++- app/views/user_mailer/issue_assign_notification.en.haml | 2 +- app/views/user_mailer/issue_assign_notification.ru.haml | 2 +- app/views/user_mailer/new_comment_notification.en.haml | 8 ++++---- app/views/user_mailer/new_comment_notification.ru.haml | 6 +++--- .../user_mailer/new_comment_reply_notification.en.haml | 4 ++-- app/views/user_mailer/new_issue_notification.en.haml | 2 +- app/views/user_mailer/new_issue_notification.ru.haml | 2 +- lib/modules/models/personal_repository.rb | 2 +- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 06c4de5b0..827e4cda0 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -2,9 +2,9 @@ module ProjectsHelper def git_repo_url(name) if current_user - "http://#{current_user.uname}@#{request.host_with_port}/#{name}.git" + "https://#{current_user.uname}@#{request.host_with_port}/#{name}.git" else - "http://#{request.host_with_port}/#{name}.git" + "https://#{request.host_with_port}/#{name}.git" end end end diff --git a/app/views/comments/_list.html.haml b/app/views/comments/_list.html.haml index 25e6e13ee..c2aa719bb 100644 --- a/app/views/comments/_list.html.haml +++ b/app/views/comments/_list.html.haml @@ -20,7 +20,8 @@ - edit_path = edit_project_commit_comment_path(project, commentable, comment) - delete_path = project_commit_comment_path(project, commentable, comment) = link_to t("layout.edit"), edit_path if can? :update, comment - = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), delete_path, :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment + =# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), delete_path, :method => "delete", :class => "button", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment + = link_to t("layout.delete"), delete_path, :method => "delete", :confirm => t("layout.comments.confirm_delete") if can? :delete, comment .block .content diff --git a/app/views/user_mailer/issue_assign_notification.en.haml b/app/views/user_mailer/issue_assign_notification.en.haml index 83c33e8ac..bc52f31d2 100644 --- a/app/views/user_mailer/issue_assign_notification.en.haml +++ b/app/views/user_mailer/issue_assign_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. -%p You have been assigned to issue #{ link_to @issue.title, [@issue.project, @issue] } +%p You have been assigned to issue #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/issue_assign_notification.ru.haml b/app/views/user_mailer/issue_assign_notification.ru.haml index a6615d3eb..db96619f7 100644 --- a/app/views/user_mailer/issue_assign_notification.ru.haml +++ b/app/views/user_mailer/issue_assign_notification.ru.haml @@ -1,7 +1,7 @@ %p== Здравствуйте, #{@user.name}. -%p Вам была назначена задача #{ link_to @issue.title, [@issue.project, @issue] } +%p Вам была назначена задача #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Команда поддержки «ROSA Build System» diff --git a/app/views/user_mailer/new_comment_notification.en.haml b/app/views/user_mailer/new_comment_notification.en.haml index 2c7fb66cb..99c1a4bfe 100644 --- a/app/views/user_mailer/new_comment_notification.en.haml +++ b/app/views/user_mailer/new_comment_notification.en.haml @@ -1,14 +1,14 @@ %p== Hello, #{@user.name}. - if @comment.commentable.class == Issue - - link = link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] + - link = link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) - object = 'issue' - elsif @comment.commentable.class == Grit::Commit - - link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id) + - link = link_to @comment.commentable.message, commit_url(@comment.project, @comment.commentable_id) - object = 'commit' -%p #{ link_to @comment.user.uname, user_path(@comment.user)} added new comment to #{object} #{link}. +%p #{ link_to @comment.user.uname, user_url(@comment.user)} added new comment to #{object} #{link}. %p "#{ @comment.body }" -%p== Support team «ROSA Build System» \ No newline at end of file +%p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/new_comment_notification.ru.haml b/app/views/user_mailer/new_comment_notification.ru.haml index d1c0734dd..1dcab28a8 100644 --- a/app/views/user_mailer/new_comment_notification.ru.haml +++ b/app/views/user_mailer/new_comment_notification.ru.haml @@ -1,12 +1,12 @@ %p== Здравствуйте, #{@user.name}. - if @comment.commentable.class == Issue - - link = link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] + - link = link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) - object = 'задаче' - elsif @comment.commentable.class == Grit::Commit - - link = link_to @comment.commentable.message, commit_path(@comment.project, @comment.commentable_id) + - link = link_to @comment.commentable.message, commit_url(@comment.project, @comment.commentable_id) - object = 'коммиту' -%p #{ link_to @comment.user.uname, user_path(@comment.user)} добавил комментарий к #{object} #{link}. +%p #{ link_to @comment.user.uname, user_url(@comment.user)} добавил комментарий к #{object} #{link}. %p "#{ @comment.body }" diff --git a/app/views/user_mailer/new_comment_reply_notification.en.haml b/app/views/user_mailer/new_comment_reply_notification.en.haml index 9324062f2..b2838b2e0 100644 --- a/app/views/user_mailer/new_comment_reply_notification.en.haml +++ b/app/views/user_mailer/new_comment_reply_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. - -%p Your comment into issue #{ link_to @comment.commentable.title, [@comment.commentable.project, @comment.commentable] } has been answered. +- #TODO hmm... this need to be refactored. +%p Your comment into issue #{ link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) } has been answered. %p "#{ @comment.body }" diff --git a/app/views/user_mailer/new_issue_notification.en.haml b/app/views/user_mailer/new_issue_notification.en.haml index f814fa617..7ddda0017 100644 --- a/app/views/user_mailer/new_issue_notification.en.haml +++ b/app/views/user_mailer/new_issue_notification.en.haml @@ -1,7 +1,7 @@ %p== Hello, #{@user.name}. -%p To project #{ link_to @issue.project.name, project_path(@issue.project) } has been added an issue #{ link_to @issue.title, [@issue.project, @issue] } +%p To project #{ link_to @issue.project.name, project_url(@issue.project) } has been added an issue #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Support team «ROSA Build System» diff --git a/app/views/user_mailer/new_issue_notification.ru.haml b/app/views/user_mailer/new_issue_notification.ru.haml index 3a2604cfb..4255c06c2 100644 --- a/app/views/user_mailer/new_issue_notification.ru.haml +++ b/app/views/user_mailer/new_issue_notification.ru.haml @@ -1,7 +1,7 @@ %p== Здравствуйте, #{@user.name}. -%p К проекту #{ link_to @issue.project.name, project_path(@issue.project) } была добавлена задача #{ link_to @issue.title, [@issue.project, @issue] } +%p К проекту #{ link_to @issue.project.name, project_url(@issue.project) } была добавлена задача #{ link_to @issue.title, project_issue_url(@issue.project, @issue) } %p== Команда поддержки «ROSA Build System» diff --git a/lib/modules/models/personal_repository.rb b/lib/modules/models/personal_repository.rb index 8ee4fd3d8..58f8f1805 100644 --- a/lib/modules/models/personal_repository.rb +++ b/lib/modules/models/personal_repository.rb @@ -16,7 +16,7 @@ module Modules pl.description = "#{self.uname}_personal" pl.platform_type = 'personal' pl.distrib_type = APP_CONFIG['distr_types'].first - pl.visibility = 'hidden' + pl.visibility = 'open' pl.save! rep = pl.repositories.build From 2b170fcbf17eca8547feb8f6ceddb50619c56139 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Wed, 15 Feb 2012 22:02:47 +0400 Subject: [PATCH 11/33] Fixed default host in mailer --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index fe08b9089..85f7a95ef 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -37,7 +37,7 @@ Rosa::Application.configure do # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - config.action_mailer.default_url_options = { :host => 'rosa-build.rosalab.ru' } + config.action_mailer.default_url_options = { :host => 'abf.rosalinux.ru' } # Enable threaded mode # config.threadsafe! From 4888993c3fb3eaf840c7f97735e65c68fc437879 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 16 Feb 2012 21:08:08 +0600 Subject: [PATCH 12/33] [refs #134] fixed bug with new project --- app/models/project.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 3970650fe..aed140e2f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -212,9 +212,20 @@ class Project < ActiveRecord::Base end def write_hook + is_production = ENV['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} && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s << " > /dev/null 2>&1" if is_production + s << "\ndone\n" + f.write(s) + end + hook_file = File.join(path, 'hooks', 'post-receive') - FileUtils.cp(File.join(::Rails.root.to_s, 'bin', "post-receive-hook#{ENV['RAILS_ENV'] == 'production' ? '_prod' : '_dev'}"), hook_file) - #File.chmod(0775, hook_file) # need? + FileUtils.cp(hook, hook_file) + FileUtils.rm_rf(hook) + rescue Exception # FIXME end end From a5375c369c2ff911d3d8482cb2a3344cf46e60e9 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 16 Feb 2012 22:29:41 +0600 Subject: [PATCH 13/33] [refs #134] lost env! --- app/models/project.rb | 2 +- lib/tasks/hook.rake | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index aed140e2f..d7c83d852 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -216,7 +216,7 @@ class Project < ActiveRecord::Base 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} && bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" s << " > /dev/null 2>&1" if is_production s << "\ndone\n" f.write(s) diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index baf1e458a..67c5e8140 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -6,8 +6,7 @@ namespace :hook do 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} && \ - bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" + s = "\n /bin/bash -l -c \"cd #{is_production ? '/srv/rosa_build/current' : Rails.root.to_s} && #{is_production ? 'RAILS_ENV=production' : ''} bundle exec rails runner 'Project.delay.process_hook(\"$owner\", \"$reponame\", \"$newrev\", \"$oldrev\", \"$ref\", \"$newrev_type\", \"$oldrev_type\")'\"" s << " > /dev/null 2>&1" if is_production s << "\ndone\n" f.write(s) From 689d15f9fd7a7cde5cfacb3d5cf3ba75666cf771 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 16 Feb 2012 20:23:33 +0200 Subject: [PATCH 14/33] Change blank repo message. Refs #196 --- config/locales/en.yml | 2 +- config/locales/ru.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 05f7ca5f0..67706ca90 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -510,7 +510,7 @@ en: list_header: Event log repositories: - empty: Empty repository + empty: "Repository is still empty. You need to wait some time if you have forked or imported" source: Source commits: Commits commit_diff_too_big: Sorry, commit too big! diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 9b55c3059..a4a252cdc 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -362,7 +362,7 @@ ru: git: repositories: - empty: Пустой репозиторий + empty: "Репозиторий пока пустой. Если форкнули или импортировали, необходимо немного подожать" source: Source commits: Commits commit_diff_too_big: Извините, коммит слишком большой! From 6a0870486689b91ae7cfa5084dd8136047ad85bb Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Thu, 16 Feb 2012 23:08:54 +0400 Subject: [PATCH 15/33] [Refs#196] Update text message for empty text[ru] --- config/locales/ru.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index a4a252cdc..b4c81d717 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -362,7 +362,7 @@ ru: git: repositories: - empty: "Репозиторий пока пустой. Если форкнули или импортировали, необходимо немного подожать" + empty: "Репозиторий пуст. Если вы клонировали(Fork) проект или импортировали пакет, данные скоро появятся" source: Source commits: Commits commit_diff_too_big: Извините, коммит слишком большой! From 3d7b6ea9d655135640b30b8075661d0485a679ee Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Thu, 16 Feb 2012 23:10:58 +0400 Subject: [PATCH 16/33] [Refs#196] Update text message for empty text[en] --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 67706ca90..2e652f118 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -510,7 +510,7 @@ en: list_header: Event log repositories: - empty: "Repository is still empty. You need to wait some time if you have forked or imported" + empty: "Repository is empty. You need to wait some time if you have forked project or imported package" source: Source commits: Commits commit_diff_too_big: Sorry, commit too big! From c55158a8924eea1571b7d503c69b143180ea34d0 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Fri, 17 Feb 2012 15:22:55 +0600 Subject: [PATCH 17/33] [refs #134] some hook task improvements --- lib/tasks/hook.rake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tasks/hook.rake b/lib/tasks/hook.rake index 67c5e8140..d41bbafdb 100644 --- a/lib/tasks/hook.rake +++ b/lib/tasks/hook.rake @@ -14,7 +14,8 @@ namespace :hook do say "Install process.." count = 0 - Project.all.each do |project| + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| hook_file = File.join(project.path, 'hooks', 'post-receive') FileUtils.cp(hook, hook_file) count = count + 1 @@ -28,7 +29,11 @@ namespace :hook do task :remove => :environment do say "process.." count = 0 - Project.all.each { |project| FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive'); count = count + 1} + projects = ENV['project_id'] ? Project.where(:id => eval(ENV['project_id'])) : Project + projects.where('created_at >= ?', Time.now.ago(ENV['period'] ? eval(ENV['period']) : 100.years)).each do |project| + FileUtils.rm_rf File.join(project.path, 'hooks', 'post-receive') + count = count + 1 + end say "Done! Removing from #{count.to_s} repo(s)" end end From 3347a7465339271a4a0565561aa3b6ff39e4fb95 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 17 Feb 2012 16:32:03 +0200 Subject: [PATCH 18/33] Refactor bluepill deploy recipies. Restart DJ through bluepill. Refs #196 --- config/deploy.rb | 3 ++- config/production.pill | 1 + lib/recipes/bluepill.rb | 49 +++++++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index c67c374a3..3dc198504 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -62,8 +62,9 @@ namespace :deploy do end after "deploy:update_code", "deploy:symlink_all", "deploy:migrate" -after "deploy:restart","bluepill:stop", "delayed_job:restart", "deploy:cleanup", "bluepill:start" after "deploy:setup", "deploy:symlink_pids" +after "deploy:restart","bluepill:processes:restart_dj" # "bluepill:restart" +after "deploy:restart", "deploy:cleanup" require 'cape' namespace :rake_tasks do diff --git a/config/production.pill b/config/production.pill index ff49759fc..3199e382a 100644 --- a/config/production.pill +++ b/config/production.pill @@ -11,6 +11,7 @@ Bluepill.application(app_name) do |app| process.start_command = "/usr/bin/env RAILS_ENV=production script/delayed_job start" process.stop_command = "/usr/bin/env RAILS_ENV=production script/delayed_job stop" + process.restart_command = "/usr/bin/env RAILS_ENV=production script/delayed_job restart" process.pid_file = File.join(app.working_dir, 'tmp', 'pids', 'delayed_job.pid') end diff --git a/lib/recipes/bluepill.rb b/lib/recipes/bluepill.rb index a84ff7ecb..969728664 100644 --- a/lib/recipes/bluepill.rb +++ b/lib/recipes/bluepill.rb @@ -3,29 +3,46 @@ Capistrano::Configuration.instance(:must_exist).load do namespace :bluepill do set(:bluepill_binary) {"bundle exec bluepill --no-privileged"} - desc "Load bluepill configuration and start it" + namespace :processes do + desc "Start processes that bluepill is monitoring" + task :start, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} start" + end + + desc "Stop processes that bluepill is monitoring" + task :stop, :roles => [:app], :on_error => :continue do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} stop" + end + + desc "Restart processes that bluepill is monitoring" + task :restart, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart" + end + + desc "Prints bluepills monitored processes statuses" + task :status, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} status" + end + + desc "Restart DJ process" + task :restart_dj, :roles => [:app] do + run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart delayed_job" + end + end + + desc "Start a bluepill process and load a config" task :start, :roles => [:app] do run "cd #{fetch :current_path} && #{try_sudo} APP_NAME=#{fetch :application} #{bluepill_binary} load config/production.pill" end - desc "Stop processes that bluepill is monitoring" - task :stop, :roles => [:app], :on_error => :continue do - run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} stop" - end - - task :restart, :roles => [:app] do - # run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} restart" - stop; quit; start - end - - desc "Stop processes that bluepill is monitoring and quit bluepill" - task :quit, :roles => [:app] do + desc "Quit bluepill" + task :stop, :roles => [:app] do run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} quit" end - desc "Prints bluepills monitored processes statuses" - task :status, :roles => [:app] do - run "cd #{fetch :current_path} && #{try_sudo} #{bluepill_binary} #{fetch :application} status" + desc "Completely restart bluepill and monitored services" + task :restart, :roles => [:app] do + processes.stop; stop; start end end end From ed60751dfac549fc3621c337db711e0a05ad2018 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 21 Feb 2012 01:13:05 +0200 Subject: [PATCH 19/33] Delegate all repo abilities to platform. Remove repository owner and relations. Fix templates and specs. Refactor and code cleanup. Refs #205 --- .../personal_repositories_controller.rb | 2 +- app/controllers/repositories_controller.rb | 1 - app/models/ability.rb | 14 +++--- app/models/group.rb | 21 ++++---- app/models/relation.rb | 7 +-- app/models/repository.rb | 50 ++++++------------- app/models/user.rb | 15 +++--- .../projects_list.html.haml | 10 ---- .../personal_repositories/show.html.haml | 6 --- .../repositories/projects_list.html.haml | 5 -- app/views/repositories/show.html.haml | 5 -- ...0120220185458_remove_repositories_owner.rb | 12 +++++ db/schema.rb | 4 +- lib/modules/models/personal_repository.rb | 1 - .../collaborators_controller_spec.rb | 1 + spec/controllers/groups_controller_spec.rb | 1 + spec/controllers/members_controller_spec.rb | 1 + .../personal_repositories_controller_spec.rb | 5 +- .../repositories_controller_spec.rb | 6 +-- spec/factories/repository_factory.rb | 16 ++---- spec/models/cancan_spec.rb | 11 ++-- spec/models/comment_for_commit_spec.rb | 1 + spec/models/comment_spec.rb | 1 + spec/models/repository_spec.rb | 11 ++-- spec/models/subscribe_spec.rb | 1 + 25 files changed, 77 insertions(+), 131 deletions(-) create mode 100644 db/migrate/20120220185458_remove_repositories_owner.rb diff --git a/app/controllers/personal_repositories_controller.rb b/app/controllers/personal_repositories_controller.rb index c76c21623..122ed928a 100644 --- a/app/controllers/personal_repositories_controller.rb +++ b/app/controllers/personal_repositories_controller.rb @@ -12,7 +12,7 @@ class PersonalRepositoriesController < ApplicationController else @projects = @repository.projects.recent.paginate :page => params[:project_page], :per_page => 30 end - @user = @repository.owner + @user = @repository.platform.owner @urpmi_commands = @repository.platform.urpmi_list(request.host) end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 317683699..693be6034 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -42,7 +42,6 @@ class RepositoriesController < ApplicationController def create @repository = Repository.new(params[:repository]) @repository.platform_id = params[:platform_id] - @repository.owner = get_owner if @repository.save flash[:notice] = t('flash.repository.saved') redirect_to @repositories_path diff --git a/app/models/ability.rb b/app/models/ability.rb index 2b58c1329..8a6ac63a4 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -66,18 +66,16 @@ class Ability can :read, Platform, :owner_type => 'User', :owner_id => user.id can :read, Platform, :owner_type => 'Group', :owner_id => user.group_ids can(:read, Platform, read_relations_for('platforms')) {|platform| local_reader? platform} - can(:update, Platform) {|platform| local_admin? platform} + can([:update, :build_all], Platform) {|platform| local_admin? platform} can([:freeze, :unfreeze, :destroy], Platform) {|platform| owner? platform} can :autocomplete_user_uname, Platform - # TODO delegate to platform? can :read, Repository, :platform => {:visibility => 'open'} - can :read, Repository, :owner_type => 'User', :owner_id => user.id - can :read, Repository, :owner_type => 'Group', :owner_id => user.group_ids - can(:read, Repository, read_relations_for('repositories')) {|repository| local_reader? repository} - can(:create, Repository) {|repository| local_admin? repository.platform} - can([:update, :add_project, :remove_project], Repository) {|repository| local_admin? repository} - can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository} + can :read, Repository, :platform => {:owner_type => 'User', :owner_id => user.id} + can :read, Repository, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} + can(:read, Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} + can([:create, :update, :projects_list, :add_project, :remove_project], Repository) {|repository| local_admin? repository.platform} + can([:change_visibility, :settings, :destroy], Repository) {|repository| owner? repository.platform} can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id} can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} diff --git a/app/models/group.rb b/app/models/group.rb index c68147305..a7d96dcc7 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -2,16 +2,16 @@ class Group < ActiveRecord::Base belongs_to :owner, :class_name => 'User' - has_many :own_projects, :as => :owner, :class_name => 'Project' - + has_many :relations, :as => :object, :dependent => :destroy has_many :objects, :as => :target, :class_name => 'Relation' has_many :targets, :as => :object, :class_name => 'Relation' has_many :members, :through => :objects, :source => :object, :source_type => 'User', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true - has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true, :dependent => :destroy - has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true - has_many :relations, :as => :object, :dependent => :destroy + has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true + + has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy + has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy validates :name, :owner, :presence => true validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } @@ -26,11 +26,12 @@ class Group < ActiveRecord::Base after_initialize lambda {|r| r.name ||= r.uname } # default include Modules::Models::PersonalRepository -# include Modules::Models::Owner + # include Modules::Models::Owner protected - def add_owner_to_members - Relation.create_with_role(self.owner, self, 'admin') -# members << self.owner if !members.exists?(:id => self.owner.id) - end + + def add_owner_to_members + Relation.create_with_role(self.owner, self, 'admin') + # members << self.owner if !members.exists?(:id => self.owner.id) + end end diff --git a/app/models/relation.rb b/app/models/relation.rb index 59c31d29d..6847b097b 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -22,7 +22,8 @@ class Relation < ActiveRecord::Base end protected - def add_default_role - self.role = ROLES.first if role.nil? || role.empty? - end + + def add_default_role + self.role = ROLES.first if role.nil? || role.empty? + end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 379d3deac..f5c7d4c13 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,27 +1,19 @@ # -*- encoding : utf-8 -*- class Repository < ActiveRecord::Base belongs_to :platform - belongs_to :owner, :polymorphic => true has_many :projects, :through => :project_to_repositories #, :dependent => :destroy has_many :project_to_repositories, :validate => true, :dependent => :destroy - has_many :relations, :as => :target, :dependent => :destroy - has_many :objects, :as => :target, :class_name => 'Relation', :dependent => :destroy - has_many :members, :through => :objects, :source => :object, :source_type => 'User' - has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' - validates :description, :uniqueness => {:scope => :platform_id}, :presence => true validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ } - # validates :platform_id, :presence => true # if you uncomment this platform clone will not work scope :recent, order("name ASC") before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy - after_create :add_admin_relations - attr_accessible :description, :name #, :platform_id + attr_accessible :description, :name def full_clone(attrs) # owner clone.tap do |c| # dup @@ -31,8 +23,6 @@ class Repository < ActiveRecord::Base end end - include Modules::Models::Owner - class << self def build_stub(platform) rep = Repository.new @@ -43,31 +33,21 @@ class Repository < ActiveRecord::Base protected - def xml_rpc_create - result = BuildServer.create_repo name, platform.name - if result == BuildServer::SUCCESS - return true - else - raise "Failed to create repository #{name} inside platform #{platform.name} with code #{result}." - end + def xml_rpc_create + result = BuildServer.create_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to create repository #{name} inside platform #{platform.name} with code #{result}." end + end - def xml_rpc_destroy - result = BuildServer.delete_repo name, platform.name - if result == BuildServer::SUCCESS - return true - else - raise "Failed to delete repository #{name} inside platform #{platform.name} with code #{result}." - end - end - - def add_admin_relations - platform.relations.where(:role => 'admin').each do |rel| - if !relations.exists?(:role => 'admin', :object_type => rel.object_type, :object_id => rel.object_id) && rel.object != owner - r = relations.build(:role => 'admin', :object_type => rel.object_type) - r.object_id = rel.object_id - r.save - end - end + def xml_rpc_destroy + result = BuildServer.delete_repo name, platform.name + if result == BuildServer::SUCCESS + return true + else + raise "Failed to delete repository #{name} inside platform #{platform.name} with code #{result}." end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 69dac7a6a..51eaba5b4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,22 +11,19 @@ class User < ActiveRecord::Base has_many :authentications, :dependent => :destroy has_many :build_lists, :dependent => :destroy + has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy + has_many :comments, :dependent => :destroy has_many :relations, :as => :object, :dependent => :destroy has_many :targets, :as => :object, :class_name => 'Relation' - has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy - has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group' - has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy - has_many :own_repositories, :as => :owner, :class_name => 'Repository', :dependent => :destroy - - has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true + has_many :groups, :through => :targets, :source => :target, :source_type => 'Group', :autosave => true has_many :platforms, :through => :targets, :source => :target, :source_type => 'Platform', :autosave => true - has_many :repositories, :through => :targets, :source => :target, :source_type => 'Repository', :autosave => true - has_many :subscribes, :foreign_key => :user_id, :dependent => :destroy - has_many :comments, :dependent => :destroy + has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy + has_many :own_groups, :foreign_key => :owner_id, :class_name => 'Group', :dependent => :destroy + has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy include Modules::Models::PersonalRepository diff --git a/app/views/personal_repositories/projects_list.html.haml b/app/views/personal_repositories/projects_list.html.haml index 4766fcb0b..2f3d8c3c0 100644 --- a/app/views/personal_repositories/projects_list.html.haml +++ b/app/views/personal_repositories/projects_list.html.haml @@ -20,21 +20,11 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.name, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.name, url_for(@repository.owner) %p %b = t("activerecord.attributes.platform.visibility") \: = @repository.platform.visibility - %p - %b - = t("activerecord.attributes.repository.platform") - \: - = link_to @repository.platform.name, platform_path(@platform) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/personal_repositories/show.html.haml b/app/views/personal_repositories/show.html.haml index f8f346094..c40d3a1d5 100644 --- a/app/views/personal_repositories/show.html.haml +++ b/app/views/personal_repositories/show.html.haml @@ -6,12 +6,6 @@ %li= link_to t("layout.personal_repositories.private_users"), platform_private_users_path(@repository.platform) if @repository.platform.hidden? .content .inner - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.name, url_for(@repository.owner) - = render 'shared/urpmi_list', :urpmi_commands => @urpmi_commands .wat-cf =# link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/repositories/projects_list.html.haml b/app/views/repositories/projects_list.html.haml index af5a9a1a9..d9ca336d8 100644 --- a/app/views/repositories/projects_list.html.haml +++ b/app/views/repositories/projects_list.html.haml @@ -21,11 +21,6 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.description, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.uname, url_for(@repository.owner) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") diff --git a/app/views/repositories/show.html.haml b/app/views/repositories/show.html.haml index 72ab6577a..7e23d2b0d 100644 --- a/app/views/repositories/show.html.haml +++ b/app/views/repositories/show.html.haml @@ -21,11 +21,6 @@ = t("activerecord.attributes.repository.platform") \: = link_to @repository.platform.description, url_for(@repository.platform) - %p - %b - = t("activerecord.attributes.repository.owner") - \: - = link_to @repository.owner.try(:name), url_for(@repository.owner) .wat-cf = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), @repository_path, :method => "delete", :class => "button", :confirm => t("layout.repositories.confirm_delete") if can? :destroy, @repository diff --git a/db/migrate/20120220185458_remove_repositories_owner.rb b/db/migrate/20120220185458_remove_repositories_owner.rb new file mode 100644 index 000000000..88c85a855 --- /dev/null +++ b/db/migrate/20120220185458_remove_repositories_owner.rb @@ -0,0 +1,12 @@ +class RemoveRepositoriesOwner < ActiveRecord::Migration + def self.up + remove_column :repositories, :owner_id + remove_column :repositories, :owner_type + Relation.delete_all(:target_type => 'Repository') + end + + def self.down + add_column :repositories, :owner_id, :integer + add_column :repositories, :owner_type, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 2498d7f31..6814bbbc7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120210141153) do +ActiveRecord::Schema.define(:version => 20120220185458) do create_table "arches", :force => true do |t| t.string "name", :null => false @@ -294,8 +294,6 @@ ActiveRecord::Schema.define(:version => 20120210141153) do t.datetime "created_at" t.datetime "updated_at" t.string "name", :null => false - t.integer "owner_id" - t.string "owner_type" end create_table "rpms", :force => true do |t| diff --git a/lib/modules/models/personal_repository.rb b/lib/modules/models/personal_repository.rb index 58f8f1805..5b903ecae 100644 --- a/lib/modules/models/personal_repository.rb +++ b/lib/modules/models/personal_repository.rb @@ -20,7 +20,6 @@ module Modules pl.save! rep = pl.repositories.build - rep.owner = pl.owner rep.name = 'main' rep.description = 'main' rep.save! diff --git a/spec/controllers/collaborators_controller_spec.rb b/spec/controllers/collaborators_controller_spec.rb index c7dcaa4b5..858bd3c05 100644 --- a/spec/controllers/collaborators_controller_spec.rb +++ b/spec/controllers/collaborators_controller_spec.rb @@ -37,6 +37,7 @@ end describe CollaboratorsController do before(:each) do + stub_rsync_methods @project = Factory(:project) @another_user = Factory(:user) @update_params = {:user => {:read => {@another_user.id => '1'}}} diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 2ccf820b3..4238babf8 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe GroupsController do before(:each) do + stub_rsync_methods @group = Factory(:group) @another_user = Factory(:user) @create_params = {:group => {:name => 'grp1', :uname => 'un_grp1'}} diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 512bbc73c..ab8ab5fbe 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe MembersController do before(:each) do + stub_rsync_methods @group = Factory(:group) @user = @group.owner set_session_for @user diff --git a/spec/controllers/personal_repositories_controller_spec.rb b/spec/controllers/personal_repositories_controller_spec.rb index 50ff6f03f..6e020d61e 100644 --- a/spec/controllers/personal_repositories_controller_spec.rb +++ b/spec/controllers/personal_repositories_controller_spec.rb @@ -92,9 +92,6 @@ describe PersonalRepositoriesController do @project.update_attribute(:owner, @user) - @repository.update_attribute(:owner, @user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') - @repository.platform.update_attribute(:owner, @user) @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end @@ -108,7 +105,7 @@ describe PersonalRepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end it_should_behave_like 'personal repository viewer' diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 935de2e40..422fb5128 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -79,8 +79,8 @@ describe RepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.update_attribute(:owner, @user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') + @repository.platform.update_attribute(:owner, @user) + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'admin') end it_should_behave_like 'repository user with owner rights' @@ -90,7 +90,7 @@ describe RepositoriesController do before(:each) do @user = Factory(:user) set_session_for(@user) - @repository.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') + @repository.platform.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader') end it_should_behave_like 'repository user with reader rights' diff --git a/spec/factories/repository_factory.rb b/spec/factories/repository_factory.rb index 2188bc17e..4af755b28 100644 --- a/spec/factories/repository_factory.rb +++ b/spec/factories/repository_factory.rb @@ -3,18 +3,12 @@ Factory.define(:repository) do |p| p.description { Factory.next(:string) } p.name { Factory.next(:unixname) } p.association :platform, :factory => :platform - p.association :owner, :factory => :user end -Factory.define(:personal_repository, :class => Repository) do |p| - p.description { Factory.next(:string) } - p.name { Factory.next(:unixname) } - p.association :platform, :factory => :platform - p.association :owner, :factory => :user - - p.after_create { |rep| - rep.platform.platform_type = 'personal' - rep.platform.visibility = 'hidden' - rep.platform.save! +Factory.define(:personal_repository, :parent => :repository) do |p| + p.after_create {|r| + r.platform.platform_type = 'personal' + r.platform.visibility = 'hidden' + r.platform.save! } end diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index 597d5dd38..248a502d6 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -278,24 +278,19 @@ describe CanCan do context 'with owner rights' do before(:each) do - @repository.update_attribute(:owner, @user) + @repository.platform.update_attribute(:owner, @user) end - [:read, :update, :destroy, :add_project, :remove_project, :change_visibility, :settings].each do |action| + [:read, :create, :update, :destroy, :add_project, :remove_project, :change_visibility, :settings].each do |action| it "should be able to #{action} repository" do @ability.should be_able_to(action, @repository) end end - - it do - @repository.platform.update_attribute(:owner, @user) - @ability.should be_able_to(:create, @repository) - end end context 'with read rights' do before(:each) do - @repository.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') + @repository.platform.relations.create!(:object_id => @user.id, :object_type => 'User', :role => 'reader') end it "should be able to read repository" do diff --git a/spec/models/comment_for_commit_spec.rb b/spec/models/comment_for_commit_spec.rb index 6f693d03e..446131e5e 100644 --- a/spec/models/comment_for_commit_spec.rb +++ b/spec/models/comment_for_commit_spec.rb @@ -21,6 +21,7 @@ def set_comments_data_for_commit end describe Comment do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index b44f85684..d692beb19 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -15,6 +15,7 @@ def set_commentable_data end describe Comment do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 9056e45c7..c742a5671 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -10,14 +10,9 @@ describe Repository do @params = {:name => 'tst_platform', :description => 'test platform'} end - it 'it should increase Relations.count by 1' do - rep = Repository.new(@params) - rep.platform = @platform - rep.owner = @platform.owner - rep.save! - Relation.by_object(rep.owner).by_target(rep).count.should eql(1) -# (@platform.owner.repositories.where(:platform_id => @platform.id).count == 1).should be_true + it 'it should increase Repository.count by 1' do + rep = Repository.create(@params) {|r| r.platform = @platform} + @platform.repositories.count.should eql(1) end end - #pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/subscribe_spec.rb b/spec/models/subscribe_spec.rb index eff91b9a8..40ccddd3c 100644 --- a/spec/models/subscribe_spec.rb +++ b/spec/models/subscribe_spec.rb @@ -12,6 +12,7 @@ def set_testable_data end describe Subscribe do + before { stub_rsync_methods } context 'for global admin user' do before(:each) do @user = Factory(:admin) From 5b29de93af89c7bdb378ecacd8c4ccf2c4395929 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 21 Feb 2012 23:27:11 +0200 Subject: [PATCH 20/33] Refactor platform clone controller and routes. Refactor and fix clone process for platform, repository, product. Place XML RPC clone request to DJ. Refs #207 --- app/controllers/platforms_controller.rb | 26 +++++++++++++------------ app/models/platform.rb | 12 +++++------- app/models/product.rb | 6 +++--- app/models/repository.rb | 6 +++--- app/views/platforms/clone.html.haml | 2 +- config/routes.rb | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 060fe99e0..06eb87c45 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -109,19 +109,21 @@ class PlatformsController < ApplicationController end def clone - if request.post? - @cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], - :owner_id => current_user.id, :owner_type => current_user.class.to_s) - if @cloned.persisted? - flash[:notice] = I18n.t("flash.platform.clone_success") - redirect_to @cloned - else - flash[:error] = @cloned.errors.full_messages.join('. ') - end + @cloned = Platform.new + @cloned.name = @platform.name + "_clone" + @cloned.description = @platform.description + "_clone" + end + + def make_clone + @cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], + :owner_id => current_user.id, :owner_type => current_user.class.to_s) + if @cloned.persisted? # valid? + flash[:notice] = I18n.t("flash.platform.clone_success") + redirect_to @cloned else - @cloned = Platform.new - @cloned.name = @platform.name + "_clone" - @cloned.description = @platform.description + "_clone" + raise @cloned.repositories.first.inspect + flash[:error] = @cloned.errors.full_messages.join('. ') + render 'clone' end end diff --git a/app/models/platform.rb b/app/models/platform.rb index e7b552ba2..773aa3111 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -98,23 +98,21 @@ class Platform < ActiveRecord::Base platform_type == 'personal' end - def full_clone(attrs) # :description, :name, :owner + def full_clone(attrs = {}) # :description, :name, :owner clone.tap do |c| - c.attributes = attrs + c.attributes = attrs # do not set protected c.updated_at = nil; c.created_at = nil # :id = nil c.parent = self - new_attrs = {:platform_id => nil} - c.repositories = repositories.map{|r| r.full_clone(new_attrs.merge(:owner_id => attrs[:owner_id], :owner_type => attrs[:owner_type]))} - c.products = products.map{|p| p.full_clone(new_attrs)} + c.repositories = repositories.map(&:full_clone) + c.products = products.map(&:full_clone) end end - # TODO * make it Delayed Job * def make_clone(attrs) p = full_clone(attrs) begin Thread.current[:skip] = true - p.save and xml_rpc_clone(attrs[:name]) + p.save and self.delay.xml_rpc_clone(attrs[:name]) ensure Thread.current[:skip] = false end diff --git a/app/models/product.rb b/app/models/product.rb index 94e355d20..14cd10549 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -59,10 +59,10 @@ class Product < ActiveRecord::Base EOF end - def full_clone(attrs) # owner + def full_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs - c.updated_at = nil; c.created_at = nil # :id = nil + c.attributes = attrs # do not set protected + c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil end end diff --git a/app/models/repository.rb b/app/models/repository.rb index f5c7d4c13..79e49a345 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -15,10 +15,10 @@ class Repository < ActiveRecord::Base attr_accessible :description, :name - def full_clone(attrs) # owner + def full_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs - c.updated_at = nil; c.created_at = nil # :id = nil + c.attributes = attrs # do not set protected + c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil c.projects = projects end end diff --git a/app/views/platforms/clone.html.haml b/app/views/platforms/clone.html.haml index 045e2956a..01eb9b7be 100644 --- a/app/views/platforms/clone.html.haml +++ b/app/views/platforms/clone.html.haml @@ -8,7 +8,7 @@ %h2.title = t("layout.platforms.clone_header") .inner - = form_for @cloned, :url => clone_platform_path(@platform), :html => { :class => :form } do |f| + = form_for @cloned, :url => make_clone_platform_path(@platform), :html => { :class => :form } do |f| .group = f.label :name, :class => :label = f.text_field :name, :class => 'text_field' diff --git a/config/routes.rb b/config/routes.rb index 1963dc03a..947f2b27a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,7 +71,7 @@ Rosa::Application.routes.draw do post 'freeze' post 'unfreeze' get 'clone' - post 'clone' + post 'make_clone' post 'build_all' end From 5829ab87e90f86e1174fd5fef99cf794688d865c Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 21 Feb 2012 23:43:06 +0200 Subject: [PATCH 21/33] Remove raise. Refs #207 --- app/controllers/platforms_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 06eb87c45..5e6a467f3 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -121,7 +121,6 @@ class PlatformsController < ApplicationController flash[:notice] = I18n.t("flash.platform.clone_success") redirect_to @cloned else - raise @cloned.repositories.first.inspect flash[:error] = @cloned.errors.full_messages.join('. ') render 'clone' end From 8f4c20754565f67c2e750d08f784d15bbf7ae521 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 22 Feb 2012 14:35:40 +0200 Subject: [PATCH 22/33] Place platform destroy to background. Redo clone process to 2 phases - base_clone and relations_clone. Place relations clone and XML RPC to background. Remove unneeded validations. Refactor xml_rpc_clone. Refs #207 --- app/controllers/platforms_controller.rb | 7 +++-- app/models/platform.rb | 38 +++++++++++++++---------- app/models/project.rb | 2 +- app/models/repository.rb | 8 +++--- lib/ext/core/object.rb | 10 +++++++ 5 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 lib/ext/core/object.rb diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 5e6a467f3..c357b526a 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -115,9 +115,10 @@ class PlatformsController < ApplicationController end def make_clone - @cloned = @platform.make_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], + @cloned = @platform.base_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], :owner_id => current_user.id, :owner_type => current_user.class.to_s) - if @cloned.persisted? # valid? + if with_skip{@cloned.save} + @cloned.delay.clone_complete flash[:notice] = I18n.t("flash.platform.clone_success") redirect_to @cloned else @@ -127,7 +128,7 @@ class PlatformsController < ApplicationController end def destroy - @platform.destroy if @platform + @platform.delay.destroy if @platform flash[:notice] = t("flash.platform.destroyed") redirect_to root_path diff --git a/app/models/platform.rb b/app/models/platform.rb index 773aa3111..305addb84 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -14,7 +14,7 @@ class Platform < ActiveRecord::Base has_many :members, :through => :objects, :source => :object, :source_type => 'User' has_many :groups, :through => :objects, :source => :object, :source_type => 'Group' - validates :description, :presence => true, :uniqueness => true + validates :description, :presence => true validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} @@ -98,25 +98,33 @@ class Platform < ActiveRecord::Base platform_type == 'personal' end - def full_clone(attrs = {}) # :description, :name, :owner + def base_clone(attrs = {}) # :description, :name, :owner clone.tap do |c| c.attributes = attrs # do not set protected c.updated_at = nil; c.created_at = nil # :id = nil c.parent = self - c.repositories = repositories.map(&:full_clone) - c.products = products.map(&:full_clone) end end - def make_clone(attrs) - p = full_clone(attrs) - begin - Thread.current[:skip] = true - p.save and self.delay.xml_rpc_clone(attrs[:name]) - ensure - Thread.current[:skip] = false + # def full_clone(attrs = {}) # :description, :name, :owner + # clone.tap do |c| + # c.attributes = attrs # do not set protected + # c.updated_at = nil; c.created_at = nil # :id = nil + # c.parent = self + # c.repositories = repositories.map(&:full_clone) + # c.products = products.map(&:full_clone) + # end + # end + + def clone_relations(from = parent) + self.repositories = from.repositories.map(&:full_clone) + self.products = from.products.map(&:full_clone) + end + + def clone_complete + with_skip do + clone_relations and xml_rpc_clone end - p end def name @@ -179,12 +187,12 @@ class Platform < ActiveRecord::Base end end - def xml_rpc_clone(new_name) - result = BuildServer.clone_platform new_name, self.name, APP_CONFIG['root_path'] + '/platforms' + def xml_rpc_clone(old_name = parent.name, new_name = name) + result = BuildServer.clone_platform new_name, old_name, APP_CONFIG['root_path'] + '/platforms' if result == BuildServer::SUCCESS return true else - raise "Failed to clone platform #{name} with code #{result}. Path: #{build_path(name)} to platform #{new_name}" + raise "Failed to clone platform #{old_name} with code #{result}. Path: #{build_path(old_name)} to platform #{new_name}" end end diff --git a/app/models/project.rb b/app/models/project.rb index d7c83d852..c9804c528 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -18,7 +18,7 @@ class Project < ActiveRecord::Base has_many :collaborators, :through => :relations, :source => :object, :source_type => 'User' has_many :groups, :through => :relations, :source => :object, :source_type => 'Group' - validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ } + validates :name, :uniqueness => {:scope => [:owner_id, :owner_type], :case_sensitive => false}, :presence => true, :format => {:with => /^[a-zA-Z0-9_\-\+\.]+$/} validates :owner, :presence => true validate { errors.add(:base, :can_have_less_or_equal, :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } # validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?} diff --git a/app/models/repository.rb b/app/models/repository.rb index 79e49a345..45b1e116d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -2,11 +2,11 @@ class Repository < ActiveRecord::Base belongs_to :platform - has_many :projects, :through => :project_to_repositories #, :dependent => :destroy - has_many :project_to_repositories, :validate => true, :dependent => :destroy + has_many :project_to_repositories, :dependent => :destroy, :validate => true + has_many :projects, :through => :project_to_repositories - validates :description, :uniqueness => {:scope => :platform_id}, :presence => true - validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ } + validates :description, :presence => true + validates :name, :uniqueness => {:scope => :platform_id, :case_sensitive => false}, :presence => true, :format => {:with => /^[a-z0-9_\-]+$/} scope :recent, order("name ASC") diff --git a/lib/ext/core/object.rb b/lib/ext/core/object.rb new file mode 100644 index 000000000..d2856a51c --- /dev/null +++ b/lib/ext/core/object.rb @@ -0,0 +1,10 @@ +class Object + def with_skip + begin + Thread.current[:skip] = true + yield + ensure + Thread.current[:skip] = false + end + end +end From 9eb191da7b894f6a3687690ad9cc558c97579b2b Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Wed, 22 Feb 2012 22:24:29 +0200 Subject: [PATCH 23/33] Redo clone logic. Split clone process for repositories. Optimize and refactor. Refs #207 --- app/controllers/platforms_controller.rb | 6 ++---- app/models/platform.rb | 20 +++++--------------- app/models/product.rb | 5 +++-- app/models/repository.rb | 20 ++++++++++++++++---- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index c357b526a..3b0151bd6 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -115,10 +115,8 @@ class PlatformsController < ApplicationController end def make_clone - @cloned = @platform.base_clone(:name => params[:platform]['name'], :description => params[:platform]['description'], - :owner_id => current_user.id, :owner_type => current_user.class.to_s) - if with_skip{@cloned.save} - @cloned.delay.clone_complete + @cloned = @platform.full_clone params[:platform].merge(:owner => current_user) + if @cloned.persisted? flash[:notice] = I18n.t("flash.platform.clone_success") redirect_to @cloned else diff --git a/app/models/platform.rb b/app/models/platform.rb index 305addb84..3b7551703 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -100,30 +100,20 @@ class Platform < ActiveRecord::Base def base_clone(attrs = {}) # :description, :name, :owner clone.tap do |c| - c.attributes = attrs # do not set protected + c.attributes = attrs # attrs.each {|k,v| c.send("#{k}=", v)} c.updated_at = nil; c.created_at = nil # :id = nil c.parent = self end end - # def full_clone(attrs = {}) # :description, :name, :owner - # clone.tap do |c| - # c.attributes = attrs # do not set protected - # c.updated_at = nil; c.created_at = nil # :id = nil - # c.parent = self - # c.repositories = repositories.map(&:full_clone) - # c.products = products.map(&:full_clone) - # end - # end - def clone_relations(from = parent) - self.repositories = from.repositories.map(&:full_clone) + self.repositories = from.repositories.map{|r| r.full_clone(:platform_id => id)} self.products = from.products.map(&:full_clone) end - def clone_complete - with_skip do - clone_relations and xml_rpc_clone + def full_clone(attrs = {}) + base_clone(attrs).tap do |c| + with_skip {c.save} and c.clone_relations(self) and c.delay.xml_rpc_clone end end diff --git a/app/models/product.rb b/app/models/product.rb index 14cd10549..536b3dbbf 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -61,8 +61,9 @@ class Product < ActiveRecord::Base def full_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs # do not set protected - c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil + c.platform_id = nil + attrs.each {|k,v| c.send("#{k}=", v)} + c.updated_at = nil; c.created_at = nil # :id = nil end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 45b1e116d..50b57cb4a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -15,11 +15,23 @@ class Repository < ActiveRecord::Base attr_accessible :description, :name - def full_clone(attrs = {}) + def base_clone(attrs = {}) clone.tap do |c| # dup - c.attributes = attrs # do not set protected - c.platform_id = nil; c.updated_at = nil; c.created_at = nil # :id = nil - c.projects = projects + c.platform_id = nil + attrs.each {|k,v| c.send("#{k}=", v)} + c.updated_at = nil; c.created_at = nil # :id = nil + end + end + + def clone_relations(from) + with_skip do + from.projects.find_each {|p| self.projects << p} + end + end + + def full_clone(attrs = {}) + base_clone(attrs).tap do |c| + with_skip {c.save} and c.delay.clone_relations(self) end end From b192ebdceabf514ebcbee29f050948c3e6e5a9ca Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 00:57:43 +0200 Subject: [PATCH 24/33] Create directory for platform before clone. Fix created directory permissions. Increase timeout during XML RPC clone. Switch off cascade XML RPC requests during platform destroy. Refs #207 --- app/models/platform.rb | 11 ++++++++++- app/models/project_to_repository.rb | 2 +- app/models/repository.rb | 2 +- lib/build_server.rb | 4 +++- lib/modules/models/rsync_stub.rb | 4 ++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index 3b7551703..713283b5c 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -18,6 +18,7 @@ class Platform < ActiveRecord::Base validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ } validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} + before_create :create_directory, :if => lambda {Thread.current[:skip]} # TODO remove this when core will be ready before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy # before_update :check_freezing @@ -131,9 +132,13 @@ class Platform < ActiveRecord::Base end end + def create_directory + system("sudo mkdir -p -m 0777 #{path}") + end + def mount_directory_for_rsync # umount_directory_for_rsync # TODO ignore errors - system("sudo mkdir -p #{mount_path}") + system("sudo mkdir -p -m 0777 #{mount_path}") system("sudo mount --bind #{path} #{mount_path}") Arch.all.each do |arch| str = "country=Russian Federation,city=Moscow,latitude=52.18,longitude=48.88,bw=1GB,version=2011,arch=#{arch.name},type=distrib,url=#{public_downloads_url}\n" @@ -153,6 +158,10 @@ class Platform < ActiveRecord::Base end end + def destroy + with_skip {super} # avoid cascade XML RPC requests + end + protected def build_path(dir) diff --git a/app/models/project_to_repository.rb b/app/models/project_to_repository.rb index 7bf5adba5..611bb0bbe 100644 --- a/app/models/project_to_repository.rb +++ b/app/models/project_to_repository.rb @@ -6,7 +6,7 @@ class ProjectToRepository < ActiveRecord::Base delegate :path, :to => :project after_create lambda { project.xml_rpc_create(repository) }, :unless => lambda {Thread.current[:skip]} - after_destroy lambda { project.xml_rpc_destroy(repository) } + after_destroy lambda { project.xml_rpc_destroy(repository) }, :unless => lambda {Thread.current[:skip]} # after_rollback lambda { project.xml_rpc_destroy(repository) rescue true if new_record? } validate :one_project_in_platform_repositories diff --git a/app/models/repository.rb b/app/models/repository.rb index 50b57cb4a..7684ee005 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -11,7 +11,7 @@ class Repository < ActiveRecord::Base scope :recent, order("name ASC") before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} - before_destroy :xml_rpc_destroy + before_destroy :xml_rpc_destroy, :unless => lambda {Thread.current[:skip]} attr_accessible :description, :name diff --git a/lib/build_server.rb b/lib/build_server.rb index feb066b19..2bf6cfc9a 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -49,10 +49,12 @@ class BuildServer end def self.clone_repo new_name, old_name, new_platform_name + tmp = self.client.timeout # TODO remove this when core will be ready + self.client.timeout = 30.minutes self.client.call('clone_repo', new_name, old_name, new_platform_name) + self.client.timeout = tmp end - def self.publish_container container_id self.client.call('publish_container', container_id) end diff --git a/lib/modules/models/rsync_stub.rb b/lib/modules/models/rsync_stub.rb index bbf101d76..7865c232f 100644 --- a/lib/modules/models/rsync_stub.rb +++ b/lib/modules/models/rsync_stub.rb @@ -5,6 +5,10 @@ module Modules extend ActiveSupport::Concern included do + def create_directory + true + end + def mount_directory_for_rsync true end From a2a29e2baade24a64588c5dde1c8c639c68a5814 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 17:17:02 +0200 Subject: [PATCH 25/33] Rescue and ignore timeout error during long XML RPC. Apply add_branch script. Refs #207 --- lib/build_server.rb | 16 +++++++++------- lib/tasks/add_branch.rake | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 lib/tasks/add_branch.rake diff --git a/lib/build_server.rb b/lib/build_server.rb index 2bf6cfc9a..9aa2be76e 100644 --- a/lib/build_server.rb +++ b/lib/build_server.rb @@ -28,33 +28,35 @@ class BuildServer self.client.call('add_platform', name, platforms_root_folder, repos, distrib_type) end - def self.delete_platform name self.client.call('delete_platform', name) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end - def self.clone_platform new_name, old_name, new_root_folder self.client.call('clone_platform', new_name, old_name, new_root_folder) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end - def self.create_repo name, platform_name self.client.call('create_repository', name, platform_name) end - def self.delete_repo name, platform_name self.client.call('delete_repository', name, platform_name) + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end def self.clone_repo new_name, old_name, new_platform_name - tmp = self.client.timeout # TODO remove this when core will be ready - self.client.timeout = 30.minutes self.client.call('clone_repo', new_name, old_name, new_platform_name) - self.client.timeout = tmp + rescue Timeout::Error => e # TODO remove this when core will be ready + 0 end + def self.publish_container container_id self.client.call('publish_container', container_id) end diff --git a/lib/tasks/add_branch.rake b/lib/tasks/add_branch.rake new file mode 100644 index 000000000..1a7b96bd5 --- /dev/null +++ b/lib/tasks/add_branch.rake @@ -0,0 +1,22 @@ +require 'highline/import' + +desc "Add branch for platform projects" +task :add_branch => :environment do + src_branch = ENV['SRC_BRANCH'] || 'import_mandriva2011' + dst_branch = ENV['DST_BRANCH'] || 'rosa2012lts' + + say "START add branch #{dst_branch} from #{src_branch}" + Platform.find_by_name(dst_branch).repositories.each do |r| + say "=== Process #{r.name} repo" + r.projects.find_each do |p| + say "===== Process #{p.name} project" + tmp_path = Rails.root.join('tmp', p.name) + system("git clone #{p.path} #{tmp_path}") + system("cd #{tmp_path} && git checkout remotes/origin/#{src_branch}") or system("cd #{tmp_path} && git checkout master") + system("cd #{tmp_path} && git checkout -b #{dst_branch}") + system("cd #{tmp_path} && git push origin HEAD") + FileUtils.rm_rf tmp_path + end + end + say 'DONE' +end From 66fc31e4040bec1099a961d4c6fa98569a1f240c Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 20:32:56 +0200 Subject: [PATCH 26/33] Redo platform build_all with sleep and errors rescue. Refs #207 --- app/controllers/platforms_controller.rb | 6 +----- app/models/platform.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 3b0151bd6..01cbc0eec 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -8,11 +8,7 @@ class PlatformsController < ApplicationController autocomplete :user, :uname def build_all - @platform.repositories.each do |repository| - repository.projects.each do |project| - project.delay.build_for(@platform, current_user) - end - end + @platform.delay.build_all(current_user) redirect_to(platform_path(@platform), :notice => t("flash.platform.build_all_success")) end diff --git a/app/models/platform.rb b/app/models/platform.rb index 713283b5c..76756ee3e 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -158,6 +158,21 @@ class Platform < ActiveRecord::Base end end + def build_all(user) + repositories.each do |r| + r.projects.find_in_batches(:batch_size => 5) do |group| + sleep 1 + group.each do |p| + begin + p.build_for(self, user) + rescue RuntimeError, Exception + p.delay.build_for(self, user) + end + end + end + end + end + def destroy with_skip {super} # avoid cascade XML RPC requests end From 86c717dee515b4b401b4fa26f88e3d594d611742 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 21:06:28 +0200 Subject: [PATCH 27/33] Build only main repo. Refs #207 --- app/models/platform.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index 76756ee3e..6a109fa2d 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -159,15 +159,13 @@ class Platform < ActiveRecord::Base end def build_all(user) - repositories.each do |r| - r.projects.find_in_batches(:batch_size => 5) do |group| - sleep 1 - group.each do |p| - begin - p.build_for(self, user) - rescue RuntimeError, Exception - p.delay.build_for(self, user) - end + repositories.find_by_name('main').projects.find_in_batches(:batch_size => 5) do |group| + sleep 1 + group.each do |p| + begin + p.build_for(self, user) + rescue RuntimeError, Exception + p.delay.build_for(self, user) end end end From dde34cdffb6f9817dcdec5d2fcf72a9097aafe47 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Thu, 23 Feb 2012 22:20:44 +0200 Subject: [PATCH 28/33] Fix build_for settings. Refs #207 --- app/models/project.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index c9804c528..e9a3f487d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -61,14 +61,13 @@ class Project < ActiveRecord::Base end end - def build_for(platform, user) + def build_for(platform, user) build_lists.create do |bl| bl.pl = platform bl.bpl = platform - bl.update_type = 'recommended' + bl.update_type = 'newpackage' bl.arch = Arch.find_by_name('x86_64') # Return i586 after mass rebuild - # FIXME: Need to set "latest_#{platform.name}" - bl.project_version = "latest_import_mandriva2011" + bl.project_version = "latest_#{platform.name}" # "latest_import_mandriva2011" bl.build_requires = false # already set as db default bl.user = user bl.auto_publish = true # already set as db default From bda978a306a96689718544d21fd99643269a11c2 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 24 Feb 2012 17:27:49 +0200 Subject: [PATCH 29/33] Fix bug with group autocomplete. Do not delete during rsync --- app/models/group.rb | 1 - lib/tasks/import.rake | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index a7d96dcc7..14a62b670 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -23,7 +23,6 @@ class Group < ActiveRecord::Base delegate :email, :to => :owner after_create :add_owner_to_members - after_initialize lambda {|r| r.name ||= r.uname } # default include Modules::Models::PersonalRepository # include Modules::Models::Owner diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 13b6a18c8..1649e395a 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -47,7 +47,7 @@ namespace :import do source = "rsync://mirror.yandex.ru/mandriva/#{release}/SRPMS/#{repository}/" destination = ENV['DESTINATION'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository) say "START rsync projects (*.src.rpm) from '#{source}' to '#{destination}'" - if system "rsync -rtv --delete --exclude='backports/*' --exclude='testing/*' #{source} #{destination}" # --include='*.src.rpm' + if system "rsync -rtv --exclude='backports/*' --exclude='testing/*' #{source} #{destination}" # --delete --include='*.src.rpm' say 'Rsync ok!' else say 'Rsync failed!' @@ -61,7 +61,7 @@ namespace :import do platform = Platform.find_by_name(ENV['PLATFORM'] || "mandriva2011") repository = platform.repositories.find_by_name(ENV['REPOSITORY'] || 'main') source = ENV['SOURCE'] || File.join(APP_CONFIG['root_path'], 'mirror.yandex.ru', 'mandriva', release, 'SRPMS', repository.name) - owner = Group.find_or_create_by_uname(ENV['OWNER'] || 'import') {|g| g.owner = User.first} + owner = Group.find_or_create_by_uname(ENV['OWNER'] || 'import') {|g| g.name = g.uname; g.owner = User.first} branch = "import_#{platform.name}" say 'START' From 482874409ddb3b356c5a68bfe3ac2fd0f53025c6 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 24 Feb 2012 17:28:46 +0200 Subject: [PATCH 30/33] Force bluepill restart after deploy. Refs #196 --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 3dc198504..b730c6c76 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -63,7 +63,7 @@ end after "deploy:update_code", "deploy:symlink_all", "deploy:migrate" after "deploy:setup", "deploy:symlink_pids" -after "deploy:restart","bluepill:processes:restart_dj" # "bluepill:restart" +after "deploy:restart", "bluepill:start" # "bluepill:processes:restart_dj" # "bluepill:restart" after "deploy:restart", "deploy:cleanup" require 'cape' From 586d4e0beacaca5fbbe1a1b65f075b90db32ecb4 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Fri, 24 Feb 2012 20:34:41 +0400 Subject: [PATCH 31/33] Fixed bug with Windows line endings in blob editing. --- app/controllers/git/blobs_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 0b93db28f..3300c98e8 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -29,8 +29,8 @@ class Git::BlobsController < Git::BaseController # @git_repository.after_update_file do |repo, sha| # end - res = @git_repository.update_file(params[:path], params[:content], - :message => params[:message], :actor => current_user, :head => @treeish) + res = @git_repository.update_file(params[:path], params[:content].gsub("\r", ''), + :message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish) if res flash[:notice] = t("flash.blob.successfully_updated", :name => params[:path].encode_to_default) else From e1f781762479e5c4ef7e3edca13e7feedbc4c394 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 27 Feb 2012 15:49:24 +0200 Subject: [PATCH 32/33] Add local admin ability to build product. Fix template links. Refactor. Refs #217 --- app/models/ability.rb | 1 + app/views/products/show.html.haml | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 8a6ac63a4..bbbb6fd9d 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -80,6 +80,7 @@ class Ability can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id} can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can(:manage, Product, read_relations_for('products', 'platforms')) {|product| local_admin? product.platform} + can(:create, ProductBuildList) {|pbl| pbl.product.can_build? and can?(:update, pbl.product)} can [:read, :platforms], Category diff --git a/app/views/products/show.html.haml b/app/views/products/show.html.haml index f20fdb222..aaaca6bcb 100644 --- a/app/views/products/show.html.haml +++ b/app/views/products/show.html.haml @@ -26,11 +26,13 @@ = t("layout.#{@product.system_wide?}_") .wat-cf - = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_product_path(@platform, @product), :class => "button" - = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete") + - if can? :update, @product + = link_to image_tag("web-app-theme/icons/application_edit.png", :alt => t("layout.edit")) + " " + t("layout.edit"), edit_platform_product_path(@platform, @product), :class => "button" + - if can? :destroy, @product + = link_to image_tag("web-app-theme/icons/cross.png", :alt => t("layout.delete")) + " " + t("layout.delete"), platform_product_path(@platform, @product), :method => "delete", :class => "button", :confirm => t("layout.products.confirm_delete") - if @product.can_clone? = link_to t("layout.products.clone"), clone_platform_product_path(@platform, @product), :class => "button" - - if @product.can_build? + - if can?(:create, @product => ProductBuildList) = link_to t("layout.products.build"), platform_product_product_build_lists_path(@platform, @product), :class => "button", :method => 'post', :confirm => t("layout.confirm") .block From 1005fbd64f4b4dcea6628cd2263e1a036d7674c1 Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Mon, 27 Feb 2012 18:21:56 +0200 Subject: [PATCH 33/33] Add link to product container. Refs #217 --- app/models/product_build_list.rb | 4 ++++ app/views/product_build_lists/_product_build_list.html.haml | 1 + app/views/products/show.html.haml | 1 + config/locales/en.yml | 1 + config/locales/ru.yml | 1 + 5 files changed, 8 insertions(+) diff --git a/app/models/product_build_list.rb b/app/models/product_build_list.rb index b01ee85e4..f9078f19d 100644 --- a/app/models/product_build_list.rb +++ b/app/models/product_build_list.rb @@ -15,6 +15,10 @@ class ProductBuildList < ActiveRecord::Base after_create :xml_rpc_create + def container_path + "/downloads/#{product.platform.name}/product/#{id}/" + end + def human_status I18n.t("layout.product_build_lists.statuses.#{status}") end diff --git a/app/views/product_build_lists/_product_build_list.html.haml b/app/views/product_build_lists/_product_build_list.html.haml index bf8fe072c..d1464dc3a 100644 --- a/app/views/product_build_lists/_product_build_list.html.haml +++ b/app/views/product_build_lists/_product_build_list.html.haml @@ -1,5 +1,6 @@ %tr{:class => cycle("odd", "even")} %td= product_build_list.id %td= link_to product_build_list.product.name, [product_build_list.product.platform, product_build_list.product] + %td= link_to nil, product_build_list.container_path %td= product_build_list.human_status %td= product_build_list.notified_at \ No newline at end of file diff --git a/app/views/products/show.html.haml b/app/views/products/show.html.haml index aaaca6bcb..3372317e6 100644 --- a/app/views/products/show.html.haml +++ b/app/views/products/show.html.haml @@ -42,6 +42,7 @@ %tr %th.first= t("activerecord.attributes.product_build_list.id") %th= t("activerecord.attributes.product_build_list.product") + %th= t("activerecord.attributes.product_build_list.container_path") %th= t("activerecord.attributes.product_build_list.status") %th.last= t("activerecord.attributes.product_build_list.notified_at") = render @product.product_build_lists.default_order diff --git a/config/locales/en.yml b/config/locales/en.yml index 2e652f118..deb26de54 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -901,6 +901,7 @@ en: product_build_list: id: Id product: Product + container_path: Container status: Status notified_at: Notified at diff --git a/config/locales/ru.yml b/config/locales/ru.yml index b4c81d717..f5eac73ae 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -748,6 +748,7 @@ ru: product_build_list: id: Id product: Продукт + container_path: Контейнер status: Статус notified_at: Информация получена