Commit 3bfcb8268bcee7603da07c7c38bea1a195eb1977
Committed by
João M. M. da Silva
1 parent
5c48092d
Exists in
master
and in
28 other branches
[Mezuro] draft to new project content.
Showing
2 changed files
with
44 additions
and
31 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin/project_content.rb
| 1 | 1 | class MezuroPlugin::ProjectContent < Article |
| 2 | 2 | include ActionView::Helpers::TagHelper |
| 3 | 3 | |
| 4 | - settings_items :project_license, :description, :repository_type, :repository_url, :configuration_name, :periodicity_in_days | |
| 4 | + settings_items :project_id | |
| 5 | 5 | |
| 6 | 6 | validate_on_create :validate_kalibro_project_name |
| 7 | 7 | validate_on_create :validate_repository_url |
| ... | ... | @@ -22,71 +22,84 @@ class MezuroPlugin::ProjectContent < Article |
| 22 | 22 | |
| 23 | 23 | def project |
| 24 | 24 | begin |
| 25 | - @project ||= Kalibro::Project.find_by_name(name) | |
| 25 | + @project ||= Kalibro::Project.find(project_id) | |
| 26 | 26 | rescue Exception => error |
| 27 | 27 | errors.add_to_base(error.message) |
| 28 | 28 | end |
| 29 | 29 | @project |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | - def project_result | |
| 32 | + def repositories | |
| 33 | 33 | begin |
| 34 | - @project_result ||= Kalibro::ProjectResult.last_result(name) | |
| 34 | + @repositories ||= Kalibro::Repository.repositories_of(project_id) | |
| 35 | 35 | rescue Exception => error |
| 36 | 36 | errors.add_to_base(error.message) |
| 37 | 37 | end |
| 38 | - @project_result | |
| 38 | + @repositories | |
| 39 | + end | |
| 40 | + | |
| 41 | + def processing(repository_id) | |
| 42 | + begin | |
| 43 | + if Kalibro::Processing.has_ready_processing(repository_id) | |
| 44 | + @processing ||= Kalibro::Processing.last_ready_processing_of(repository_id) | |
| 45 | + end | |
| 46 | + rescue Exception => error | |
| 47 | + errors.add_to_base(error.message) | |
| 48 | + end | |
| 49 | + @processing | |
| 39 | 50 | end |
| 40 | 51 | |
| 41 | - def project_result_with_date(date) | |
| 52 | + def processing_with_date(repository_id, date) | |
| 42 | 53 | begin |
| 43 | - @project_result ||= Kalibro::ProjectResult.has_results_before?(name, date) ? Kalibro::ProjectResult.last_result_before(name, date) : | |
| 44 | -Kalibro::ProjectResult.first_result_after(name, date) | |
| 54 | + if Kalibro::Processing.has_processing_before(repository_id, date) | |
| 55 | + @processing ||= Kalibro::Processing.last_processing_before(repository_id, date) | |
| 56 | + else if Kalibro::Processing.has_processing_after(repository_id, date) | |
| 57 | + @processing ||= Kalibro::Processing.last_processing_after(repository_id, date) | |
| 58 | + end | |
| 45 | 59 | rescue Exception => error |
| 46 | 60 | errors.add_to_base(error.message) |
| 47 | 61 | end |
| 48 | - @project_result | |
| 62 | + @processing | |
| 49 | 63 | end |
| 50 | 64 | |
| 51 | - def module_result(attributes) | |
| 52 | - module_name = attributes[:module_name].nil? ? project.name : attributes[:module_name] | |
| 53 | - date = attributes[:date].nil? ? project_result.date : project_result_with_date(attributes[:date]).date | |
| 65 | + def module_result(repository_id, date = nil) | |
| 66 | + @processing ||= date.nil? ? processing(repository_id) : processing_with_date(repository_id, date) | |
| 54 | 67 | begin |
| 55 | - @module_result ||= Kalibro::ModuleResult.find_by_project_name_and_module_name_and_date(name, module_name, date) | |
| 68 | + @module_result ||= Kalibro::ModuleResult.find(@procesing.results_root_id) | |
| 56 | 69 | rescue Exception => error |
| 57 | 70 | errors.add_to_base(error.message) |
| 58 | 71 | end |
| 59 | 72 | @module_result |
| 60 | 73 | end |
| 61 | 74 | |
| 62 | - def result_history(module_name) | |
| 75 | + def result_history(module_id) | |
| 63 | 76 | begin |
| 64 | - @result_history ||= Kalibro::ModuleResult.all_by_project_name_and_module_name(name, module_name) | |
| 77 | + @result_history ||= Kalibro::MetricResult.history_of(module_id) | |
| 65 | 78 | rescue Exception => error |
| 66 | 79 | errors.add_to_base(error.message) |
| 67 | 80 | end |
| 68 | 81 | end |
| 69 | 82 | |
| 83 | + def description=(value) | |
| 84 | + @description=value | |
| 85 | + end | |
| 86 | + | |
| 87 | + def repositories=(value) | |
| 88 | + @repositories = value.kind_of?(Array) ? value : [value] | |
| 89 | + @repositories = @repositories.map { |element| to_object(element) } | |
| 90 | + end | |
| 91 | + | |
| 92 | + def self.to_object value | |
| 93 | + value.kind_of?(Hash) ? Kalibro::Repository.new(value) : value | |
| 94 | + end | |
| 95 | + | |
| 70 | 96 | after_save :send_project_to_service |
| 71 | 97 | after_destroy :destroy_project_from_service |
| 72 | 98 | |
| 73 | 99 | private |
| 74 | 100 | |
| 75 | - def validate_kalibro_project_name | |
| 76 | - begin | |
| 77 | - existing = Kalibro::Project.all_names | |
| 78 | - rescue Exception => error | |
| 79 | - errors.add_to_base(error.message) | |
| 80 | - existing = [] | |
| 81 | - end | |
| 82 | - | |
| 83 | - if existing.any?{|existing_name| existing_name.casecmp(name)==0} # existing.include?(name) + case insensitive | |
| 84 | - errors.add_to_base("Project name already exists in Kalibro") | |
| 85 | - end | |
| 86 | - end | |
| 87 | - | |
| 88 | 101 | def validate_repository_url |
| 89 | - if(repository_url.nil? || repository_url == "") | |
| 102 | + if(@repositories.nil? || repository_url == "") | |
| 90 | 103 | errors.add_to_base("Repository URL is mandatory") |
| 91 | 104 | end |
| 92 | 105 | end | ... | ... |
plugins/mezuro/test/fixtures/project_fixtures.rb
| ... | ... | @@ -23,8 +23,8 @@ class ProjectFixtures |
| 23 | 23 | content.name = 'Qt-Calculator' |
| 24 | 24 | content.project_license = 'GPL' |
| 25 | 25 | content.description = 'Calculator for Qt' |
| 26 | - content.repository_type = RepositoryFixtures.repository_hash[:type] | |
| 27 | - content.repository_url = RepositoryFixtures.repository_hash[:address] | |
| 26 | + content.repository_type = [RepositoryFixtures.repository_hash[:type]] | |
| 27 | + content.repository_url = [RepositoryFixtures.repository_hash[:address]] | |
| 28 | 28 | content.configuration_name = 'Kalibro for Java' |
| 29 | 29 | content.periodicity_in_days = 1 |
| 30 | 30 | content | ... | ... |