From 4a4c613c55c626c8a1cd4d3312674563f44a48af Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 24 Jun 2016 19:38:08 +0800 Subject: [PATCH 01/17] =?UTF-8?q?utf-8=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/quality_analysis_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb index e13882f6f..9c6c07109 100644 --- a/app/helpers/quality_analysis_helper.rb +++ b/app/helpers/quality_analysis_helper.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 module QualityAnalysisHelper def sqale_rating_status val From 69f7dab04d68142a53c8953d43f77e21f09d6a0b Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 24 Jun 2016 21:33:35 +0800 Subject: [PATCH 02/17] some modified --- app/controllers/quality_analysis_controller.rb | 11 +++++++---- app/controllers/repositories_controller.rb | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 83e5960b9..6453ef5a8 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -21,11 +21,11 @@ class QualityAnalysisController < ApplicationController #@client.exists?(job_name) @g = Gitlab.client user_name = User.find(params[:user_id]).try(:login) - branch = params[:branch].nil? ? "master" : params[:branch] + branch = params[:branch].blank? ? "master" : params[:branch] language = params[:language] path = params[:path] identifier = params[:identifier] - qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first + qa = QualityAnalysis.where(:project_id => @project.id).first version = qa.nil? ? 1 : qa.sonar_version + 1 properties = "sonar.projectKey=#{user_name}:#{identifier} sonar.projectName=#{user_name}:#{identifier} @@ -42,16 +42,19 @@ class QualityAnalysisController < ApplicationController @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties #sonar-properties # # replace config.xml of jenkins - @client = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) + @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) # relace gitlab hook # genkins address @g.add_project_hook(@project.gpid, jenkins_address + "/project/#{user_name}_#{identifier}") - if qa.nil? + if qa.blank? QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, :sonar_version => version, :path => path, :branch => branch, :language => language) else qa.update_attribute(:sonar_version, version) end + + # scan + @client.job.build("#{user_name}_#{identifier}") end def index diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index cbb5b2f69..7c3acb2cc 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -20,6 +20,8 @@ require 'SVG/Graph/BarHorizontal' require 'digest/sha1' require 'redmine/scm/adapters/abstract_adapter' require 'tempfile' +require 'json' +require 'open-uri' class ChangesetNotFound < Exception; end class InvalidRevisionParam < Exception; end @@ -358,6 +360,11 @@ update end def show + # sonar_address = Redmine::Configuration['sonar_address'] + # projects_date = open(sonar_address + "/api/projects/index").read + # arr = JSON.parse(projects_date).map {|m| m["nm"]} + # arr.map + ## TODO: the below will move to filter, done. if !User.current.member_of?(@project) && @project.hidden_repo render_403 From e5b93ac7ed7c8cdad1e02d7a726f2e1730b712b8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Jun 2016 18:13:46 +0800 Subject: [PATCH 03/17] modified main method --- .../quality_analysis_controller.rb | 109 +++++++++--------- app/helpers/quality_analysis_helper.rb | 38 +++--- app/views/quality_analysis/_show.html.erb | 20 ++-- app/views/repositories/show.html.erb | 8 +- ...0624103411_add_name_to_quality_analyses.rb | 5 - ...0316_add_sonar_name_to_quality_analyses.rb | 5 + db/schema.rb | 3 +- 7 files changed, 93 insertions(+), 95 deletions(-) delete mode 100644 db/migrate/20160624103411_add_name_to_quality_analyses.rb create mode 100644 db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 6453ef5a8..9a5745dc1 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -1,6 +1,7 @@ class QualityAnalysisController < ApplicationController before_filter :find_project_by_project_id#, :except => [:getattachtype] before_filter :authorize + before_filter :connect_jenkins, :only => [:create] layout "base_projects" include ApplicationHelper require 'jenkins_api_client' @@ -13,74 +14,61 @@ class QualityAnalysisController < ApplicationController end def create - gitlab_address = Redmine::Configuration['gitlab_address'] - jenkins_address = Redmine::Configuration['jenkins_address'] - @client = JenkinsApi::Client.new(:server_url => jenkins_address, - :username => "temp", - :password => '123123') - #@client.exists?(job_name) - @g = Gitlab.client user_name = User.find(params[:user_id]).try(:login) - branch = params[:branch].blank? ? "master" : params[:branch] - language = params[:language] - path = params[:path] identifier = params[:identifier] - qa = QualityAnalysis.where(:project_id => @project.id).first - version = qa.nil? ? 1 : qa.sonar_version + 1 - properties = "sonar.projectKey=#{user_name}:#{identifier} + job_name = "#{user_name}:#{identifier}" + # Checks if the given job exists in Jenkins. + unless @client.job.exists?(job_name) + @g = Gitlab.client + branch = params[:branch].blank? ? "master" : params[:branch] + language = params[:language] + path = params[:path] + qa = QualityAnalysis.where(:project_id => @project.id).first + version = qa.nil? ? 1 : qa.sonar_version + 1 + properties = "sonar.projectKey=#{user_name}:#{identifier} sonar.projectName=#{user_name}:#{identifier} sonar.projectVersion=#{version} sonar.sources=#{path} sonar.language=#{language.downcase} sonar.sourceEncoding=utf-8" - git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" - - # # # modify config - @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) - @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url - @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" - @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties #sonar-properties - # - # replace config.xml of jenkins - @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) - # relace gitlab hook - # genkins address - @g.add_project_hook(@project.gpid, jenkins_address + "/project/#{user_name}_#{identifier}") - if qa.blank? - QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, :sonar_version => version, :path => path, :branch => branch, :language => language) - - else - qa.update_attribute(:sonar_version, version) + git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" + # modify config.yml + @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) + @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url + @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" + @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties + @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) + # relace gitlab hook + @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}") + # build job + opts = {'build_start_timeout' => 30, 'cancel_on_build_start_timeout' => true} + code = @client.job.build("#{user_name}_#{identifier}", opts) + # sucessed will return "201" + raise "Unable to build job: #{user_name}_#{identifier}" unless code == '201' + if qa.blank? && code == '201' + QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, + :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => job_name) + else + qa.update_attribute(:sonar_version, version) + end end - - # scan - @client.job.build("#{user_name}_#{identifier}") end def index @sonar_address = Redmine::Configuration['sonar_address'] - # if params[:resource_id].nil? - # @name_flag = true - # @quality_analyses = QualityAnalysis.where(:project_id => @project.id) - # # @quality_analyses.map {|qa| qa.} - # # if @quality_analyses.count > 0 - # # @quality_analyses.each do |qa| - # # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] - # # - # # end - # # end - # # projects_date = open(@sonar_address + "/api/projects/index").read - # # arr = JSON.parse(projects_date).map {|m| m["nm"]} - # # arr.map - # else - qa = QualityAnalysis.where(:project_id => @project.id).first - @resource_id = qa.author_login+":"+qa.rep_identifier - @name_flag = false - complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read - @complexity =JSON.parse(complexity_date).first - issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read - @sonar_issues = JSON.parse(issue_date).first - # end + projects_date = open(@sonar_address + "/api/projects/index").read + arr = JSON.parse(projects_date).map {|m| m["nm"]} # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] + if params[:resource_id].nil? + @quality_analyses = QualityAnalysis.where("sonar_name in #{arr}") + else + qa = QualityAnalysis.where(:project_id => @project.id).first + @resource_id = qa.author_login+":"+qa.rep_identifier + @name_flag = false + complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read + @complexity =JSON.parse(complexity_date).first + # issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read + # @sonar_issues = JSON.parse(issue_date).first + end end # Find project of id params[:project_id] @@ -99,4 +87,13 @@ class QualityAnalysisController < ApplicationController end end + def connect_jenkins + @gitlab_address = Redmine::Configuration['gitlab_address'] + @jenkins_address = Redmine::Configuration['jenkins_address'] + # connect jenkins + @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123') + rescue + logger.error("failed to connect Jenkins") + end + end diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb index 9c6c07109..d2948e02b 100644 --- a/app/helpers/quality_analysis_helper.rb +++ b/app/helpers/quality_analysis_helper.rb @@ -3,19 +3,19 @@ module QualityAnalysisHelper def sqale_rating_status val arr = [] - if val.to_i > 0 && val.to_i < 5 + if val > 0 && val < 5 arr << "很好" arr << "b_green2" - elsif val.to_i > 5 && val.to_i < 10 + elsif val. > 5 && val < 10 arr << "较好" arr << "b_slow_yellow" - elsif val.to_i > 10 && val.to_i < 20 + elsif val > 10 && val < 20 arr << "中等" arr << "b_yellow" - elsif val.to_i > 20 && val.to_i < 50 + elsif val > 20 && val < 50 arr << "较差" arr << "b_slow_red" - elsif val.to_i > 20 + elsif val > 20 arr << "很差" arr << "b_red" end @@ -23,13 +23,13 @@ module QualityAnalysisHelper def complexity_status val arr = [] - if val.to_i < 10 + if val < 10 arr << "良好" arr << "b_green2" - elsif val.to_i > 10 && val.to_i < 15 + elsif val > 10 && val < 15 arr << "较高" arr << "b_yellow" - elsif val.to_i > 15 + elsif val > 15 arr << "很高" arr << "b_red" end @@ -37,13 +37,13 @@ module QualityAnalysisHelper def duplicated_lines_density_status val arr = [] - if val.to_i < 30 + if val < 30 arr << "良好" arr << "b_green2" - elsif val.to_i > 30 && val.to_i < 50 + elsif val > 30 && val < 50 arr << "较高" arr << "b_yellow" - elsif val.to_i > 50 + elsif val > 50 arr << "很高" arr << "b_red" end @@ -51,28 +51,28 @@ module QualityAnalysisHelper def comment_lines_density_status val arr = [] - if val.to_i < 20 + if val < 20 arr << "较低" arr << "b_yellow" - elsif val.to_i > 20 && val.to_i < 50 + elsif val > 20 && val < 50 arr << "正常" arr << "b_green2" - elsif val.to_i > 50 + elsif val > 50 arr << "较高" arr << "b_red" end end def score_sqale_rating val - if val.to_i > 0 && val.to_i < 5 + if val > 0 && val < 5 "5" - elsif val.to_i > 5 && val.to_i < 10 + elsif val > 5 && val < 10 "4" - elsif val.to_i > 10 && val.to_i < 20 + elsif val > 10 && val < 20 "3" - elsif val.to_i > 20 && val.to_i < 50 + elsif val > 20 && val < 50 "2" - elsif val.to_i > 20 + elsif val > 20 "1" end end diff --git a/app/views/quality_analysis/_show.html.erb b/app/views/quality_analysis/_show.html.erb index 8f1cb8443..864512bdd 100644 --- a/app/views/quality_analysis/_show.html.erb +++ b/app/views/quality_analysis/_show.html.erb @@ -1,8 +1,8 @@ <%= javascript_include_tag 'highcharts','highcharts-more' %> - <%= render :partial => "hightchars" %> -
-

