add delete to qa

This commit is contained in:
huang 2016-07-12 16:23:30 +08:00
parent 8b5a2ac1cb
commit e766adf087
4 changed files with 36 additions and 14 deletions

View File

@ -2,7 +2,7 @@ class QualityAnalysisController < ApplicationController
before_filter :find_project_by_project_id#, :except => [:getattachtype] before_filter :find_project_by_project_id#, :except => [:getattachtype]
before_filter :find_quality_analysis, :only => [:edit, :update_jenkins_job] before_filter :find_quality_analysis, :only => [:edit, :update_jenkins_job]
before_filter :authorize 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" layout "base_projects"
include ApplicationHelper include ApplicationHelper
include QualityAnalysisHelper include QualityAnalysisHelper
@ -84,7 +84,7 @@ class QualityAnalysisController < ApplicationController
end end
# sonar 缓冲,取数据 # sonar 缓冲,取数据
sleep(5) sleep(3)
# 获取sonar output结果 # 获取sonar output结果
console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["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 @gitlab_default_branch = @g.project(@project.gpid).default_branch
end 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平台数据的更新 # 更新Jenkins job主要包括相关配置文件参数的更新Trustie平台数据的更新
def update_jenkins_job def update_jenkins_job
begin begin
rep_id = Repository.where(:project_id => @project.id).first.try(:id) rep_id = Repository.where(:project_id => @project.id).first.try(:id)
logger.error("#############################===>666")
sonar_name = @quality_analysis.sonar_name sonar_name = @quality_analysis.sonar_name
job_name = "#{@quality_analysis.author_login}-#{rep_id}" job_name = "#{@quality_analysis.author_login}-#{rep_id}"
version = @quality_analysis.sonar_version version = @quality_analysis.sonar_version
@ -223,7 +243,7 @@ class QualityAnalysisController < ApplicationController
if key == "sqale_index" if key == "sqale_index"
value = com["frmt_val"] value = com["frmt_val"]
else else
value = com["val"].to_i value = com["val"]
end end
@ha.store(key,value) @ha.store(key,value)
end end
@ -260,9 +280,11 @@ class QualityAnalysisController < ApplicationController
def connect_jenkins def connect_jenkins
@gitlab_address = Redmine::Configuration['gitlab_address'] @gitlab_address = Redmine::Configuration['gitlab_address']
@jenkins_address = Redmine::Configuration['jenkins_address'] @jenkins_address = Redmine::Configuration['jenkins_address']
jenkins_username = Redmine::Configuration['jenkins_username']
jenkins_password = Redmine::Configuration['jenkins_password']
# connect jenkins # 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 rescue => e
logger.error("failed to connect Jenkins ==> #{e}") logger.error("failed to connect Jenkins ==> #{e}")
end end

View File

@ -10,7 +10,7 @@
<li class="analysis-result-version fl fontBlue2" >分支</li> <li class="analysis-result-version fl fontBlue2" >分支</li>
<li class="analysis-result-loc fl fontBlue2" >语言</li> <li class="analysis-result-loc fl fontBlue2" >语言</li>
<li class="analysis-result-debt fl fontBlue2" >路径</li> <li class="analysis-result-debt fl fontBlue2" >路径</li>
<li class="analysis-result-time fl fontBlue2" >编辑</li> <li class="analysis-result-time fl fontBlue2" ></li>
<!--<li class="analysis-result-time fl fontBlue2" >bianji</li>--> <!--<li class="analysis-result-time fl fontBlue2" >bianji</li>-->
<div class="cl"></div> <div class="cl"></div>
</ul> </ul>
@ -21,16 +21,17 @@
<li class="analysis-result-version fl fontBlue2 hidden" title="分支名"><%= qa.branch %></li> <li class="analysis-result-version fl fontBlue2 hidden" title="分支名"><%= qa.branch %></li>
<li class="analysis-result-loc fl fontBlue2 hidden" title="语言"><%= qa.language %></li> <li class="analysis-result-loc fl fontBlue2 hidden" title="语言"><%= qa.language %></li>
<li class="analysis-result-debt fl fontBlue2 hidden" title="路径"><%= qa.path %></li> <li class="analysis-result-debt fl fontBlue2 hidden" title="路径"><%= qa.path %></li>
<% 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) %>
<li class="analysis-result-time fl" title="编辑"> <li class="analysis-result-time fl" title="编辑">
<%=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" %><span style="color: #888"> / </span>
<%=link_to "删除", delete_project_quality_analysi_path(qa, :project_id => @project.id), :method => "delete", :confirm => "删除会一并删除分析结果,确定删除吗?", :class => "fontBlue2" %>
</li> </li>
<% else %> <% end %>
<li class="analysis-result-time fl" style="color: #888" title="编辑">编辑</li>
<% end %>
<div class="cl"></div> <div class="cl"></div>
</ul> </ul>
<% end %> <% end %>
<% else %>
<%#= 数据为空时候界面,待完善 %>
<% end %> <% end %>

View File

@ -790,12 +790,13 @@ RedmineApp::Application.routes.draw do
end end
end end
resources :quality_analysis, :only => [:index, :create, :edit, :update] do resources :quality_analysis, :only => [:index, :create, :edit, :update, :delete] do
collection do collection do
end end
member do member do
match 'update_jenkins_job' match 'update_jenkins_job'
match 'edit' match 'edit'
match 'delete'
match 'create' match 'create'
get 'error_list' get 'error_list'
end end

View File

@ -60,8 +60,6 @@ module Trustie
def get_gitlab_role m def get_gitlab_role m
case m.roles.first.position case m.roles.first.position
when 1,2
GUEST
when 5 when 5
REPORTER REPORTER
when 4 when 4