add model error_list

This commit is contained in:
huang 2016-07-07 14:22:48 +08:00
parent 92b6171c36
commit b90c90bc60
9 changed files with 105 additions and 19 deletions

View File

@ -72,18 +72,28 @@ class QualityAnalysisController < ApplicationController
end
end
@console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')
# 获取sonar output结果
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}")
d = @client.job.delete("#{job_name}") if jenkins_job == '200' && code != '201'
logger.error("delete result ==> #{code}")
if @current_build_status == "success"
SonarError.create()
end
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}")
# 两种情况需要删除job
# 1/创建成功但是build失败则删除job
# 2/creat和build成功调用sonar启动失败则删除job
# 错误信息存储需存到Trustie数据库否则一旦job删除则无法获取这些信息
if jenkins_job == '200' && code != '201'
@client.job.delete("#{job_name}")
else
qa.update_attribute(:sonar_version, version) unless qa.blank?
if @current_build_status == "failure"
@sonar_error = SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => console_build)
@client.job.delete("#{job_name}")
elsif @current_build_status == "success"
if qa.blank?
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
qa.update_attribute(:sonar_version, version)
end
end
end
end
rescue => e
@ -93,11 +103,18 @@ class QualityAnalysisController < ApplicationController
if @current_build_status == "success"
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)}
elsif @current_build_status == "failure"
format.html
format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)}
end
end
end
def error_list
@error_list = SonarError.where(:jenkins_job_name => params[:job_name]).first
respond_to do |format|
format.html
end
end
# get language type
def swith_language_type language
if language == "c#"

View File

@ -0,0 +1,3 @@
class SonarError < ActiveRecord::Base
attr_accessible :jenkins_job_name, :output, :project_id
end

View File

@ -3,9 +3,9 @@
</div>
<div>
<div class="c_red">本次分析失败,原因如下:</div>
<% if @current_build_status == "failure" %>
<%= h @console_build.to_json %>
<% elsif @build_console_result == false %>
<% if @build_console_result == false %>
分析超时
<% else %>
<%= h @sonar_error.to_json %>
<% end %>
</div>

View File

@ -0,0 +1,11 @@
<div class="project_r_h">
<h2 class="project_h2" style="width:180px;">质量分析</h2>
</div>
<div>
<div class="c_red">本次分析失败,原因如下:</div>
<% if @build_console_result == false %>
分析超时
<% else %>
<%= h @error_list.to_json %>
<% end %>
</div>

View File

@ -797,6 +797,7 @@ RedmineApp::Application.routes.draw do
match 'update_jenkins_job'
match 'edit'
match 'create'
get 'error_list'
end
end
# resources :files, :only => [:index, :new, :create] do

View File

@ -0,0 +1,11 @@
class CreateSonarErrors < ActiveRecord::Migration
def change
create_table :sonar_errors do |t|
t.integer :project_id
t.string :jenkins_job_name
t.text :output
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160627090316) do
ActiveRecord::Schema.define(:version => 20160707031248) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -57,6 +57,18 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
t.integer "user_id", :null => false
end
create_table "apply_add_schools", :force => true do |t|
t.string "name"
t.string "province"
t.string "city"
t.string "address"
t.string "remarks"
t.integer "school_id"
t.integer "status", :default => 0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "apply_homeworks", :force => true do |t|
t.integer "status"
t.integer "user_id"
@ -1633,10 +1645,11 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
create_table "schools", :force => true do |t|
t.string "name"
t.string "province"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "logo_link"
t.string "pinyin"
t.integer "school_type", :default => 0
end
create_table "secdomains", :force => true do |t|
@ -1725,6 +1738,14 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
t.integer "project_id"
end
create_table "sonar_errors", :force => true do |t|
t.integer "project_id"
t.string "jenkins_job_name"
t.text "output"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "ssos", :force => true do |t|
t.integer "user_id"
t.string "openid"
@ -1849,8 +1870,18 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
t.string "title"
t.text "description"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "eng_name"
t.integer "syllabus_type"
t.integer "credit"
t.integer "hours"
t.integer "theory_hours"
t.integer "practice_hours"
t.string "applicable_major"
t.string "pre_course"
t.integer "visits", :default => 0
t.integer "des_status", :default => 0
end
add_index "syllabuses", ["user_id"], :name => "index_syllabuses_on_user_id"

View File

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :sonar_error do
project_id 1
jenkins_job_name "MyString"
output "MyText"
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe SonarError, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end