Commit 3bfcb8268bcee7603da07c7c38bea1a195eb1977
Committed by
João M. M. da Silva
1 parent
5c48092d
Exists in
master
and in
29 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 | class MezuroPlugin::ProjectContent < Article | 1 | class MezuroPlugin::ProjectContent < Article |
2 | include ActionView::Helpers::TagHelper | 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 | validate_on_create :validate_kalibro_project_name | 6 | validate_on_create :validate_kalibro_project_name |
7 | validate_on_create :validate_repository_url | 7 | validate_on_create :validate_repository_url |
@@ -22,71 +22,84 @@ class MezuroPlugin::ProjectContent < Article | @@ -22,71 +22,84 @@ class MezuroPlugin::ProjectContent < Article | ||
22 | 22 | ||
23 | def project | 23 | def project |
24 | begin | 24 | begin |
25 | - @project ||= Kalibro::Project.find_by_name(name) | 25 | + @project ||= Kalibro::Project.find(project_id) |
26 | rescue Exception => error | 26 | rescue Exception => error |
27 | errors.add_to_base(error.message) | 27 | errors.add_to_base(error.message) |
28 | end | 28 | end |
29 | @project | 29 | @project |
30 | end | 30 | end |
31 | 31 | ||
32 | - def project_result | 32 | + def repositories |
33 | begin | 33 | begin |
34 | - @project_result ||= Kalibro::ProjectResult.last_result(name) | 34 | + @repositories ||= Kalibro::Repository.repositories_of(project_id) |
35 | rescue Exception => error | 35 | rescue Exception => error |
36 | errors.add_to_base(error.message) | 36 | errors.add_to_base(error.message) |
37 | end | 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 | end | 50 | end |
40 | 51 | ||
41 | - def project_result_with_date(date) | 52 | + def processing_with_date(repository_id, date) |
42 | begin | 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 | rescue Exception => error | 59 | rescue Exception => error |
46 | errors.add_to_base(error.message) | 60 | errors.add_to_base(error.message) |
47 | end | 61 | end |
48 | - @project_result | 62 | + @processing |
49 | end | 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 | begin | 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 | rescue Exception => error | 69 | rescue Exception => error |
57 | errors.add_to_base(error.message) | 70 | errors.add_to_base(error.message) |
58 | end | 71 | end |
59 | @module_result | 72 | @module_result |
60 | end | 73 | end |
61 | 74 | ||
62 | - def result_history(module_name) | 75 | + def result_history(module_id) |
63 | begin | 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 | rescue Exception => error | 78 | rescue Exception => error |
66 | errors.add_to_base(error.message) | 79 | errors.add_to_base(error.message) |
67 | end | 80 | end |
68 | end | 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 | after_save :send_project_to_service | 96 | after_save :send_project_to_service |
71 | after_destroy :destroy_project_from_service | 97 | after_destroy :destroy_project_from_service |
72 | 98 | ||
73 | private | 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 | def validate_repository_url | 101 | def validate_repository_url |
89 | - if(repository_url.nil? || repository_url == "") | 102 | + if(@repositories.nil? || repository_url == "") |
90 | errors.add_to_base("Repository URL is mandatory") | 103 | errors.add_to_base("Repository URL is mandatory") |
91 | end | 104 | end |
92 | end | 105 | end |
plugins/mezuro/test/fixtures/project_fixtures.rb
@@ -23,8 +23,8 @@ class ProjectFixtures | @@ -23,8 +23,8 @@ class ProjectFixtures | ||
23 | content.name = 'Qt-Calculator' | 23 | content.name = 'Qt-Calculator' |
24 | content.project_license = 'GPL' | 24 | content.project_license = 'GPL' |
25 | content.description = 'Calculator for Qt' | 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 | content.configuration_name = 'Kalibro for Java' | 28 | content.configuration_name = 'Kalibro for Java' |
29 | content.periodicity_in_days = 1 | 29 | content.periodicity_in_days = 1 |
30 | content | 30 | content |