From e766adf087977677d67b22c7e998df97b58e4c23 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 12 Jul 2016 16:23:30 +0800 Subject: [PATCH] add delete to qa --- .../quality_analysis_controller.rb | 32 ++++++++++++++++--- .../quality_analysis/_result_list.html.erb | 13 ++++---- config/routes.rb | 3 +- lib/trustie/gitlab/helper.rb | 2 -- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index ae752f6b9..08ac4067f 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, :index] + before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job, :index, :delete] layout "base_projects" include ApplicationHelper include QualityAnalysisHelper @@ -84,7 +84,7 @@ class QualityAnalysisController < ApplicationController end # sonar 缓冲,取数据 - sleep(5) + sleep(3) # 获取sonar output结果 console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] @@ -152,11 +152,31 @@ class QualityAnalysisController < ApplicationController @gitlab_default_branch = @g.project(@project.gpid).default_branch end + # 删除的时候主要删除三方面数据:1/Trustie数据 2/jenkins数据 3/sonar数据 + # 如果只删除数据1,则新建的时候会有冲突 + def delete + begin + qa = QualityAnalysis.find(params[:id]) + rep_id = Repository.where(:project_id => @project.id, :identifier => qa.rep_identifier).first.try(:id) + job_name = "#{qa.author_login}-#{rep_id}" + logger.info("result: job_name ###################==>#{job_name}") + logger.info("result: @client.job ###################==>#{@client.job}") + + d_job = @client.job.delete(job_name) + logger.info("result: delete job ###################==>#{d_job}") + qa.delete + respond_to do |format| + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id)} + end + rescue Exception => e + puts e + end + end + # 更新Jenkins job,主要包括相关配置文件参数的更新,Trustie平台数据的更新 def update_jenkins_job begin rep_id = Repository.where(:project_id => @project.id).first.try(:id) - logger.error("#############################===>666") sonar_name = @quality_analysis.sonar_name job_name = "#{@quality_analysis.author_login}-#{rep_id}" version = @quality_analysis.sonar_version @@ -223,7 +243,7 @@ class QualityAnalysisController < ApplicationController if key == "sqale_index" value = com["frmt_val"] else - value = com["val"].to_i + value = com["val"] end @ha.store(key,value) end @@ -260,9 +280,11 @@ class QualityAnalysisController < ApplicationController def connect_jenkins @gitlab_address = Redmine::Configuration['gitlab_address'] @jenkins_address = Redmine::Configuration['jenkins_address'] + jenkins_username = Redmine::Configuration['jenkins_username'] + jenkins_password = Redmine::Configuration['jenkins_password'] # connect jenkins - @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123') + @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => jenkins_username, :password => jenkins_password) rescue => e logger.error("failed to connect Jenkins ==> #{e}") end diff --git a/app/views/quality_analysis/_result_list.html.erb b/app/views/quality_analysis/_result_list.html.erb index 3e2a7d373..d27ef6812 100644 --- a/app/views/quality_analysis/_result_list.html.erb +++ b/app/views/quality_analysis/_result_list.html.erb @@ -10,7 +10,7 @@
  • 分支
  • 语言
  • 路径
  • -
  • 编辑
  • +
  • @@ -21,16 +21,17 @@ - <% if User.current.try(:login) == qa.author_login %> + <% if User.current.try(:login) == qa.author_login || User.current.admin? || is_project_manager?(User.current.id, @project.id) %>
  • - <%=link_to "编辑", edit_project_quality_analysi_path(qa, :project_id => @project.id), :remote => true, :class => "fontBlue2" %> + <%=link_to "编辑", edit_project_quality_analysi_path(qa, :project_id => @project.id), :remote => true, :class => "fontBlue2" %> / + <%=link_to "删除", delete_project_quality_analysi_path(qa, :project_id => @project.id), :method => "delete", :confirm => "删除会一并删除分析结果,确定删除吗?", :class => "fontBlue2" %>
  • - <% else %> -
  • 编辑
  • - <% end %> + <% end %>
    <% end %> +<% else %> + <%#= 数据为空时候界面,待完善 %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index a570fef55..fbb69af62 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -790,12 +790,13 @@ RedmineApp::Application.routes.draw do end end - resources :quality_analysis, :only => [:index, :create, :edit, :update] do + resources :quality_analysis, :only => [:index, :create, :edit, :update, :delete] do collection do end member do match 'update_jenkins_job' match 'edit' + match 'delete' match 'create' get 'error_list' end diff --git a/lib/trustie/gitlab/helper.rb b/lib/trustie/gitlab/helper.rb index c9cbcee26..615bb6ac3 100644 --- a/lib/trustie/gitlab/helper.rb +++ b/lib/trustie/gitlab/helper.rb @@ -60,8 +60,6 @@ module Trustie def get_gitlab_role m case m.roles.first.position - when 1,2 - GUEST when 5 REPORTER when 4