获取结果ajax加载中
This commit is contained in:
parent
db1ad932c6
commit
1fbb65b906
|
@ -5,6 +5,7 @@ class QualityAnalysisController < ApplicationController
|
|||
before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job]
|
||||
layout "base_projects"
|
||||
include ApplicationHelper
|
||||
include QualityAnalysisHelper
|
||||
require 'jenkins_api_client'
|
||||
require 'nokogiri'
|
||||
require 'json'
|
||||
|
@ -14,12 +15,14 @@ class QualityAnalysisController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
# params 说明:{identifier:版本库名}
|
||||
def create
|
||||
begin
|
||||
user_name = User.find(params[:user_id]).try(:login)
|
||||
identifier = params[:identifier]
|
||||
rep_id = params[:rep_id]
|
||||
# REDO
|
||||
|
||||
# job_name and sonar_name 前者为job名字,后者为jenkins配置名
|
||||
job_name = "#{user_name}-#{rep_id}"
|
||||
sonar_name = "#{user_name}:#{rep_id}"
|
||||
|
||||
|
@ -39,22 +42,40 @@ class QualityAnalysisController < ApplicationController
|
|||
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
|
||||
|
||||
# return '200' if successed
|
||||
# jenkins job创建
|
||||
jenkins_job = @client.job.create("#{job_name}", @doc.to_xml)
|
||||
logger.info("Jenkins status of create ==> #{jenkins_job}")
|
||||
|
||||
# replace gitlab hook
|
||||
# 将地址作为hook值添加到gitlab
|
||||
@g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}")
|
||||
# build job
|
||||
logger.error("Jenkins status of create ==> #{jenkins_job}")
|
||||
# return '201' if build successed
|
||||
# job创建完成后自动运行job,如果运行成功则返回‘200’
|
||||
code = @client.job.build("#{job_name}")
|
||||
logger.error("build result ==> #{code}")
|
||||
|
||||
# 判断调用sonar分析是否成功
|
||||
# 等待启动时间处理, 最长时间为30分钟
|
||||
for i in 0..60 do
|
||||
sleep(60)
|
||||
@current_build_status = @client.job.get_current_build_status("#{job_name}")
|
||||
if (@current_build_status != "not_run" || @current_build_status != "running")
|
||||
break
|
||||
if i == 60
|
||||
@build_console_result = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')
|
||||
logger.info("@current_build_status is ==> #{@current_build_status}")
|
||||
logger.info("@console_build is ==> #{@console_build}")
|
||||
|
||||
d = @client.job.delete("#{job_name}") if jenkins_job == '200' && code != '201'
|
||||
logger.error("delete result ==> #{code}")
|
||||
if qa.blank? && code == '201'
|
||||
|
@ -67,10 +88,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{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)}
|
||||
end
|
||||
end
|
||||
|
||||
# get language type
|
||||
|
@ -93,6 +114,7 @@ class QualityAnalysisController < ApplicationController
|
|||
@gitlab_default_branch = @g.project(@project.gpid).default_branch
|
||||
end
|
||||
|
||||
# 更新Jenkins job,主要包括相关配置文件参数的更新,Trustie平台数据的更新
|
||||
def update_jenkins_job
|
||||
begin
|
||||
rep_id = Repository.where(:project_id => @project.id).first.try(:id)
|
||||
|
@ -118,9 +140,12 @@ class QualityAnalysisController < ApplicationController
|
|||
@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
|
||||
# update成功则返回 ‘200’
|
||||
jenkins_job = @client.job.update("#{job_name}", @doc.to_xml)
|
||||
get_current_build_status = @client.job.get_current_build_status("Hjqreturn-1280")
|
||||
logger.error("Failed to update job: ==> #{jenkins_job}") unless jenkins_job == '200'
|
||||
|
||||
# 数据更新到Trustie数据库
|
||||
if jenkins_job == '200'
|
||||
logger.info("quality_ananlysis will be updated: ==> #{jenkins_job}")
|
||||
@quality_analysis.path = path
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
<script type="text/javascript">
|
||||
// $("#ajax-indicator span").text("载入中...");
|
||||
$("#ajax-indicator").show();
|
||||
</script>
|
||||
<div class="project_r_h">
|
||||
<h2 class="project_h2">分析结果</h2>
|
||||
</div>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<% if @complexity["msr"].count > 3 %>
|
||||
<%= render :partial => "hightchars" %>
|
||||
<div class="analysis-block mt10 mb40 f14">
|
||||
<div class="flex">
|
||||
<div class="flex mb10">
|
||||
<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>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
$("#ajax-indicator").hide();
|
||||
<% if @current_build_status == "success" %>
|
||||
<%= escape_javascript( render :partial => 'quality_analysis/show', :locals => {:branch => branch}) %>
|
||||
<% elsif @current_build_status == "failure" %>
|
||||
<%=h @console_build.html_safe %>
|
||||
<% elsif @current_build_status == "not_run" %>
|
||||
alert('任务启动失败');
|
||||
<% else %>
|
||||
alert('你已经创建类一个同名job');
|
||||
<% end %>
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
<% if @name_flag %>
|
||||
<%= render :partial => "result_list" %>
|
||||
<% else %>
|
||||
<%= render "show" %>
|
||||
<% if @build_console_result %>
|
||||
运行结果超时
|
||||
<% else %>
|
||||
<%= render :partial => "show", :locals => {:branch => params[:branch]} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
@ -15,7 +15,7 @@
|
|||
<%= select_tag :language, options_for_select(["java","python","ruby","c++","c#","c"]), :id => 'branch', :class => "analysis-option-box" %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="courseSendSubmit mr15"><a href="javascript:void(0);" class="sendSourceText" onclick="$('#quality_analyses_form').submit();hideModal()">提交</a></div>
|
||||
<div class="courseSendSubmit mr15"><a href="javascript:void(0);" class="sendSourceText" onclick="$('#ajax-indicator').text('正在分析中…………(大概需要30分钟,请耐心等待)').show();$('#quality_analyses_form').submit();hideModal()">提交</a></div>
|
||||
<div class="courseSendCancel"><a href="javascript:void(0);" class="sendSourceText" onclick="hideModal()">取消</a></div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -5,9 +5,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? && is_project_manager?(User.current.id, @project.id) %>
|
||||
<%# 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 %>
|
||||
<%# end %>
|
||||
<%# else %>
|
||||
<%#= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %>
|
||||
|
|
Loading…
Reference in New Issue