diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 1cf38308e..6be51da70 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -8,7 +8,7 @@ class QualityAnalysisController < ApplicationController require 'json' require 'open-uri' - def new + def show end @@ -24,9 +24,11 @@ class QualityAnalysisController < ApplicationController language = params[:language] path = params[:path] identifier = params[:identifier] + qa = QualityAnalysis.where(:project_id => @project.id).first + version = qa.sonar_version + 1 properties = "sonar.projectKey=#{user_name}:#{identifier} sonar.projectName=#{user_name}:#{identifier} - sonar.projectVersion=1.0 + sonar.projectVersion=#{version} sonar.sources=#{path} sonar.language=#{language.downcase} sonar.sourceEncoding=utf-8" @@ -43,13 +45,24 @@ class QualityAnalysisController < ApplicationController # relace gitlab hook # genkins address @g.add_project_hook(@project.gpid,"http://123.59.135.93:8890/project/#{user_name}_#{identifier}") - QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier) + if qa.nil? + QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, :version => version) + else + qa.update_attribute(:version, version) + end end def index - data = open('http://123.59.135.93:8891/api/resources/index?resource=my:project985&depth=-1&metrics=complexity,class_complexity,lines,comment_lines,blocker_violations').read - @cc =JSON.parse(data) - + if params[:name].nil? + @name_flag = true + projects_date = open("http://123.59.135.93:8891/api/projects/index").read + @results = JSON.parse(projects_date) + else + @name_flag = false + project_key = params[:name] + data = open("http://123.59.135.93:8891/api/resources/index?resource=#{project_key}&depth=-1&metrics=complexity,class_complexity,lines,comment_lines,blocker_violations").read + @cc =JSON.parse(data) + end end # Find project of id params[:project_id] diff --git a/app/models/quality_analysis.rb b/app/models/quality_analysis.rb index 45778ff3f..09803467e 100644 --- a/app/models/quality_analysis.rb +++ b/app/models/quality_analysis.rb @@ -1,3 +1,3 @@ class QualityAnalysis < ActiveRecord::Base - attr_accessible :author_login, :project_id, :rep_identifier + attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version end diff --git a/app/models/sonar_analysis.rb b/app/models/sonar_analysis.rb new file mode 100644 index 000000000..0bb2089de --- /dev/null +++ b/app/models/sonar_analysis.rb @@ -0,0 +1,3 @@ +class SonarAnalysis < ActiveRecord::Base + attr_accessible :author_login, :project_id, :rep_identifier +end diff --git a/app/views/quality_analysis/index.html.erb b/app/views/quality_analysis/index.html.erb index 1f70644db..627d33d96 100644 --- a/app/views/quality_analysis/index.html.erb +++ b/app/views/quality_analysis/index.html.erb @@ -1,3 +1,10 @@ -<% @cc.each do |c| %> - <%= c %> -<% end %> \ No newline at end of file +<% if @name_flag %> + <%= @results.each do |result| %> +
+ <%=link_to result["k"], project_quality_analysis_path(:name => result["k"]) %> +
+ <% end %> +<% else %> + <%= @cc %> +<% end %> + diff --git a/app/views/quality_analysis/show.html.erb b/app/views/quality_analysis/show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/db/migrate/20160622015019_create_quality_analyses.rb b/db/migrate/20160622033322_create_quality_analyses.rb similarity index 100% rename from db/migrate/20160622015019_create_quality_analyses.rb rename to db/migrate/20160622033322_create_quality_analyses.rb diff --git a/db/migrate/20160622074138_add_jk_version_to_quality_analysis.rb b/db/migrate/20160622074138_add_jk_version_to_quality_analysis.rb new file mode 100644 index 000000000..838d6d896 --- /dev/null +++ b/db/migrate/20160622074138_add_jk_version_to_quality_analysis.rb @@ -0,0 +1,5 @@ +class AddJkVersionToQualityAnalysis < ActiveRecord::Migration + def change + add_column :quality_analyses, :sonar_version, :integer, :default => false + end +end diff --git a/db/schema.rb b/db/schema.rb index 51e0682d0..01a001769 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 => 20160622015019) do +ActiveRecord::Schema.define(:version => 20160622074138) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1837,8 +1837,10 @@ ActiveRecord::Schema.define(:version => 20160622015019) do t.integer "project_id" t.string "author_login" t.string "rep_identifier" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.float "version", :default => 0.0 + t.integer "sonar_version", :default => 1 end create_table "queries", :force => true do |t|