sonar升级列表导向

This commit is contained in:
huang 2018-06-28 16:50:36 +08:00
parent c5bbe1e786
commit 8c18d59a9c
2 changed files with 42 additions and 38 deletions

View File

@ -225,43 +225,43 @@ class QualityAnalysisController < ApplicationController
@branch = params[:branch]
@resource_id = params[:resource_id]
@sonar_address = Redmine::Configuration['sonar_address']
if params[:resource_id].nil?
@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).select{|qa| arr.include?(qa.sonar_name)}
else
filter = "sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,files,functions,classes,directories,blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations"
complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=#{filter}").read
@complexity =JSON.parse(complexity_date).first
logger.info("######################################complexity is #{@complexity}")
# 获取排名结果
# @g = Gitlab.client
# @author_infos = @g.rep_user_stats(@project.gpid, :rev => @branch)
# @user_quality_infos = []
# @author_infos.each do |author_info|
# email = author_info.email
# changes = author_info.changes.to_i
# unresolved_issues = open(URI::escape(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}&resolved=false")).read
# unresolved_issue_count = JSON.parse(unresolved_issues)["total"].to_i
# all_issues = open(URI::escape(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}")).read
# all_issue_count = JSON.parse(all_issues)["total"].to_i
# ratio = ((changes == 0 || all_issue_count == 0) ? 0 : format("%0.4f",all_issue_count.to_f/changes.to_f))
# @user_quality_infos << {:email => email, :changes => changes, :unresolved_issue_count => unresolved_issue_count, :ratio => ratio, :all_issue_count => all_issue_count}
# end
# 按名称转换成hash键值对
@ha = {}
@complexity["msr"].each do |com|
key = com["key"]
if key == "sqale_index"
value = com["frmt_val"]
else
value = com["val"]
end
@ha.store(key,value)
end
end
# if params[:resource_id].nil?
@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).select{|qa| arr.include?(qa.sonar_name)}
# else
# # filter = "sqale_rating,function_complexity,duplicated_lines_density,comment_lines_density,sqale_index,lines,files,functions,classes,directories,blocker_violations,critical_violations,major_violations,minor_violations,info_violations,violations"
# # complexity_date = open(@sonar_address + "/api/resources/index?resource=#{@resource_id}&depth=0&metrics=#{filter}").read
# # @complexity =JSON.parse(complexity_date).first
# # logger.info("######################################complexity is #{@complexity}")
# # 获取排名结果
# # @g = Gitlab.client
# # @author_infos = @g.rep_user_stats(@project.gpid, :rev => @branch)
# # @user_quality_infos = []
# # @author_infos.each do |author_info|
# # email = author_info.email
# # changes = author_info.changes.to_i
# # unresolved_issues = open(URI::escape(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}&resolved=false")).read
# # unresolved_issue_count = JSON.parse(unresolved_issues)["total"].to_i
# # all_issues = open(URI::escape(@sonar_address + "/api/issues/search?projectKeys=#{@resource_id}&authors=#{email}")).read
# # all_issue_count = JSON.parse(all_issues)["total"].to_i
# # ratio = ((changes == 0 || all_issue_count == 0) ? 0 : format("%0.4f",all_issue_count.to_f/changes.to_f))
# # @user_quality_infos << {:email => email, :changes => changes, :unresolved_issue_count => unresolved_issue_count, :ratio => ratio, :all_issue_count => all_issue_count}
# # end
#
# # 按名称转换成hash键值对
# # @ha = {}
# # @complexity["msr"].each do |com|
# # key = com["key"]
# # if key == "sqale_index"
# # value = com["frmt_val"]
# # else
# # value = com["val"]
# # end
# # @ha.store(key,value)
# # end
# end
rescue Exception => e
logger.error("fatal################# #{e}")
end

View File

@ -20,7 +20,11 @@
<% if @quality_analyses && @quality_analyses.count > 0 %>
<% @quality_analyses.each do |qa| %>
<tr>
<td style="width:15%;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;padding-left: 5px;" title="<%= qa.sonar_name %>"><%=link_to qa.sonar_name, project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => (qa.branch.nil? ? "master" : qa.branch)), :class => "analysis-result-name fl fontBlue2 hidden" %></td>
<td style="width:15%;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;padding-left: 5px;" title="<%= qa.sonar_name %>">
<a href="<%= Redmine::Configuration['sonar_address'] + "/dashboard?id=#{qa.sonar_name}" %>" class="analysis-result-name fl fontBlue2 hidden" target="_blank">
<%= qa.sonar_name %>
</a>
<%#=link_to qa.sonar_name, project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => (qa.branch.nil? ? "master" : qa.branch)), :class => "analysis-result-name fl fontBlue2 hidden" %></td>
<td style="width:10%;"><%= qa.branch %></td>
<td style="width:10%;"><%= qa.language %></td>
<td style="width:25%;overflow:hidden; white-space: nowrap; text-overflow:ellipsis;" title="<%= qa.path %>"><%= qa.path %></td>