质量分析

-
+<%= render :partial => "hightchars" %> +
+

质量分析

+
当前分支:<%= params[:branch] %>
项目代码质量分析报告
@@ -12,28 +12,28 @@

质量等级

-

<%= @complexity["msr"][9]["frmt_val"] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>

+

<%= @complexity["msr"][9]["frmt_val"] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

复杂度

-

<%= @complexity["msr"][6]["val"] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"])[0] %>

+

<%= @complexity["msr"][6]["val"] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"].to_i)[0] %>

代码重复度

-

<%= @complexity["msr"][7]["frmt_val"] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"])[0] %>

+

<%= @complexity["msr"][7]["frmt_val"] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %>

注释率

-

<%= @complexity["msr"][5]["frmt_val"] %> borderRadius"><%=comment_lines_density_status(@complexity["msr"][5]["val"])[0] %>

+

<%= @complexity["msr"][5]["frmt_val"] %> borderRadius"><%=comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %>

-
质量等级<%= score_sqale_rating(@complexity["msr"][9]["val"]) %>/5分可定性评价为:质量<%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
+
质量等级<%= score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分可定性评价为:质量<%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
技术债务<%= @complexity["msr"][8]["frmt_val"] %>查看详情
质量问题 @@ -46,7 +46,7 @@
信息<%= @sonar_issues["msr"][5]["frmt_val"] %>%;">
-
代码规模可定性评价为:<%= lines_scale(@complexity["msr"][0]["frmt_val"]) %>
+
代码规模可定性评价为:<%= lines_scale(@complexity["msr"][0]["frmt_val"].to_i) %>

代码行数

diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 124e3ef4d..5f4288262 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -2,13 +2,13 @@

<%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

