diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index 75499c985..2c55f780c 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -2,7 +2,7 @@ class QualityAnalysisController < ApplicationController before_filter :find_project_by_project_id#, :except => [:getattachtype] before_filter :find_quality_analysis, :only => [:edit, :update_jenkins_job] before_filter :authorize - before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job] + before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job, :index] layout "base_projects" include ApplicationHelper include QualityAnalysisHelper @@ -78,7 +78,7 @@ class QualityAnalysisController < ApplicationController d = @client.job.delete("#{job_name}") if jenkins_job == '200' && code != '201' logger.error("delete result ==> #{code}") - if qa.blank? && code == '201' + if qa.blank? && @current_build_status == "success" QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier, :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}") else @@ -89,7 +89,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 => sonar_name, :branch => branch)} + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)} # format.js{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch)} end end @@ -167,6 +167,7 @@ class QualityAnalysisController < ApplicationController begin @resource_id = params[:resource_id] @sonar_address = Redmine::Configuration['sonar_address'] + @jenkins_address = Redmine::Configuration['jenkins_address'] if params[:resource_id].nil? @name_flag = true projects_date = open(@sonar_address + "/api/projects/index").read @@ -174,6 +175,10 @@ class QualityAnalysisController < ApplicationController @quality_analyses = QualityAnalysis.where(:project_id => @project.id).select{|qa| arr.include?(qa.sonar_name)} else + if params[:current_build_status] == "failure" + job_name = params[:job_name] + @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text') + end 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/views/quality_analysis/_console_output.html.erb b/app/views/quality_analysis/_console_output.html.erb new file mode 100644 index 000000000..45115b9fe --- /dev/null +++ b/app/views/quality_analysis/_console_output.html.erb @@ -0,0 +1,8 @@ +<%= javascript_include_tag 'highcharts','highcharts-more' %> +
+

质量分析

+
+

+ <%= h @console_build.to_json.html_safe %> +

+ diff --git a/app/views/quality_analysis/create.html.erb b/app/views/quality_analysis/create.html.erb new file mode 100644 index 000000000..e7c81f662 --- /dev/null +++ b/app/views/quality_analysis/create.html.erb @@ -0,0 +1,9 @@ +<% if @current_build_status == "success" %> + <%= render :partial => "show", :locals => {:branch => params[:branch]} %> +<% else %> + <% if @build_console_result %> + 运行结果超时 + <% else %> + <%= render :partial => "console_output" %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/quality_analysis/index.html.erb b/app/views/quality_analysis/index.html.erb index ead8aae48..19b5c5eea 100644 --- a/app/views/quality_analysis/index.html.erb +++ b/app/views/quality_analysis/index.html.erb @@ -1,10 +1,14 @@ <% if @name_flag %> <%= render :partial => "result_list" %> <% else %> - <% if @build_console_result %> - 运行结果超时 - <% else %> + <% if params[:current_build_status].nil? || params[:current_build_status] == "success" %> <%= render :partial => "show", :locals => {:branch => params[:branch]} %> + <% else %> + <% if params[:build_console_result] %> + 运行结果超时 + <% else %> + <%= render :partial => "console_output" %> + <% end %> <% end %> <% end %> diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 0a9b49470..8164a103f 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? && 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) && @project.is_public? %> <%= 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" %> diff --git a/config/routes.rb b/config/routes.rb index 075aff6e1..dd6df94ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -792,6 +792,7 @@ RedmineApp::Application.routes.draw do member do match 'update_jenkins_job' match 'edit' + match 'create' end end # resources :files, :only => [:index, :new, :create] do