From f30feb11530c22cfba3278b370db91d019debaf9 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 2 Jun 2014 18:09:35 +0400 Subject: [PATCH 1/9] Added ability for system user for add_repo_lock_file/remove_repo_lock_file --- app/models/ability.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ability.rb b/app/models/ability.rb index 38eadba95..4c33f0534 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -187,7 +187,7 @@ class Ability cannot(:cancel, MassBuild) {|mass_build| mass_build.stop_build} if @user.system? - can :key_pair, Repository + can %i(key_pair add_repo_lock_file remove_repo_lock_file), Repository else cannot :key_pair, Repository end From d91ceab0a9ddd66558300b6ca527a206c2dd552d Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 2 Jun 2014 20:49:50 +0400 Subject: [PATCH 2/9] rename forbid_to_publish_builds_not_from field to publish_builds_only_from_branch --- .../platforms/repositories_controller.rb | 2 +- app/models/build_list.rb | 6 +++--- app/models/repository.rb | 4 ++-- app/views/platforms/repositories/_form.html.haml | 4 ++-- config/locales/models/repository.en.yml | 2 +- config/locales/models/repository.ru.yml | 2 +- ..._not_from_to_publish_builds_only_from_branch.rb | 7 +++++++ db/schema.rb | 14 +++++++------- 8 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20140602164337_rename_repositories_forbid_to_publish_builds_not_from_to_publish_builds_only_from_branch.rb diff --git a/app/controllers/platforms/repositories_controller.rb b/app/controllers/platforms/repositories_controller.rb index 305019909..27734252f 100644 --- a/app/controllers/platforms/repositories_controller.rb +++ b/app/controllers/platforms/repositories_controller.rb @@ -22,7 +22,7 @@ class Platforms::RepositoriesController < Platforms::BaseController end def update - if @repository.update_attributes params[:repository].slice(:description, :synchronizing_publications, :forbid_to_publish_builds_not_from).merge(publish_without_qa: (params[:repository][:publish_without_qa] || @repository.publish_without_qa)) + if @repository.update_attributes params[:repository].slice(:description, :synchronizing_publications, :publish_builds_only_from_branch).merge(publish_without_qa: (params[:repository][:publish_without_qa] || @repository.publish_without_qa)) flash[:notice] = I18n.t("flash.repository.updated") redirect_to platform_repository_path(@platform, @repository) else diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 8a5d8be3f..d364c574f 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -606,12 +606,12 @@ class BuildList < ActiveRecord::Base def valid_branch_for_publish? return true if save_to_platform.personal? || - save_to_repository.forbid_to_publish_builds_not_from.blank? || - ( project_version == save_to_repository.forbid_to_publish_builds_not_from ) + save_to_repository.publish_builds_only_from_branch.blank? || + ( project_version == save_to_repository.publish_builds_only_from_branch ) project.repo.git.native(:branch, {}, '--contains', commit_hash). gsub(/\*/, '').split(/\n/).map(&:strip). - include?(save_to_repository.forbid_to_publish_builds_not_from) + include?(save_to_repository.publish_builds_only_from_branch) end diff --git a/app/models/repository.rb b/app/models/repository.rb index f02cc7551..cb9fc2b36 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -23,7 +23,7 @@ class Repository < ActiveRecord::Base validates :description, presence: true validates :name, uniqueness: { scope: :platform_id, case_sensitive: false }, presence: true, format: { with: /\A[a-z0-9_\-]+\z/ } - validates :forbid_to_publish_builds_not_from, length: { maximum: 255 } + validates :publish_builds_only_from_branch, length: { maximum: 255 } scope :recent, -> { order(:name) } scope :main, -> { where(name: %w(main base)) } @@ -34,7 +34,7 @@ class Repository < ActiveRecord::Base :description, :publish_without_qa, :synchronizing_publications, - :forbid_to_publish_builds_not_from + :publish_builds_only_from_branch attr_readonly :name, :platform_id attr_accessor :projects_list diff --git a/app/views/platforms/repositories/_form.html.haml b/app/views/platforms/repositories/_form.html.haml index e44b03b5a..2343c718e 100644 --- a/app/views/platforms/repositories/_form.html.haml +++ b/app/views/platforms/repositories/_form.html.haml @@ -13,8 +13,8 @@ - if @platform.main? .both - .leftlist= f.label :forbid_to_publish_builds_not_from - .rightlist= f.text_field :forbid_to_publish_builds_not_from + .leftlist= f.label :publish_builds_only_from_branch + .rightlist= f.text_field :publish_builds_only_from_branch .both diff --git a/config/locales/models/repository.en.yml b/config/locales/models/repository.en.yml index 90b9b5767..83660c017 100644 --- a/config/locales/models/repository.en.yml +++ b/config/locales/models/repository.en.yml @@ -71,4 +71,4 @@ en: updated_at: Updated owner: Owner synchronizing_publications: Publish only on success all build_lists for each arch (checking by commit hash) - forbid_to_publish_builds_not_from: "Publish builds only from branch" + publish_builds_only_from_branch: "Publish builds only from branch" diff --git a/config/locales/models/repository.ru.yml b/config/locales/models/repository.ru.yml index 287361713..a2decc530 100644 --- a/config/locales/models/repository.ru.yml +++ b/config/locales/models/repository.ru.yml @@ -71,5 +71,5 @@ ru: updated_at: Обновлен owner: Владелец synchronizing_publications: Публиковать сборочные листы только при успешной сборке под каждую архитектуру (проверка по хэшу коммита) - forbid_to_publish_builds_not_from: "Публикация сборок только из ветки" + publish_builds_only_from_branch: "Публикация сборок только из ветки" diff --git a/db/migrate/20140602164337_rename_repositories_forbid_to_publish_builds_not_from_to_publish_builds_only_from_branch.rb b/db/migrate/20140602164337_rename_repositories_forbid_to_publish_builds_not_from_to_publish_builds_only_from_branch.rb new file mode 100644 index 000000000..32425dbf9 --- /dev/null +++ b/db/migrate/20140602164337_rename_repositories_forbid_to_publish_builds_not_from_to_publish_builds_only_from_branch.rb @@ -0,0 +1,7 @@ +class RenameRepositoriesForbidToPublishBuildsNotFromToPublishBuildsOnlyFromBranch < ActiveRecord::Migration + def change + change_table :repositories do |t| + t.rename :forbid_to_publish_builds_not_from, :publish_builds_only_from_branch + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a0d15fbad..82c9152ac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140530193652) do +ActiveRecord::Schema.define(version: 20140602164337) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -522,14 +522,14 @@ ActiveRecord::Schema.define(version: 20140530193652) do end create_table "repositories", force: true do |t| - t.string "description", null: false - t.integer "platform_id", null: false + t.string "description", null: false + t.integer "platform_id", null: false t.datetime "created_at" t.datetime "updated_at" - t.string "name", null: false - t.boolean "publish_without_qa", default: true - t.boolean "synchronizing_publications", default: false, null: false - t.string "forbid_to_publish_builds_not_from" + t.string "name", null: false + t.boolean "publish_without_qa", default: true + t.boolean "synchronizing_publications", default: false, null: false + t.string "publish_builds_only_from_branch" t.index ["platform_id"], :name => "index_repositories_on_platform_id" end From 6650462c2e86945c28b49bb0d8d3e2fcccde741a Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Wed, 4 Jun 2014 17:47:08 +0400 Subject: [PATCH 3/9] remove tmp hook --- app/views/projects/build_lists/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/build_lists/show.html.haml b/app/views/projects/build_lists/show.html.haml index e55051a3a..22d79b83e 100644 --- a/app/views/projects/build_lists/show.html.haml +++ b/app/views/projects/build_lists/show.html.haml @@ -199,7 +199,7 @@ method: :put, data: { confirm: t("layout.confirm") }, class: 'button', 'ng-show' => 'build_list.can_reject_publish' - - if can?(:rerun_tests, @build_list) && (current_user.tester? || current_user.admin?) + - if can?(:rerun_tests, @build_list) = link_to t('layout.build_lists.rerun_tests'), rerun_tests_build_list_path(@build_list), method: :put, From d9dc1af6ccab6bfdd3f8565ed7d2e01578593a21 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 5 Jun 2014 21:35:20 +0400 Subject: [PATCH 4/9] Fixed: links to forked projects --- app/views/projects/git/base/_choose_fork.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/git/base/_choose_fork.html.haml b/app/views/projects/git/base/_choose_fork.html.haml index 6f36e07de..0d8ec5b4e 100644 --- a/app/views/projects/git/base/_choose_fork.html.haml +++ b/app/views/projects/git/base/_choose_fork.html.haml @@ -4,7 +4,7 @@ - if owner.own_projects.exists? name: name %p.center =t 'layout.projects.already_exists' - =link_to full_name, project_path(@project) + =link_to full_name, project_path("#{owner.uname}/#{name}") - else = form_for @project, url: fork_project_path(@project), html: { class: :form, multipart: true, method: :post } do |f| = hidden_field_tag :group, owner.id if owner.class == Group From 3a1b505cf5779f37db98fe7657486a2b10f1cff4 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 5 Jun 2014 22:22:39 +0400 Subject: [PATCH 5/9] Fixed: overflow of queue when build list is not valid --- app/models/build_list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/build_list.rb b/app/models/build_list.rb index d364c574f..6f6b4439b 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -598,7 +598,7 @@ class BuildList < ActiveRecord::Base end def delayed_add_job_to_abf_worker_queue(*args) - restart_job if status == BUILD_PENDING + restart_job if valid? && status == BUILD_PENDING end later :delayed_add_job_to_abf_worker_queue, delay: 60, queue: :middle From b06ff1f216be0a353fdb6f75e89eebb8fd37b285 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Fri, 6 Jun 2014 16:53:06 +0400 Subject: [PATCH 6/9] Add references into attr_accessible --- app/models/advisory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/advisory.rb b/app/models/advisory.rb index c53a4bdcd..07528e880 100644 --- a/app/models/advisory.rb +++ b/app/models/advisory.rb @@ -11,7 +11,7 @@ class Advisory < ActiveRecord::Base after_create :generate_advisory_id before_save :normalize_references, if: :references_changed? - attr_accessible :description + attr_accessible :description, :references ID_TEMPLATE = 'ROSA-%s-%d:%04d' ID_STRING_TEMPLATE = 'ROSA-%s-%04s:%04s' From 23d3f8a0bc683798556f53b2da6017d81aabccde Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Sat, 7 Jun 2014 02:07:54 +0400 Subject: [PATCH 7/9] #397: added dependent_packages && dependent_projects to BuildList::Package --- app/models/build_list/package.rb | 18 ++- .../projects/build_lists/show.json.jbuilder | 104 ++++++++++-------- ...pendent_projects_to_build_list_packages.rb | 6 + db/schema.rb | 10 +- 4 files changed, 84 insertions(+), 54 deletions(-) create mode 100644 db/migrate/20140606193047_add_dependent_packages_and_dependent_projects_to_build_list_packages.rb diff --git a/app/models/build_list/package.rb b/app/models/build_list/package.rb index 026dad4a1..5428b48e5 100644 --- a/app/models/build_list/package.rb +++ b/app/models/build_list/package.rb @@ -1,11 +1,14 @@ class BuildList::Package < ActiveRecord::Base PACKAGE_TYPES = %w(source binary) - belongs_to :build_list + belongs_to :build_list, touch: true belongs_to :project belongs_to :platform - attr_accessible :fullname, :name, :release, :version, :sha1, :epoch + serialize :dependent_packages, Array + serialize :dependent_projects, Array + + attr_accessible :fullname, :name, :release, :version, :sha1, :epoch, :dependent_packages validates :build_list_id, :project_id, :platform_id, :fullname, :package_type, :name, :release, :version, @@ -23,6 +26,8 @@ class BuildList::Package < ActiveRecord::Base scope :like_name, ->(name) { where("#{table_name}.name ILIKE ?", "%#{name}%") if name.present? } before_create :set_epoch + before_create :normalize_dependent_packages + after_commit(on: :create) { |p| p.find_dependent_projects if p.dependent_packages.present? } # later with resque def assignee project.maintainer @@ -45,8 +50,17 @@ class BuildList::Package < ActiveRecord::Base end end + def find_dependent_projects + # TODO + end + later :find_dependent_projects, queue: :middle + protected + def normalize_dependent_packages + self.dependent_packages = dependent_packages.split(/\s/).select(&:present?) if dependent_packages.present? + end + def set_epoch self.epoch = nil if epoch.blank? || epoch == 0 end diff --git a/app/views/projects/build_lists/show.json.jbuilder b/app/views/projects/build_lists/show.json.jbuilder index c502fc670..f462f329d 100644 --- a/app/views/projects/build_lists/show.json.jbuilder +++ b/app/views/projects/build_lists/show.json.jbuilder @@ -1,67 +1,75 @@ json.build_list do - json.(@build_list, :id, :container_status, :status) - json.(@build_list, :update_type) - json.updated_at @build_list.updated_at - json.updated_at_utc @build_list.updated_at.strftime('%Y-%m-%d %H:%M:%S UTC') - if !@build_list.in_work? && @build_list.started_at json.human_duration @build_list.human_duration elsif @build_list.in_work? json.human_duration "#{@build_list.human_current_duration} / #{@build_list.human_average_build_time}" end - - json.can_publish can?(:publish, @build_list) - json.can_publish_into_testing can?(:publish_into_testing, @build_list) && @build_list.can_publish_into_testing? - json.can_cancel @build_list.can_cancel? - json.can_create_container @build_list.can_create_container? - json.can_reject_publish @build_list.can_reject_publish? - - json.extra_build_lists_published @build_list.extra_build_lists_published? - json.can_publish_in_future can_publish_in_future?(@build_list) - json.can_publish_into_repository @build_list.can_publish_into_repository? + + json.cache! @build_list, expires_in: 1.minute do + json.(@build_list, :id, :container_status, :status) + json.(@build_list, :update_type) + json.updated_at @build_list.updated_at + json.updated_at_utc @build_list.updated_at.strftime('%Y-%m-%d %H:%M:%S UTC') - json.container_path container_url if @build_list.container_published? + json.can_publish can?(:publish, @build_list) + json.can_publish_into_testing can?(:publish_into_testing, @build_list) && @build_list.can_publish_into_testing? + json.can_cancel @build_list.can_cancel? + json.can_create_container @build_list.can_create_container? + json.can_reject_publish @build_list.can_reject_publish? - json.publisher do - json.fullname @build_list.publisher.try(:fullname) - json.path user_path(@build_list.publisher) - end if @build_list.publisher + json.extra_build_lists_published @build_list.extra_build_lists_published? + json.can_publish_in_future can_publish_in_future?(@build_list) + json.can_publish_into_repository @build_list.can_publish_into_repository? - json.builder do - json.fullname @build_list.builder.try(:fullname) - json.path user_path(@build_list.builder) - end if @build_list.builder && (!@build_list.builder.system? || current_user.try(:admin?)) - json.advisory do - json.(@build_list.advisory, :description, :advisory_id) - json.path advisory_path(@build_list.advisory) - end if @build_list.advisory + json.container_path container_url if @build_list.container_published? - json.results @build_list.results do |result| - json.file_name result['file_name'] - json.sha1 result['sha1'] - json.size result['size'] + json.publisher do + json.fullname @build_list.publisher.try(:fullname) + json.path user_path(@build_list.publisher) + end if @build_list.publisher - timestamp = result['timestamp'] - json.created_at Time.zone.at(result['timestamp']).to_s if timestamp + json.builder do + json.fullname @build_list.builder.try(:fullname) + json.path user_path(@build_list.builder) + end if @build_list.builder && (!@build_list.builder.system? || current_user.try(:admin?)) - json.url file_store_results_url(result['sha1'], result['file_name']) - end if @build_list.new_core? && @build_list.results.present? + json.advisory do + json.(@build_list.advisory, :description, :advisory_id) + json.path advisory_path(@build_list.advisory) + end if @build_list.advisory - json.packages @build_list.packages do |package| - json.(package, :id, :name, :fullname, :release, :version, :sha1, :epoch) - json.url "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{package.sha1}" if package.sha1 - end if @build_list.packages.present? + json.results @build_list.results do |result| + json.file_name result['file_name'] + json.sha1 result['sha1'] + json.size result['size'] - json.item_groups do |group| - @item_groups.each_with_index do |group, level| - json.group group do |item| - json.(item, :name, :status) - json.path build_list_item_version_link item - json.level level + timestamp = result['timestamp'] + json.created_at Time.zone.at(result['timestamp']).to_s if timestamp + + json.url file_store_results_url(result['sha1'], result['file_name']) + end if @build_list.new_core? && @build_list.results.present? + + json.packages @build_list.packages do |package| + json.(package, :id, :name, :fullname, :release, :version, :sha1, :epoch) + json.url "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{package.sha1}" if package.sha1 + + json.dependent_projects Project.where(id: package.dependent_projects).to_a do |project| + json.project_path project_path(project) + json.new_project_build_list_path new_project_build_list_path(@project) end - end - end if @item_groups.present? + end if @build_list.packages.present? + + json.item_groups do |group| + @item_groups.each_with_index do |group, level| + json.group group do |item| + json.(item, :name, :status) + json.path build_list_item_version_link item + json.level level + end + end + end if @item_groups.present? + end end diff --git a/db/migrate/20140606193047_add_dependent_packages_and_dependent_projects_to_build_list_packages.rb b/db/migrate/20140606193047_add_dependent_packages_and_dependent_projects_to_build_list_packages.rb new file mode 100644 index 000000000..c2d1db1db --- /dev/null +++ b/db/migrate/20140606193047_add_dependent_packages_and_dependent_projects_to_build_list_packages.rb @@ -0,0 +1,6 @@ +class AddDependentPackagesAndDependentProjectsToBuildListPackages < ActiveRecord::Migration + def change + add_column :build_list_packages, :dependent_packages, :text + add_column :build_list_packages, :dependent_projects, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 82c9152ac..3bc0ac99d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140602164337) do +ActiveRecord::Schema.define(version: 20140606193047) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -90,11 +90,13 @@ ActiveRecord::Schema.define(version: 20140602164337) do t.string "version" t.string "release" t.string "package_type" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "actual", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "actual", default: false t.string "sha1" t.integer "epoch" + t.text "dependent_packages" + t.text "dependent_projects" t.index ["actual", "platform_id"], :name => "index_build_list_packages_on_actual_and_platform_id" t.index ["build_list_id"], :name => "index_build_list_packages_on_build_list_id" t.index ["name", "project_id"], :name => "index_build_list_packages_on_name_and_project_id" From 790cd05cae29d0caffa20b33376c0b1bea79abf8 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 10 Jun 2014 00:06:21 +0400 Subject: [PATCH 8/9] #397: Fixed: error at saving dependent_packages --- app/models/build_list/package.rb | 2 +- lib/abf_worker/rpm_worker_observer.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/build_list/package.rb b/app/models/build_list/package.rb index 5428b48e5..82e111ad2 100644 --- a/app/models/build_list/package.rb +++ b/app/models/build_list/package.rb @@ -58,7 +58,7 @@ class BuildList::Package < ActiveRecord::Base protected def normalize_dependent_packages - self.dependent_packages = dependent_packages.split(/\s/).select(&:present?) if dependent_packages.present? + self.dependent_packages = dependent_packages.to_s.split(/\s/).select(&:present?) end def set_epoch diff --git a/lib/abf_worker/rpm_worker_observer.rb b/lib/abf_worker/rpm_worker_observer.rb index 747169af9..85f568719 100644 --- a/lib/abf_worker/rpm_worker_observer.rb +++ b/lib/abf_worker/rpm_worker_observer.rb @@ -72,9 +72,9 @@ module AbfWorker def fill_container_data (options['packages'] || []).each do |package| package = subject.packages.build(package) - package.package_type = package['fullname'] =~ /.*\.src\.rpm$/ ? 'source' : 'binary' - package.project_id = subject.project_id - package.platform_id = subject.save_to_platform_id + package.package_type = package['fullname'] =~ /.*\.src\.rpm$/ ? 'source' : 'binary' + package.project_id = subject.project_id + package.platform_id = subject.save_to_platform_id package.save! end update_results From 16fa4466986d9dc3ffabb5efc0b5f06d12e9e304 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 10 Jun 2014 00:56:32 +0400 Subject: [PATCH 9/9] Fixed: json.cache --- app/views/projects/build_lists/show.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/build_lists/show.json.jbuilder b/app/views/projects/build_lists/show.json.jbuilder index f462f329d..2282940e8 100644 --- a/app/views/projects/build_lists/show.json.jbuilder +++ b/app/views/projects/build_lists/show.json.jbuilder @@ -5,7 +5,7 @@ json.build_list do json.human_duration "#{@build_list.human_current_duration} / #{@build_list.human_average_build_time}" end - json.cache! @build_list, expires_in: 1.minute do + json.cache! [@build_list, current_user], expires_in: 1.minute do json.(@build_list, :id, :container_status, :status) json.(@build_list, :update_type) json.updated_at @build_list.updated_at