ZIP下载 - <% if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> + <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> <%# if User.current.member_of?(@project) %> <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> <%# end %> - <% else %> - <%= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %> - <% end %> + <%# else %> + <%#= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %> + <%# end %>
<% if @entries.nil? %> diff --git a/db/migrate/20160624103411_add_name_to_quality_analyses.rb b/db/migrate/20160624103411_add_name_to_quality_analyses.rb deleted file mode 100644 index bf61fd5ac..000000000 --- a/db/migrate/20160624103411_add_name_to_quality_analyses.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddNameToQualityAnalyses < ActiveRecord::Migration - def change - add_column :quality_analyses, :language, :string - end -end diff --git a/db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb b/db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb new file mode 100644 index 000000000..c69b5c909 --- /dev/null +++ b/db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb @@ -0,0 +1,5 @@ +class AddSonarNameToQualityAnalyses < ActiveRecord::Migration + def change + add_column :quality_analyses, :sonar_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index ee2da177b..16f39f6a1 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 => 20160624055127) do +ActiveRecord::Schema.define(:version => 20160627090316) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1844,6 +1844,7 @@ ActiveRecord::Schema.define(:version => 20160624055127) do t.string "path" t.string "branch" t.string "language" + t.string "sonar_name" end create_table "queries", :force => true do |t| From f930bbddad7eb88c1884878dade392e132627342 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 28 Jun 2016 09:45:45 +0800 Subject: [PATCH 04/17] modified create --- .../quality_analysis_controller.rb | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 9a5745dc1..bff369eaf 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -14,43 +14,53 @@ class QualityAnalysisController < ApplicationController end def create - user_name = User.find(params[:user_id]).try(:login) - identifier = params[:identifier] - job_name = "#{user_name}:#{identifier}" - # Checks if the given job exists in Jenkins. - unless @client.job.exists?(job_name) - @g = Gitlab.client - branch = params[:branch].blank? ? "master" : params[:branch] - language = params[:language] - path = params[:path] - qa = QualityAnalysis.where(:project_id => @project.id).first - version = qa.nil? ? 1 : qa.sonar_version + 1 - properties = "sonar.projectKey=#{user_name}:#{identifier} + begin + user_name = User.find(params[:user_id]).try(:login) + identifier = params[:identifier] + # REDO + job_name = "#{user_name}:#{identifier}" + + # Checks if the given job exists in Jenkins. + unless @client.job.exists?(job_name) + @g = Gitlab.client + branch = params[:branch].blank? ? "master" : params[:branch] + language = params[:language] + path = params[:path] + qa = QualityAnalysis.where(:project_id => @project.id).first + version = qa.nil? ? 1 : qa.sonar_version + 1 + properties = "sonar.projectKey=#{user_name}:#{identifier} sonar.projectName=#{user_name}:#{identifier} sonar.projectVersion=#{version} sonar.sources=#{path} sonar.language=#{language.downcase} sonar.sourceEncoding=utf-8" - git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" - # modify config.yml - @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) - @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url - @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" - @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties - @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) - # relace gitlab hook - @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}") - # build job - opts = {'build_start_timeout' => 30, 'cancel_on_build_start_timeout' => true} - code = @client.job.build("#{user_name}_#{identifier}", opts) - # sucessed will return "201" - raise "Unable to build job: #{user_name}_#{identifier}" unless code == '201' - if qa.blank? && code == '201' - QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, - :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => job_name) - else - qa.update_attribute(:sonar_version, version) + git_url = @gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git" + + # modify config.yml + @doc = Nokogiri::XML(File.open(File.join(Rails.root, 'tmp', 'config.xml'))) + @doc.at_xpath("//hudson.plugins.git.UserRemoteConfig/url").content = git_url + @doc.at_xpath("//hudson.plugins.git.BranchSpec/name").content = "*/#{branch}" + @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties + + # return '200' if successed + jenkins_job = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) + + # replace gitlab hook + @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}") + # build job + logger.error("Test#{jenkins_job}") + + # return '201' if successed + code = @client.job.build("#{user_name}_#{identifier}") + if qa.blank? + QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, + :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => job_name) + else + qa.update_attribute(:sonar_version, version) + end end + rescue => e + puts e end end @@ -90,10 +100,11 @@ class QualityAnalysisController < ApplicationController def connect_jenkins @gitlab_address = Redmine::Configuration['gitlab_address'] @jenkins_address = Redmine::Configuration['jenkins_address'] + # connect jenkins @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123') - rescue - logger.error("failed to connect Jenkins") + rescue => e + logger.error("failed to connect Jenkins ==> #{e}") end end From dd6b19a8b543234d1f9d2fa879a583bf3d1f4cb7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 28 Jun 2016 14:48:09 +0800 Subject: [PATCH 05/17] some status of sonar --- .../quality_analysis_controller.rb | 66 +++++++++++-------- app/models/quality_analysis.rb | 2 +- .../quality_analysis/_result_list.html.erb | 6 +- .../repositories/_quality_analysis.html.erb | 2 +- 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index bff369eaf..7de4bedab 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -17,19 +17,20 @@ class QualityAnalysisController < ApplicationController begin user_name = User.find(params[:user_id]).try(:login) identifier = params[:identifier] + rep_id = params[:rep_id] # REDO - job_name = "#{user_name}:#{identifier}" + job_name = "#{user_name}-#{rep_id}" # Checks if the given job exists in Jenkins. unless @client.job.exists?(job_name) @g = Gitlab.client - branch = params[:branch].blank? ? "master" : params[:branch] + branch = params[:branch] language = params[:language] path = params[:path] - qa = QualityAnalysis.where(:project_id => @project.id).first + qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first version = qa.nil? ? 1 : qa.sonar_version + 1 - properties = "sonar.projectKey=#{user_name}:#{identifier} - sonar.projectName=#{user_name}:#{identifier} + properties = "sonar.projectKey=#{user_name}:#{rep_id} + sonar.projectName=#{user_name}:#{rep_id} sonar.projectVersion=#{version} sonar.sources=#{path} sonar.language=#{language.downcase} @@ -43,18 +44,20 @@ class QualityAnalysisController < ApplicationController @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties # return '200' if successed - jenkins_job = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml) + jenkins_job = @client.job.create("#{job_name}", @doc.to_xml) # replace gitlab hook - @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}") + @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}") # build job - logger.error("Test#{jenkins_job}") - - # return '201' if successed - code = @client.job.build("#{user_name}_#{identifier}") - if qa.blank? + logger.error("Jenkins status of create ==> #{jenkins_job}") + # return '201' if build successed + code = @client.job.build("#{job_name}") + logger.error("build result ==> #{code}") + d = @client.delete("#{job_name}") if jenkins_job == '200' && code != '201' + logger.error("delete result ==> #{code}") + if qa.blank? && code == '201' QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, - :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => job_name) + :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}") else qa.update_attribute(:sonar_version, version) end @@ -62,23 +65,34 @@ class QualityAnalysisController < ApplicationController rescue => e puts e end + respond_to do |format| + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => "#{user_name}:#{rep_id}")} + format.js + end end + # resource_id: login + @repository.id def index - @sonar_address = Redmine::Configuration['sonar_address'] - projects_date = open(@sonar_address + "/api/projects/index").read - arr = JSON.parse(projects_date).map {|m| m["nm"]} # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] - if params[:resource_id].nil? - @quality_analyses = QualityAnalysis.where("sonar_name in #{arr}") - else - qa = QualityAnalysis.where(:project_id => @project.id).first - @resource_id = qa.author_login+":"+qa.rep_identifier - @name_flag = false - complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read - @complexity =JSON.parse(complexity_date).first - # issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read - # @sonar_issues = JSON.parse(issue_date).first + begin + @resource_id = params[:resource_id] + @sonar_address = Redmine::Configuration['sonar_address'] + # projects_date = open(@sonar_address + "/api/projects/index").read + # @arr = JSON.parse(projects_date).map {|m| m["nm"]} # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] + if params[:resource_id].nil? + @name_flag = true + # @quality_analyses = QualityAnalysis.where("sonar_name in (#{arr.empty? ? '0': arr.join(',')})") + @quality_analyses = QualityAnalysis.where(:project_id => @project.id) + else + qa = QualityAnalysis.where(:project_id => @project.id).first + complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read + @complexity =JSON.parse(complexity_date).first + issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read + @sonar_issues = JSON.parse(issue_date).first + end + rescue => e + puts e end + end # Find project of id params[:project_id] diff --git a/app/models/quality_analysis.rb b/app/models/quality_analysis.rb index 229be9826..8b8034c65 100644 --- a/app/models/quality_analysis.rb +++ b/app/models/quality_analysis.rb @@ -1,5 +1,5 @@ class QualityAnalysis < ActiveRecord::Base - attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version, :branch, :path, :rep_identifier, :language + attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version, :branch, :path, :rep_identifier, :language, :sonar_name def user_rep_name self.author_login+":"+self.rep_identifier diff --git a/app/views/quality_analysis/_result_list.html.erb b/app/views/quality_analysis/_result_list.html.erb index 507ded0fe..845049cea 100644 --- a/app/views/quality_analysis/_result_list.html.erb +++ b/app/views/quality_analysis/_result_list.html.erb @@ -6,17 +6,17 @@
  • 版本
  • 分支
  • 语言
  • -
  • 时间
  • +
  • lujing
  • <% if @quality_analyses.count >0 %> <% @quality_analyses.each do |qa| %>
      -
    • <%=link_to "#{qa.author_login}:#{qa.rep_identifier}", project_quality_analysis_path(:resource_id => qa.author_login+":"+qa.rep_identifier, :branch => qa.branch.nil? ? "master" : qa.branch), :class => "analysis-result-name fl fontBlue2" %>
    • +
    • <%=link_to "#{qa.author_login}:#{qa.rep_identifier}", project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => qa.branch.nil? ? "master" : qa.branch), :class => "analysis-result-name fl fontBlue2" %>
    • 1.0
    • <%= qa.branch %>
    • <%= qa.language %>
    • -
    • <%= format_time(qa.created_at) %>
    • +
    • <%= qa.path %>
    <% end %> diff --git a/app/views/repositories/_quality_analysis.html.erb b/app/views/repositories/_quality_analysis.html.erb index f9726fb9b..0b3f38ee3 100644 --- a/app/views/repositories/_quality_analysis.html.erb +++ b/app/views/repositories/_quality_analysis.html.erb @@ -1,6 +1,6 @@
    代码质量分析
    - <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier), :remote => true, :id => 'quality_analyses_form') do %> + <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id), :remote => true, :id => 'quality_analyses_form') do %>
    From a08edcca8a6acdb1ab2d026916d52306460ec450 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 28 Jun 2016 17:18:50 +0800 Subject: [PATCH 06/17] quanxian --- app/controllers/quality_analysis_controller.rb | 9 +++++---- app/helpers/repositories_helper.rb | 5 +++++ app/views/projects/_development_group.html.erb | 6 ++++++ .../quality_analysis/_result_list.html.erb | 2 +- app/views/quality_analysis/_show.html.erb | 18 +++++++++--------- app/views/quality_analysis/create.js.erb | 1 + .../repositories/_quality_analysis.html.erb | 2 +- app/views/repositories/show.html.erb | 2 ++ public/stylesheets/public.css | 1 + 9 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 app/views/quality_analysis/create.js.erb diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 7de4bedab..591cef596 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -20,17 +20,19 @@ class QualityAnalysisController < ApplicationController rep_id = params[:rep_id] # REDO job_name = "#{user_name}-#{rep_id}" + sonar_name = "#{user_name}:#{rep_id}" # Checks if the given job exists in Jenkins. unless @client.job.exists?(job_name) @g = Gitlab.client branch = params[:branch] + logger.error("##################################{branch}") language = params[:language] path = params[:path] qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first version = qa.nil? ? 1 : qa.sonar_version + 1 - properties = "sonar.projectKey=#{user_name}:#{rep_id} - sonar.projectName=#{user_name}:#{rep_id} + properties = "sonar.projectKey=#{sonar_name} + sonar.projectName=#{sonar_name} sonar.projectVersion=#{version} sonar.sources=#{path} sonar.language=#{language.downcase} @@ -66,7 +68,7 @@ class QualityAnalysisController < ApplicationController puts e end respond_to do |format| - format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => "#{user_name}:#{rep_id}")} + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} format.js end end @@ -83,7 +85,6 @@ class QualityAnalysisController < ApplicationController # @quality_analyses = QualityAnalysis.where("sonar_name in (#{arr.empty? ? '0': arr.join(',')})") @quality_analyses = QualityAnalysis.where(:project_id => @project.id) else - qa = QualityAnalysis.where(:project_id => @project.id).first complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read @complexity =JSON.parse(complexity_date).first issue_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations").read diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 3cf781f76..b525c4aed 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -41,6 +41,11 @@ module RepositoriesHelper identifiers.include?(iden) ? false :true end + def quality_analysis login, rep_id + long_rep_id = "#{login}:#{rep_id}" + QualityAnalysis.where(:sonar_name => long_rep_id).first + end + # 获取文件目录的最新动态 def get_trees_last_changes(project_id, rev, ent_name) g = Gitlab.client diff --git a/app/views/projects/_development_group.html.erb b/app/views/projects/_development_group.html.erb index 2c7d36fb5..6961fcbac 100644 --- a/app/views/projects/_development_group.html.erb +++ b/app/views/projects/_development_group.html.erb @@ -55,6 +55,12 @@ <%= link_to "+"+l(:project_gitlab_create_repository), url_for(:controller => 'projects', :action => 'settings', :id => @project.id, :tab=>'repositories') , :class => "subnav_green" %> <% end %>
    + + <% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %> + + <% end %> <% end %> diff --git a/app/views/quality_analysis/_result_list.html.erb b/app/views/quality_analysis/_result_list.html.erb index 845049cea..8c80d403f 100644 --- a/app/views/quality_analysis/_result_list.html.erb +++ b/app/views/quality_analysis/_result_list.html.erb @@ -12,7 +12,7 @@ <% if @quality_analyses.count >0 %> <% @quality_analyses.each do |qa| %>
      -
    • <%=link_to "#{qa.author_login}:#{qa.rep_identifier}", project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => qa.branch.nil? ? "master" : qa.branch), :class => "analysis-result-name fl fontBlue2" %>
    • +
    • <%=link_to "#{qa.author_login}:#{qa.rep_identifier}", project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => (qa.branch.nil? ? "master" : qa.branch)), :class => "analysis-result-name fl fontBlue2" %>
    • 1.0
    • <%= qa.branch %>
    • <%= qa.language %>
    • diff --git a/app/views/quality_analysis/_show.html.erb b/app/views/quality_analysis/_show.html.erb index 864512bdd..4f8c21fe3 100644 --- a/app/views/quality_analysis/_show.html.erb +++ b/app/views/quality_analysis/_show.html.erb @@ -12,37 +12,37 @@

      质量等级

      -

      <%= @complexity["msr"][9]["frmt_val"] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

      +

      <%= @complexity["msr"][9]["frmt_val"] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

      复杂度

      -

      <%= @complexity["msr"][6]["val"] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"].to_i)[0] %>

      +

      <%= @complexity["msr"][6]["val"] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"].to_i)[0] %>

    代码重复度

    -

    <%= @complexity["msr"][7]["frmt_val"] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %>

    +

    <%= @complexity["msr"][7]["frmt_val"] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %>

    注释率

    -

    <%= @complexity["msr"][5]["frmt_val"] %> borderRadius"><%=comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %>

    +

    <%= @complexity["msr"][5]["frmt_val"] %> borderRadius"><%=comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %>

    质量等级<%= score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分可定性评价为:质量<%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
    技术债务<%= @complexity["msr"][8]["frmt_val"] %>查看详情
    -
    质量问题 +
    质量问题 <%= @sonar_issues["msr"][0]["frmt_val"] %>问题分类如下:
    -
    阻断<%= @sonar_issues["msr"][1]["frmt_val"] %>%;">
    -
    严重<%= @sonar_issues["msr"][2]["frmt_val"] %>%;">
    -
    主要<%= @sonar_issues["msr"][3]["frmt_val"] %>%;">
    -
    次要<%= @sonar_issues["msr"][4]["frmt_val"] %>%;">
    +
    阻断<%= @sonar_issues["msr"][1]["frmt_val"] %>%;">
    +
    严重<%= @sonar_issues["msr"][2]["frmt_val"] %>%;">
    +
    主要<%= @sonar_issues["msr"][3]["frmt_val"] %>%;">
    +
    次要<%= @sonar_issues["msr"][4]["frmt_val"] %>%;">
    信息<%= @sonar_issues["msr"][5]["frmt_val"] %>%;">
    diff --git a/app/views/quality_analysis/create.js.erb b/app/views/quality_analysis/create.js.erb new file mode 100644 index 000000000..f6955106f --- /dev/null +++ b/app/views/quality_analysis/create.js.erb @@ -0,0 +1 @@ +<% %> \ No newline at end of file diff --git a/app/views/repositories/_quality_analysis.html.erb b/app/views/repositories/_quality_analysis.html.erb index 0b3f38ee3..e0240c257 100644 --- a/app/views/repositories/_quality_analysis.html.erb +++ b/app/views/repositories/_quality_analysis.html.erb @@ -1,6 +1,6 @@
    代码质量分析
    - <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id), :remote => true, :id => 'quality_analyses_form') do %> + <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id), :id => 'quality_analyses_form') do %>
    diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 5f4288262..6bc01c83c 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -4,7 +4,9 @@ ZIP下载 <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> <%# if User.current.member_of?(@project) %> + <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> + <% end %> <%# end %> <%# else %> <%#= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %> diff --git a/public/stylesheets/public.css b/public/stylesheets/public.css index 743c81014..2ab150405 100644 --- a/public/stylesheets/public.css +++ b/public/stylesheets/public.css @@ -28,6 +28,7 @@ h2{ font-size:18px; } h3{ font-size:14px; } h4{ font-size:14px; } .f8 {font-size:8px;} +.f10 {font-size:10px;} .f12{font-size:12px; font-weight:normal;} .f14{font-size:14px;} .f16{font-size:16px;} From 300ad6840537cc2ea92bac3f183e1951d7b6e5c5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 28 Jun 2016 17:39:58 +0800 Subject: [PATCH 07/17] default path for sonar --- .../quality_analysis_controller.rb | 3 +-- app/views/repositories/show.html.erb | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 591cef596..7b0bc5327 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -26,9 +26,8 @@ class QualityAnalysisController < ApplicationController unless @client.job.exists?(job_name) @g = Gitlab.client branch = params[:branch] - logger.error("##################################{branch}") language = params[:language] - path = params[:path] + path = params[:path].nil? ? "./" :params[:path] qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first version = qa.nil? ? 1 : qa.sonar_version + 1 properties = "sonar.projectKey=#{sonar_name} diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 6bc01c83c..0f179d150 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -1,16 +1,18 @@ <%= call_hook(:view_repositories_show_contextual, {:repository => @repository, :project => @project}) %>

    <%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

    - ZIP下载 - <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> - <%# if User.current.member_of?(@project) %> - <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> - <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> - <% end %> - <%# end %> - <%# else %> + <% unless @entries.nil? %> + ZIP下载 + <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> + <%# if User.current.member_of?(@project) %> + <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> + <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> + <% end %> + <%# end %> + <%# else %> <%#= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %> - <%# end %> + <%# end %> + <% end %>
    <% if @entries.nil? %> From 0a684227b8d58fa2d6a6b1766dc4a9b22df4e45a Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 28 Jun 2016 22:01:44 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E5=A6=82=E6=9E=9Csonar=E6=B2=A1=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E5=AE=8C=E6=88=90=E5=88=99=E6=9A=82=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/quality_analysis_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 7b0bc5327..40e1c81de 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -77,12 +77,12 @@ class QualityAnalysisController < ApplicationController begin @resource_id = params[:resource_id] @sonar_address = Redmine::Configuration['sonar_address'] - # projects_date = open(@sonar_address + "/api/projects/index").read - # @arr = JSON.parse(projects_date).map {|m| m["nm"]} # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] if params[:resource_id].nil? @name_flag = true - # @quality_analyses = QualityAnalysis.where("sonar_name in (#{arr.empty? ? '0': arr.join(',')})") - @quality_analyses = QualityAnalysis.where(:project_id => @project.id) + projects_date = open(@sonar_address + "/api/projects/index").read + arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] + quality_analyses = QualityAnalysis.where(:project_id => @project.id) + @quality_analyses.collect{|qa| arr.include?(qa.sonar_name)} else complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read @complexity =JSON.parse(complexity_date).first From 22b40c082cd71de2873af3136437908a10f8d1af Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Jun 2016 09:10:47 +0800 Subject: [PATCH 09/17] resole some nil problems --- .../quality_analysis_controller.rb | 2 +- .../quality_analysis/_hightchars.html.erb | 6 +- app/views/quality_analysis/_show.html.erb | 94 +++++++++++-------- app/views/repositories/show.html.erb | 4 +- 4 files changed, 62 insertions(+), 44 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 7b0bc5327..9ea602659 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -27,7 +27,7 @@ class QualityAnalysisController < ApplicationController @g = Gitlab.client branch = params[:branch] language = params[:language] - path = params[:path].nil? ? "./" :params[:path] + path = params[:path].blank? ? "./" : params[:path] qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first version = qa.nil? ? 1 : qa.sonar_version + 1 properties = "sonar.projectKey=#{sonar_name} diff --git a/app/views/quality_analysis/_hightchars.html.erb b/app/views/quality_analysis/_hightchars.html.erb index fb60eaed3..278851ad5 100644 --- a/app/views/quality_analysis/_hightchars.html.erb +++ b/app/views/quality_analysis/_hightchars.html.erb @@ -209,7 +209,7 @@ }, series: [{ name: '复杂度', - data: [<%= @complexity["msr"][6]["val"] %>] + data: [<%= @complexity["msr"][6].nil? ? 0 : @complexity["msr"][6]["val"] %>] // tooltip: { // valueSuffix: ' km/h' // } @@ -329,7 +329,7 @@ }, series: [{ name: '重复率', - data: [<%= @complexity["msr"][7]["val"] %>] + data: [<%= @complexity["msr"][7].nil? ? 0 : @complexity["msr"][7]["val"] %>] // tooltip: { // valueSuffix: ' km/h' // } @@ -454,7 +454,7 @@ }, series: [{ name: '质量等级', - data: [<%= @complexity["msr"][5]["val"] %>] + data: [<%= @complexity["msr"][5].nil? ? 0 : @complexity["msr"][5]["val"] %>] // tooltip: { // valueSuffix: ' km/h' // } diff --git a/app/views/quality_analysis/_show.html.erb b/app/views/quality_analysis/_show.html.erb index 4f8c21fe3..0a522df52 100644 --- a/app/views/quality_analysis/_show.html.erb +++ b/app/views/quality_analysis/_show.html.erb @@ -1,5 +1,4 @@ <%= javascript_include_tag 'highcharts','highcharts-more' %> -<%= render :partial => "hightchars" %>

    质量分析

    @@ -7,66 +6,85 @@
    项目代码质量分析报告
    概要信息
    -
    -
    -
    -

    -

    质量等级

    -

    <%= @complexity["msr"][9]["frmt_val"] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

    +<% if @complexity["msr"].count > 3 %> + <%= render :partial => "hightchars" %> +
    +
    +
    +

    +

    质量等级

    +

    <%= @complexity["msr"][9].nil? ? 0 : @complexity["msr"][9]["frmt_val"] %> + borderRadius"><%= @complexity["msr"][9].nil? ? 0 : sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

    +
    +
    +

    +

    复杂度

    +

    <%= @complexity["msr"][6].nil? ? 0 : @complexity["msr"][6]["val"] %> + borderRadius"><%= @complexity["msr"][6].nil? ? 0 : complexity_status(@complexity["msr"][6]["val"].to_i)[0] %>

    +
    -
    -

    -

    复杂度

    -

    <%= @complexity["msr"][6]["val"] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"].to_i)[0] %>

    +
    +
    +

    +

    代码重复度

    +

    <%= @complexity["msr"][7].nil? ? 0 : @complexity["msr"][7]["frmt_val"] %> + borderRadius"><%= @complexity["msr"][7].nil? ? 0 : duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %>

    +
    +
    +

    +

    注释率

    +

    <%= @complexity["msr"][5].nil? ? 0 : @complexity["msr"][5]["frmt_val"] %> + borderRadius"><%= @complexity["msr"][5].nil? ? 0 : comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %>

    +
    -
    -
    -

    -

    代码重复度

    -

    <%= @complexity["msr"][7]["frmt_val"] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %>

    -
    -
    -

    -

    注释率

    -

    <%= @complexity["msr"][5]["frmt_val"] %> borderRadius"><%=comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %>

    -
    -
    -
    -
    质量等级<%= score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分可定性评价为:质量<%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
    +<% end %> + +
    质量等级<%=@complexity["msr"][9].nil? ? 0 : score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分 + 可定性评价为:质量<%=@complexity["msr"][9].nil? ? 0 : sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
    -
    技术债务<%= @complexity["msr"][8]["frmt_val"] %>查看详情
    +
    技术债务<%=@complexity["msr"][8].nil? ? 0 : @complexity["msr"][8]["frmt_val"] %> + 查看详情
    质量问题 - <%= @sonar_issues["msr"][0]["frmt_val"] %>问题分类如下:
    + <%=@sonar_issues["msr"][0].nil? ? 0 : @sonar_issues["msr"][0]["frmt_val"] %>问题分类如下:
    -
    阻断<%= @sonar_issues["msr"][1]["frmt_val"] %>%;">
    -
    严重<%= @sonar_issues["msr"][2]["frmt_val"] %>%;">
    -
    主要<%= @sonar_issues["msr"][3]["frmt_val"] %>%;">
    -
    次要<%= @sonar_issues["msr"][4]["frmt_val"] %>%;">
    -
    信息<%= @sonar_issues["msr"][5]["frmt_val"] %>%;">
    +
    阻断 + <%= @sonar_issues["msr"][1].nil? ? 0 : @sonar_issues["msr"][1]["frmt_val"] %> + %;">
    +
    严重 + <%= @sonar_issues["msr"][2].nil? ? 0 : @sonar_issues["msr"][2]["frmt_val"] %> + %;">
    +
    主要 + <%= @sonar_issues["msr"][3].nil? ? 0 : @sonar_issues["msr"][3]["frmt_val"] %> + %;">
    +
    次要 + <%=@sonar_issues["msr"][4].nil? ? 0 : @sonar_issues["msr"][4]["frmt_val"] %> + %;">
    +
    信息 + <%=@sonar_issues["msr"][5].nil? ? 0 : @sonar_issues["msr"][5]["frmt_val"] %>%;">
    -
    代码规模可定性评价为:<%= lines_scale(@complexity["msr"][0]["frmt_val"].to_i) %>
    +
    代码规模可定性评价为:<%=@complexity["msr"][0].nil? ? 0 : lines_scale(@complexity["msr"][0]["frmt_val"].to_i) %>

    代码行数

    -

    <%= @complexity["msr"][0]["frmt_val"] %>

    +

    <%= @complexity["msr"][0].nil? ? 0 : @complexity["msr"][0]["frmt_val"] %>

    文件

    -

    <%= @complexity["msr"][2]["frmt_val"] %>

    +

    <%= @complexity["msr"][2].nil? ? 0 : @complexity["msr"][2]["frmt_val"] %>

    目录

    -

    <%= @complexity["msr"][3]["frmt_val"] %>

    +

    <%= @complexity["msr"][3].nil? ? 0 : @complexity["msr"][3]["frmt_val"] %>

    -

    <%= @complexity["msr"][1]["frmt_val"] %>

    +

    <%= @complexity["msr"][1].nil? ? 0 : @complexity["msr"][1]["frmt_val"] %>

    方法

    -

    <%= @complexity["msr"][4]["frmt_val"] %>

    +

    <%=@complexity["msr"][4].nil? ? 0 : @complexity["msr"][4]["frmt_val"] %>

    diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 0f179d150..92769dbbe 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -5,9 +5,9 @@ ZIP下载 <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> <%# if User.current.member_of?(@project) %> - <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> + <%# if quality_analysis(User.current.try(:login), @repository.id).nil? %> <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> - <% end %> + <%# end %> <%# end %> <%# else %> <%#= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %> From e887ac5c7c500b91d29522c47483e67316c10eaf Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Jun 2016 09:38:30 +0800 Subject: [PATCH 10/17] git data from sonar --- app/controllers/quality_analysis_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index eb20426e3..ceac41399 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -66,10 +66,10 @@ class QualityAnalysisController < ApplicationController rescue => e puts e end - respond_to do |format| - format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} - format.js - end + # respond_to do |format| + # format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} + # format.js + # end end # resource_id: login + @repository.id @@ -81,8 +81,8 @@ class QualityAnalysisController < ApplicationController @name_flag = true projects_date = open(@sonar_address + "/api/projects/index").read arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"] - quality_analyses = QualityAnalysis.where(:project_id => @project.id) - @quality_analyses.collect{|qa| arr.include?(qa.sonar_name)} + @quality_analyses = QualityAnalysis.where(:project_id => @project.id).select{|qa| arr.include?(qa.sonar_name)} + else complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,file_line,files,functions,classes,directories").read @complexity =JSON.parse(complexity_date).first From c8178fc02370d7046ed474dd75cd3b5702a2444e Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Jun 2016 09:59:21 +0800 Subject: [PATCH 11/17] allert --- app/controllers/quality_analysis_controller.rb | 15 ++++++++++++++- app/views/quality_analysis/create.js.erb | 2 +- app/views/repositories/_quality_analysis.html.erb | 4 ++-- app/views/repositories/show.html.erb | 6 +++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index ceac41399..852277126 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -26,7 +26,7 @@ class QualityAnalysisController < ApplicationController unless @client.job.exists?(job_name) @g = Gitlab.client branch = params[:branch] - language = params[:language] + language = swith_language_type(params[:language]) path = params[:path].blank? ? "./" : params[:path] qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first version = qa.nil? ? 1 : qa.sonar_version + 1 @@ -72,6 +72,19 @@ class QualityAnalysisController < ApplicationController # end end + # get language type + def swith_language_type language + if language = "c#" + "cs" + elsif language = "python" + "py" + elsif language = "c" + "c++" + else + language + end + end + # resource_id: login + @repository.id def index begin diff --git a/app/views/quality_analysis/create.js.erb b/app/views/quality_analysis/create.js.erb index f6955106f..4bb632b43 100644 --- a/app/views/quality_analysis/create.js.erb +++ b/app/views/quality_analysis/create.js.erb @@ -1 +1 @@ -<% %> \ No newline at end of file +alert("dengdai") \ No newline at end of file diff --git a/app/views/repositories/_quality_analysis.html.erb b/app/views/repositories/_quality_analysis.html.erb index e0240c257..b6eb62124 100644 --- a/app/views/repositories/_quality_analysis.html.erb +++ b/app/views/repositories/_quality_analysis.html.erb @@ -1,6 +1,6 @@
    代码质量分析
    - <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id), :id => 'quality_analyses_form') do %> + <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id, :remote => true), :id => 'quality_analyses_form') do %>
    @@ -12,7 +12,7 @@
    - <%= select_tag :language, options_for_select(["java","python","ruby","c++","c#", "Web"]), :id => 'branch', :class => "analysis-option-box" %> + <%= select_tag :language, options_for_select(["java","python","ruby","c++","c#","c"]), :id => 'branch', :class => "analysis-option-box" %>
    diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 92769dbbe..b524e898f 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -5,9 +5,9 @@ ZIP下载 <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> <%# if User.current.member_of?(@project) %> - <%# if quality_analysis(User.current.try(:login), @repository.id).nil? %> - <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> - <%# end %> + <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> + <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> + <% end %> <%# end %> <%# else %> <%#= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %> From 36944e8cce43be6b5c08917b26ee8ca91057321b Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 29 Jun 2016 10:06:23 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/quality_analysis/create.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/quality_analysis/create.js.erb b/app/views/quality_analysis/create.js.erb index 4bb632b43..8f93f86ee 100644 --- a/app/views/quality_analysis/create.js.erb +++ b/app/views/quality_analysis/create.js.erb @@ -1 +1 @@ -alert("dengdai") \ No newline at end of file +alert("正在分析中…………(大概需要30分钟,请耐心等待)") \ No newline at end of file From 3390a2d05f1ec08075a5c0ddc5171b15a072c4dd Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Jun 2016 11:10:19 +0800 Subject: [PATCH 13/17] 500 --- app/controllers/quality_analysis_controller.rb | 8 ++++---- app/views/quality_analysis/_hightchars.html.erb | 2 +- app/views/quality_analysis/create.js.erb | 1 - app/views/repositories/_quality_analysis.html.erb | 2 +- app/views/repositories/show.html.erb | 2 +- config/routes.rb | 1 + 6 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 app/views/quality_analysis/create.js.erb diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 852277126..a9b93269a 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -67,18 +67,18 @@ class QualityAnalysisController < ApplicationController puts e end # respond_to do |format| - # format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} + # #format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} # format.js # end end # get language type def swith_language_type language - if language = "c#" + if language == "c#" "cs" - elsif language = "python" + elsif language == "python" "py" - elsif language = "c" + elsif language == "c" "c++" else language diff --git a/app/views/quality_analysis/_hightchars.html.erb b/app/views/quality_analysis/_hightchars.html.erb index 278851ad5..9e6cdf5aa 100644 --- a/app/views/quality_analysis/_hightchars.html.erb +++ b/app/views/quality_analysis/_hightchars.html.erb @@ -94,7 +94,7 @@ }, series: [{ name: '代码质量', - data: [<%= @complexity["msr"][9]["val"] %>] + data: [<%= @complexity["msr"][9].nil? ? 0 : @complexity["msr"][9]["val"] %>] // tooltip: { // valueSuffix: ' km/h' // } diff --git a/app/views/quality_analysis/create.js.erb b/app/views/quality_analysis/create.js.erb deleted file mode 100644 index 8f93f86ee..000000000 --- a/app/views/quality_analysis/create.js.erb +++ /dev/null @@ -1 +0,0 @@ -alert("正在分析中…………(大概需要30分钟,请耐心等待)") \ No newline at end of file diff --git a/app/views/repositories/_quality_analysis.html.erb b/app/views/repositories/_quality_analysis.html.erb index b6eb62124..17af1b477 100644 --- a/app/views/repositories/_quality_analysis.html.erb +++ b/app/views/repositories/_quality_analysis.html.erb @@ -1,6 +1,6 @@
    代码质量分析
    - <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id, :remote => true), :id => 'quality_analyses_form') do %> + <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id), :remote => true, :id => 'quality_analyses_form') do %>
    diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index b524e898f..112f3c4e5 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -6,7 +6,7 @@ <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> <%# if User.current.member_of?(@project) %> <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> - <%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %> + <%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch ), :remote => true, :class => "btn_zipdown fr" %> <% end %> <%# end %> <%# else %> diff --git a/config/routes.rb b/config/routes.rb index 52629604c..2a6204bbf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -928,6 +928,7 @@ RedmineApp::Application.routes.draw do } get 'projects/:id/repository/statistics', :to => 'repositories#stats' + get 'projects/:id/repository/quality_analysis', :to => 'repositories#quality_analysis' get 'projects/:id/repository/graph', :to => 'repositories#graph' From 1225a33ceced3ad27d21bb59b574e95e79cce7c1 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 29 Jun 2016 11:21:46 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/quality_analysis/_result_list.html.erb | 2 +- app/views/repositories/_quality_analysis.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/quality_analysis/_result_list.html.erb b/app/views/quality_analysis/_result_list.html.erb index 8c80d403f..6124812c8 100644 --- a/app/views/quality_analysis/_result_list.html.erb +++ b/app/views/quality_analysis/_result_list.html.erb @@ -6,7 +6,7 @@
  • 版本
  • 分支
  • 语言
  • -
  • lujing
  • +
  • 路径
  • <% if @quality_analyses.count >0 %> diff --git a/app/views/repositories/_quality_analysis.html.erb b/app/views/repositories/_quality_analysis.html.erb index b6eb62124..34d70100b 100644 --- a/app/views/repositories/_quality_analysis.html.erb +++ b/app/views/repositories/_quality_analysis.html.erb @@ -3,7 +3,7 @@ <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier, :rep_id => @repository.id, :remote => true), :id => 'quality_analyses_form') do %>
    - +
    From 77387778d8afc87339dc8419a9b39f8f66d9668c Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 29 Jun 2016 14:08:30 +0800 Subject: [PATCH 15/17] some css --- app/helpers/quality_analysis_helper.rb | 2 +- app/views/quality_analysis/_show.html.erb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb index d2948e02b..2a7d350e7 100644 --- a/app/helpers/quality_analysis_helper.rb +++ b/app/helpers/quality_analysis_helper.rb @@ -3,7 +3,7 @@ module QualityAnalysisHelper def sqale_rating_status val arr = [] - if val > 0 && val < 5 + if val < 5 arr << "很好" arr << "b_green2" elsif val. > 5 && val < 10 diff --git a/app/views/quality_analysis/_show.html.erb b/app/views/quality_analysis/_show.html.erb index 0a522df52..b1588edeb 100644 --- a/app/views/quality_analysis/_show.html.erb +++ b/app/views/quality_analysis/_show.html.erb @@ -13,8 +13,8 @@

    质量等级

    -

    <%= @complexity["msr"][9].nil? ? 0 : @complexity["msr"][9]["frmt_val"] %> - borderRadius"><%= @complexity["msr"][9].nil? ? 0 : sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

    +

    <%= @complexity["msr"][9].nil? ? "A" : @complexity["msr"][9]["frmt_val"] %> + borderRadius"><%= @complexity["msr"][9].blank? ? "henhao" : sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

    @@ -41,7 +41,7 @@ <% end %>
    质量等级<%=@complexity["msr"][9].nil? ? 0 : score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分 - 可定性评价为:质量<%=@complexity["msr"][9].nil? ? 0 : sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
    + 可定性评价为:质量<%=@complexity["msr"][9].nil? ? "henhao" : sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
    技术债务<%=@complexity["msr"][8].nil? ? 0 : @complexity["msr"][8]["frmt_val"] %> 查看详情
    From b731b05a5a2b188643f2cbfa0efcd3793386dab5 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 29 Jun 2016 14:12:24 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/quality_analysis/_show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/quality_analysis/_show.html.erb b/app/views/quality_analysis/_show.html.erb index b1588edeb..e55e65bcd 100644 --- a/app/views/quality_analysis/_show.html.erb +++ b/app/views/quality_analysis/_show.html.erb @@ -14,7 +14,7 @@

    质量等级

    <%= @complexity["msr"][9].nil? ? "A" : @complexity["msr"][9]["frmt_val"] %> - borderRadius"><%= @complexity["msr"][9].blank? ? "henhao" : sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

    + borderRadius"><%= @complexity["msr"][9].blank? ? "很好" : sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>

    @@ -41,7 +41,7 @@ <% end %>
    质量等级<%=@complexity["msr"][9].nil? ? 0 : score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分 - 可定性评价为:质量<%=@complexity["msr"][9].nil? ? "henhao" : sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
    + 可定性评价为:质量<%=@complexity["msr"][9].nil? ? "很好" : sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
    技术债务<%=@complexity["msr"][8].nil? ? 0 : @complexity["msr"][8]["frmt_val"] %> 查看详情
    From daf14178cdd9db9b9c4082526e8ca258f72c63be Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 29 Jun 2016 14:20:02 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=8C=E5=8F=AA=E6=9C=89=E9=A1=B9=E7=9B=AE=E6=88=90=E5=91=98?= =?UTF-8?q?=E8=83=BD=E5=A4=9F=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F=E5=88=86?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 112f3c4e5..067056983 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -5,7 +5,7 @@ ZIP下载 <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %> <%# if User.current.member_of?(@project) %> - <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> + <% if quality_analysis(User.current.try(:login), @repository.id).nil? && is_project_manager?(User.current.id, @project.id) %> <%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch ), :remote => true, :class => "btn_zipdown fr" %> <% end %> <%# end %>