This commit is contained in:
Your Name 2016-06-28 17:18:50 +08:00
parent dd6b19a8b5
commit a08edcca8a
9 changed files with 31 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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 %>
</div>
<!--quality_analysis-->
<% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %>
<div class="subNav">
<%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "f14 c_blue02" %>
</div>
<% end %>
<% end %>
<!-- more -->
<div class="subNav subNav_jiantou" id="expand_tools_expand"><%= l(:label_project_more) %></div>

View File

@ -12,7 +12,7 @@
<% if @quality_analyses.count >0 %>
<% @quality_analyses.each do |qa| %>
<ul class="analysis-result-list">
<li title="Name" title="名称"><%=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" %></li>
<li title="Name" title="名称"><%=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" %></li>
<li class="analysis-result-version fl fontBlue2" title="版本">1.0</li>
<li class="analysis-result-loc fl fontBlue2" title="分支名"><%= qa.branch %></li>
<li class="analysis-result-debt fl fontBlue2" title="语言"><%= qa.language %></li>

View File

@ -12,37 +12,37 @@
<div class="analysis-genral">
<p id="container_sqale_rating" style="max-width:200px;min-height:200px;width:200px; margin:0 auto;"></p>
<p class="fontGrey3">质量等级</p>
<p class="fontBlue2 pr"><%= @complexity["msr"][9]["frmt_val"] %><span class="f8 c_white analysis-genral-icon <%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[1] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %></span></p>
<p class="fontBlue2 pr"><%= @complexity["msr"][9]["frmt_val"] %><span class="f10 c_white analysis-genral-icon <%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[1] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %></span></p>
</div>
<div class="analysis-genral" >
<p id="container_function_complexity" style="max-width:200px;min-height:200px;width:200px; margin:0 auto;"></p>
<p class="fontGrey3">复杂度</p>
<p class="fontBlue2 pr"><%= @complexity["msr"][6]["val"] %><span class="f8 c_white analysis-genral-icon <%= complexity_status(@complexity["msr"][6]["val"].to_i)[1] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"].to_i)[0] %></span></p>
<p class="fontBlue2 pr"><%= @complexity["msr"][6]["val"] %><span class="f10 c_white analysis-genral-icon <%= complexity_status(@complexity["msr"][6]["val"].to_i)[1] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"].to_i)[0] %></span></p>
</div>
</div>
<div class="flex">
<div class="analysis-genral">
<p id="container_duplicated_lines_density" style="max-width:200px;min-height:200px;width:200px; margin:0 auto;"></p>
<p class="fontGrey3">代码重复度</p>
<p class="fontBlue2 pr"><%= @complexity["msr"][7]["frmt_val"] %><span class="f8 c_white analysis-genral-icon <%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[1] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %></span></p>
<p class="fontBlue2 pr"><%= @complexity["msr"][7]["frmt_val"] %><span class="f10 c_white analysis-genral-icon <%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[1] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %></span></p>
</div>
<div class="analysis-genral">
<p id="container_comment_lines_density" style="max-width:200px;min-height:200px;width:200px; margin:0 auto;"></p>
<p class="fontGrey3">注释率</p>
<p class="fontBlue2 pr"><%= @complexity["msr"][5]["frmt_val"] %><span class="f8 c_white analysis-genral-icon <%= comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[1] %> borderRadius"><%=comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %></span></p>
<p class="fontBlue2 pr"><%= @complexity["msr"][5]["frmt_val"] %><span class="f10 c_white analysis-genral-icon <%= comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[1] %> borderRadius"><%=comment_lines_density_status(@complexity["msr"][5]["val"].to_i)[0] %></span></p>
</div>
</div>
</div>
<div class="analysis-tag-wrap f16"> <span class="analysis-tag fl mr15"></span> <span class="fb fl mr10">质量等级</span><span class="mr10 fontGrey2"><span class="c_red f18" style="margin-top:-5px; display:inline-block;"><%= score_sqale_rating(@complexity["msr"][9]["val"].to_i) %></span>/5分</span><span class="fontGrey2">可定性评价为:<span class="c_red">质量<%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %></span></span></div>
<div class="analysis-block mt10 mb40 f14">
<div><span class="fontGrey3 mr30">技术债务</span><span class="fontBlue2 w70 pInline"><%= @complexity["msr"][8]["frmt_val"] %></span><span class="fontGrey2"><a target="_blank" href="<%= @sonar_address %>/drilldown/measures/<%= @resource_id %>?metric=sqale_index">查看详情</a></span></div>
<div><span class="fontGrey3 mr30">质量问题</span>
<div><span class="fontGrey3 mr30 fl">质量问题</span>
<span class="fontBlue2 w70 pInline"><a class="fontBlue2 w70 pInline" target="_blank" href="<%= @sonar_address %>/component_issues?id=<%= @resource_id %>#resolved=false"><%= @sonar_issues["msr"][0]["frmt_val"] %></a></span><span class="fontGrey2">问题分类如下:</span></div>
<div class="ml90 mt15">
<div class="mb10"><span class="analysis-block-icon mr5"></span><span class="fontGrey3 mr45">阻断</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][1]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][1]["frmt_val"].to_i, 200) %>%;"></span></span></div>
<div class="mb10"><span class="analysis-serious-icon mr5"></span><span class="fontGrey3 mr45">严重</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][2]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][2]["frmt_val"].to_i, 200) %>%;"></span></span></div>
<div class="mb10"><span class="analysis-main-icon mr5"></span><span class="fontGrey3 mr45">主要</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][3]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][3]["frmt_val"].to_i, 200) %>%;"></span></span></div>
<div class="mb10"><span class="analysis-secondary-icon mr5"></span><span class="fontGrey3 mr45">次要</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][4]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][4]["frmt_val"].to_i, 200) %>%;"></span></span></div>
<div class="mb10"><span class="analysis-block-icon mr5"></span><span class="fontGrey3 mr45">阻断</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][1]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][1]["frmt_val"].to_i, 1000) %>%;"></span></span></div>
<div class="mb10"><span class="analysis-serious-icon mr5"></span><span class="fontGrey3 mr45">严重</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][2]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][2]["frmt_val"].to_i, 1000) %>%;"></span></span></div>
<div class="mb10"><span class="analysis-main-icon mr5"></span><span class="fontGrey3 mr45">主要</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][3]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][3]["frmt_val"].to_i, 1000) %>%;"></span></span></div>
<div class="mb10"><span class="analysis-secondary-icon mr5"></span><span class="fontGrey3 mr45">次要</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][4]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][4]["frmt_val"].to_i, 1000) %>%;"></span></span></div>
<div><span class="analysis-info-icon mr5"></span><span class="fontGrey3 mr45">信息</span><span class="fontBlue2 w70 pInline"><%= @sonar_issues["msr"][5]["frmt_val"] %></span><span class="quality-percentage"><span class="quality-percentage-rate" style="width:<%= statistics_result_percentage(@sonar_issues["msr"][5]["frmt_val"].to_i, 200) %>%;"></span></span></div>
</div>
</div>

View File

@ -0,0 +1 @@
<% %>

View File

@ -1,6 +1,6 @@
<div class="f16 fb fontBlue mb10">代码质量分析</div>
<div>
<%= 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 %>
<div class="ui form">
<div class="mb10" style="margin-right:13px;">
<textarea id="path_description" name="path" rows="8" placeholder="目录相对于根目录,用半角逗号隔开。如:src/main/java,libs,res/script" style="height: 87px; resize:vertical;" class="analysis-option-box"></textarea>

View File

@ -4,7 +4,9 @@
<a href="<%= @zip_path %>" class="btn_zipdown fr" onclick="">ZIP下载</a>
<%# 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" %>

View File

@ -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;}