diff --git a/plugins/mezuro/lib/mezuro_plugin/project_content.rb b/plugins/mezuro/lib/mezuro_plugin/project_content.rb index f184624..6e7428e 100644 --- a/plugins/mezuro/lib/mezuro_plugin/project_content.rb +++ b/plugins/mezuro/lib/mezuro_plugin/project_content.rb @@ -1,7 +1,7 @@ class MezuroPlugin::ProjectContent < Article include ActionView::Helpers::TagHelper - settings_items :project_license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days + settings_items :project_id validate_on_create :validate_kalibro_project_name validate_on_create :validate_repository_url @@ -22,71 +22,84 @@ class MezuroPlugin::ProjectContent < Article def project begin - @project ||= Kalibro::Project.find_by_name(name) + @project ||= Kalibro::Project.find(project_id) rescue Exception => error errors.add_to_base(error.message) end @project end - def project_result + def repositories begin - @project_result ||= Kalibro::ProjectResult.last_result(name) + @repositories ||= Kalibro::Repository.repositories_of(project_id) rescue Exception => error errors.add_to_base(error.message) end - @project_result + @repositories + end + + def processing(repository_id) + begin + if Kalibro::Processing.has_ready_processing(repository_id) + @processing ||= Kalibro::Processing.last_ready_processing_of(repository_id) + end + rescue Exception => error + errors.add_to_base(error.message) + end + @processing end - def project_result_with_date(date) + def processing_with_date(repository_id, date) begin - @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before(name, date) : -Kalibro::ProjectResult.first_result_after(name, date) + if Kalibro::Processing.has_processing_before(repository_id, date) + @processing ||= Kalibro::Processing.last_processing_before(repository_id, date) + else if Kalibro::Processing.has_processing_after(repository_id, date) + @processing ||= Kalibro::Processing.last_processing_after(repository_id, date) + end rescue Exception => error errors.add_to_base(error.message) end - @project_result + @processing end - def module_result(attributes) - module_name = attributes[:module_name].nil? ? project.name : attributes[:module_name] - date = attributes[:date].nil? ? project_result.date : project_result_with_date(attributes[:date]).date + def module_result(repository_id, date = nil) + @processing ||= date.nil? ? processing(repository_id) : processing_with_date(repository_id, date) begin - @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date) + @module_result ||= Kalibro::ModuleResult.find(@procesing.results_root_id) rescue Exception => error errors.add_to_base(error.message) end @module_result end - def result_history(module_name) + def result_history(module_id) begin - @result_history ||= Kalibro::ModuleResult.all_by_project_name_and_module_name(name, module_name) + @result_history ||= Kalibro::MetricResult.history_of(module_id) rescue Exception => error errors.add_to_base(error.message) end end + def description=(value) + @description=value + end + + def repositories=(value) + @repositories = value.kind_of?(Array) ? value : [value] + @repositories = @repositories.map { |element| to_object(element) } + end + + def self.to_object value + value.kind_of?(Hash) ? Kalibro::Repository.new(value) : value + end + after_save :send_project_to_service after_destroy :destroy_project_from_service private - def validate_kalibro_project_name - begin - existing = Kalibro::Project.all_names - rescue Exception => error - errors.add_to_base(error.message) - existing = [] - end - - if existing.any?{|existing_name| existing_name.casecmp(name)==0} # existing.include?(name) + case insensitive - errors.add_to_base("Project name already exists in Kalibro") - end - end - def validate_repository_url - if(repository_url.nil? || repository_url == "") + if(@repositories.nil? || repository_url == "") errors.add_to_base("Repository URL is mandatory") end end diff --git a/plugins/mezuro/test/fixtures/project_fixtures.rb b/plugins/mezuro/test/fixtures/project_fixtures.rb index 39c9880..6de99b0 100644 --- a/plugins/mezuro/test/fixtures/project_fixtures.rb +++ b/plugins/mezuro/test/fixtures/project_fixtures.rb @@ -23,8 +23,8 @@ class ProjectFixtures content.name = 'Qt-Calculator' content.project_license = 'GPL' content.description = 'Calculator for Qt' - content.repository_type = RepositoryFixtures.repository_hash[:type] - content.repository_url = RepositoryFixtures.repository_hash[:address] + content.repository_type = [RepositoryFixtures.repository_hash[:type]] + content.repository_url = [RepositoryFixtures.repository_hash[:address]] content.configuration_name = 'Kalibro for Java' content.periodicity_in_days = 1 content -- libgit2 0.21.2