From b68e227531bd4adcfeb834ea08dea3cb06276b83 Mon Sep 17 00:00:00 2001
From: yuanke <249218296@qq.com>
Date: Wed, 22 Jun 2016 14:04:47 +0800
Subject: [PATCH 01/64] =?UTF-8?q?=E6=B2=A1=E6=BF=80=E6=B4=BB=E7=9A=84?=
=?UTF-8?q?=E5=B8=90=E5=8F=B7=E7=95=8C=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/account_controller.rb | 15 +-
app/controllers/users_controller.rb | 6 +
app/controllers/words_controller.rb | 20 +++
app/views/account/email_activation.html.erb | 52 ++++++
config/routes.rb | 5 +-
public/stylesheets/header.css | 176 ++++++++++++++++++++
6 files changed, 270 insertions(+), 4 deletions(-)
create mode 100644 app/views/account/email_activation.html.erb
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 33d988e35..8bf40d472 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -239,14 +239,21 @@ class AccountController < ApplicationController
end
def resendmail
+ status = 1
user = User.find(params[:user]) if params[:user]
token = Token.new(:user => user, :action => "register")
if token.save
Mailer.run.register(token)
-
else
yield if block_given?
+ status = 0
end
+ render :json => status
+ end
+
+ def email_activation
+
+
end
private
@@ -264,6 +271,7 @@ class AccountController < ApplicationController
if user.nil?
invalid_credentials
elsif user.status == 2
+ @user = user
invalid_credentials_new
elsif user.new_record?
onthefly_creation_failed(user, {:login => user.login, :auth_source_id => user.auth_source_id })
@@ -375,8 +383,9 @@ class AccountController < ApplicationController
def invalid_credentials_new
logger.warn "Failed login for '#{params[:username]}' from #{request.remote_ip} at #{Time.now.utc}"
- flash[:error] = l(:notice_account_invalid_creditentials_new)
- render signin_path(:login=>true)
+ # flash[:error] = l(:notice_account_invalid_creditentials_new)
+ # render signin_path(:login=>true)
+ render :action => 'email_activation'
end
# Register a user for email activation.
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 87c7d8f54..ed8a9fa36 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1239,6 +1239,12 @@ class UsersController < ApplicationController
render :layout=>'new_base_user'
end
+ #给某人留言
+ def feedBackTo
+
+
+ end
+
def user_comments
end
diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb
index 22b7f1f52..3b540f0d0 100644
--- a/app/controllers/words_controller.rb
+++ b/app/controllers/words_controller.rb
@@ -337,6 +337,26 @@ class WordsController < ApplicationController
UserExtensions.introduction(user, message)
redirect_to user_url(user.id)
end
+
+ #邮箱激活问题留言 留言成功给出提示框
+ def leave_email_activation_message
+ status = 1 #成功
+ me = User.find(params[:user])
+ if me
+ @user = User.find(params[:id])
+ if params[:text].size>0 && @user
+ # @user.add_jour(me, params[:text])
+ #私信
+ message = "【未收到激活邮件的用户反馈,用户邮箱:"+me.mail+"】
"+params[:text]
+ @user.journals_for_messages << JournalsForMessage.new(:user_id => me.id, :notes => message, :reply_id => 0, :status => true, :is_readed => false, :private => 1)
+ else
+ status = 0
+ end
+ render :json => status
+ else
+ render_403
+ end
+ end
private
diff --git a/app/views/account/email_activation.html.erb b/app/views/account/email_activation.html.erb
new file mode 100644
index 000000000..abd010a96
--- /dev/null
+++ b/app/views/account/email_activation.html.erb
@@ -0,0 +1,52 @@
+
+
+
您的账号尚未激活,请先进入您的注册邮箱,激活您的账号。
+
+ <%#= link_to l(:label_mail_resend), { :controller => 'account', :action => 'resendmail',:user => @user}, :class=>"email_verify_btn mt30 ml30", :remote => true, :method => 'get' %>
+
+ 如果您尚未收到激活邮件,请按照以下步骤操作:
+ - 检查邮箱的“订阅邮件”、“垃圾邮件”,可能会发现激活邮件。
+ - 如果激活邮件已无效,请点击重新发送激活邮件按钮。
+ - 如果您无法收到激活邮件,请您直接给我们管理员留言:
+
+
+
+
+
diff --git a/config/routes.rb b/config/routes.rb
index ec8fa2337..6e720ffba 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -489,10 +489,13 @@ RedmineApp::Application.routes.draw do
match 'account/activate', :via => :get
match 'account/valid_ajax', :via => :get
match 'account/email_valid', :to => 'account#email_valid', :via => :get
- match 'account/resendmail', :to => 'account#resendmail', :via=> :get
+ match 'account/resendmail', :to => 'account#resendmail', :via=> :get, :as => 'resendmail'
match 'projects/:id/wiki', :to => 'wikis#edit', :via => :post
match 'projects/:id/wiki/destroy', :to => 'wikis#destroy', :via => [:get, :post]
+ #激活邮箱反馈问题
+ match 'users/:id/leave_email_activation_message', :to => 'words#leave_email_activation_message', :via => :get, :as => "leave_email_activation_message"
+
# boards
match 'boards/:board_id/topics/new', :to => 'messages#new', :via => [:get, :post], :as => 'new_board_message'
match 'boards/:id/join_to_org_subfields', :to => 'boards#join_to_org_subfields'
diff --git a/public/stylesheets/header.css b/public/stylesheets/header.css
index 767d76cb2..5700d0b00 100644
--- a/public/stylesheets/header.css
+++ b/public/stylesheets/header.css
@@ -117,3 +117,179 @@ a.f_grey:hover {color:#000000 !important;}
#loginInButton {height:54px; padding-left:10px; padding-right:10px; text-align:center; line-height:54px; vertical-align:middle; color:#ffffff; font-size:16px;}
#loginSignButton:hover {background-color:#297fb8;}
#loginInButton:hover {background-color:#297fb8;}
+
+/* 邮箱验证 */
+.email_verify body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{ margin:0; padding:0;}
+.mt30{ margin-top:30px;}
+.ml30{ margin-left:30px;}
+.new_content{
+ width:1000px;
+ margin:10px auto;
+ padding:30px 0;
+ background-color:#fff;
+}
+.email_verify{
+ width:720px;
+ margin:0px auto;
+}
+.email_verify_prompt{
+ border:2px solid #dd0000;
+ background:#ffe3e3 url(../images/icons_prompt.png) 25px 10px no-repeat;;
+ height:35px;
+ line-height:35px;
+ padding-left:45px;
+ color:#8b0000;
+ font-size:14px;
+}
+.email_verify_btn{
+ border-style:none;
+ height:35px;
+ padding:0 15px;
+ line-height:35px;
+ color:#fff;
+ background:#3a95d7;
+ text-align:center;
+ -webkit-border-radius:5px;
+ -moz-border-radius:5px;
+ -o-border-radius:5px;
+ border-radius:5px;
+ font-size:14px;
+}
+.email_verify_btn:hover{
+ background:#017bd3;
+}
+.email_sub_btn{
+ border-style:none;
+ height:30px;
+ padding:0 25px;
+ line-height:30px;
+ color:#fff;
+ background:#3a95d7;
+ text-align:center;
+ -webkit-border-radius:5px;
+ -moz-border-radius:5px;
+ -o-border-radius:5px;
+ border-radius:5px;
+ font-size:14px;
+}
+.email_sub_btn:hover{
+ background:#017bd3;
+}
+.email_prompt_p{
+ font-size:14px;
+ color:#000;
+ margin-bottom:10px;
+}
+.email_prompt_txt{ width:480px;}
+.email_prompt_txt li{
+ margin-left:15px;
+ list-style-type: disc;
+ color:#777;
+ line-height:1.9;
+ font-size:14px;
+}
+.email_prompt_mes{
+ border:1px solid #ccc;
+ -webkit-border-radius:5px;
+ -moz-border-radius:5px;
+ -o-border-radius:5px;
+ border-radius:5px;
+ width:468px;
+ height:60px;
+ background:#fff;
+ padding:5px;
+ margin-bottom: 5px;
+}
+.email_tanbox{
+ border:2px solid #3a95d7;
+ background:#fff;
+ width:480px;
+
+}
+.email_tancon{
+ width:420px;
+ margin:0 auto;
+ text-align:center;
+ padding:20px 30px;
+ background:#fff;
+}
+.email_tan_title{
+ font-size:18px;
+ color:#3a95d7;
+ font-weight:normal;
+ margin-bottom:5px;
+}
+.email_tan_p{
+ font-size:14px;
+ color:#4c4c4c;
+
+}
+.email_verify_p{
+ font-size:14px;
+ color:#3a95d7;
+}
+
+/***** Ajax indicator ******/
+/*-------resendmail---------*/
+#ajax-indicator {
+ position: absolute; /* fixed not supported by IE */
+ background-color:#eee;
+ border: 1px solid #bbb;
+ top:35%;
+ left:40%;
+ width:20%;
+ font-weight:bold;
+ text-align:center;
+ padding:0.6em;
+ z-index:100000;
+ opacity: 0.5;
+}
+
+html>body #ajax-indicator { position: fixed; }
+
+#ajax-indicator span {
+ background-position: 0% 40%;
+ background-repeat: no-repeat;
+ background-image: url(../images/loading.gif);
+ padding-left: 26px;
+ vertical-align: bottom;
+}
+
+div.modal {
+ border-radius: 5px;
+ background: #fff;
+ z-index: 50;
+ padding: 4px;
+}
+.ui-widget-content {
+ border: 1px solid #ddd;
+ color: #333;
+}
+.ui-widget {
+ font-family: Verdana, sans-serif;
+ font-size: 1.1em;
+}
+.ui-dialog .ui-dialog-content {
+ position: relative;
+ border: 0;
+ padding: .5em 1em;
+ background: none;
+ overflow: auto;
+ zoom: 1;
+}
+.ui-widget-overlay {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+}
+.ui-widget-overlay {
+ background: #666 url(http://forge.trustie.net/stylesheets/jquery/images/xui-bg_diagonals-thick_20_666666_40x40.png.pagespeed.ic.9mfuw_R0z1.png) 50% 50% repeat;
+ opacity: .5;
+ filter: Alpha(Opacity=50);
+}
+.resourceUploadPopup {width:400px; height:auto; border:3px solid #269ac9 !important; padding-left:16px; padding-bottom:16px; background-color:#ffffff; position:absolute; top:50%; left:50%; margin-left:-200px; z-index:1000;}
+a.Blue-btn{ display:block; margin-right:15px;width:65px; height:22px; background-color:#ffffff; line-height:24px; vertical-align:middle; text-align:center; border:1px solid #3598db; color:#3598db; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
+a:hover.Blue-btn{ background:#3598db; color:#fff;}
+/***** end Ajax indicator ******/
\ No newline at end of file
From 9461c41fa72bd1aadd835cc47903cab985bad9f2 Mon Sep 17 00:00:00 2001
From: yuanke <249218296@qq.com>
Date: Wed, 22 Jun 2016 14:14:36 +0800
Subject: [PATCH 02/64] =?UTF-8?q?=E6=BF=80=E6=B4=BB=E7=95=99=E8=A8=80?=
=?UTF-8?q?=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/words_controller.rb | 3 ++-
app/views/account/email_activation.html.erb | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb
index 3b540f0d0..1bbbb1190 100644
--- a/app/controllers/words_controller.rb
+++ b/app/controllers/words_controller.rb
@@ -343,7 +343,8 @@ class WordsController < ApplicationController
status = 1 #成功
me = User.find(params[:user])
if me
- @user = User.find(params[:id])
+ #课程使者id=1
+ @user = User.find(1)
if params[:text].size>0 && @user
# @user.add_jour(me, params[:text])
#私信
diff --git a/app/views/account/email_activation.html.erb b/app/views/account/email_activation.html.erb
index abd010a96..d625e7fc9 100644
--- a/app/views/account/email_activation.html.erb
+++ b/app/views/account/email_activation.html.erb
@@ -10,7 +10,7 @@
如果您无法收到激活邮件,请您直接给我们管理员留言:
@@ -29,7 +29,7 @@
}
);
}
- function leave_email_activation_message(url,user,id)
+ function leave_email_activation_message(url,user)
{
if ($(".email_prompt_mes").val().length == 0){
//弹框请他输入文字
@@ -39,7 +39,7 @@
}
$.get(
url,
- {user:user,id: 1,text:$(".email_prompt_mes").val() },
+ {user:user,text:$(".email_prompt_mes").val() },
function (data) {
console.log("2222222");
console.log(data);
From e818b5fb073f4c1ef02b9d321e8a05dee8aa8d3b Mon Sep 17 00:00:00 2001
From: yuanke <249218296@qq.com>
Date: Fri, 24 Jun 2016 11:22:43 +0800
Subject: [PATCH 03/64] =?UTF-8?q?=E6=97=A7=E7=9A=84=E6=B3=A8=E5=86=8C?=
=?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8E=BB=E6=8E=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/account/register.html.erb | 127 ----------------------------
config/routes.rb | 2 +-
2 files changed, 1 insertion(+), 128 deletions(-)
delete mode 100644 app/views/account/register.html.erb
diff --git a/app/views/account/register.html.erb b/app/views/account/register.html.erb
deleted file mode 100644
index 0bebfdf5f..000000000
--- a/app/views/account/register.html.erb
+++ /dev/null
@@ -1,127 +0,0 @@
-<% @nav_dispaly_home_path_label = 1
- @nav_dispaly_main_course_label = 1
- @nav_dispaly_main_project_label = 1
- @nav_dispaly_main_contest_label = 1 %>
-<% @nav_dispaly_forum_label = 1%>
-
-
-
-
-
-
-<%= l(:label_register) %> <%= link_to l(:label_login_with_open_id_option), signin_url if Setting.openid? %>
-
-<%= labelled_form_for @user, :url => register_path do |f| %>
- <%= error_messages_for 'user' %>
-
-
- <% if @user.auth_source_id.nil? %>
-
<%= f.text_field :login, :size => 25, :required => true %>
- <%= l(:label_max_number) %>
-
-
<%= f.password_field :password, :size => 25, :required => true %>
- <%= l(:text_caracters_minimum, :count => Setting.password_min_length) %>
-
-
<%= f.password_field :password_confirmation, :size => 25, :required => true %>
- <% end %>
-
-
- <%= f.text_field :mail,:size => 25, :required => true %>
-
-
-
-
- <%= "#{l(:label_mail_attention)} " %>
- <%= "#{l(:label_mail_attention1)} " %>
-
-
-
-
-
-
-
-
-
-
-
- <%= submit_tag l(:button_submit) %> |
-
-
-
-<% end %>
-<% if Setting.openid? %>
- <%= f.text_field :identity_url %>
-<% end %>
-<% @user.custom_field_values.select { |v| v.editable? || v.required? }.each do |value| %>
- <%= custom_field_tag_with_label :user, value %>
-<% end %>
-
-<% password_min_length = Setting.password_min_length %>
-
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 6e720ffba..8d822aafc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -484,7 +484,7 @@ RedmineApp::Application.routes.draw do
match 'logout', :to => 'account#logout', :as => 'signout', :via => [:get, :post]
match 'agreement',:to => 'account#agreement',:as => 'agreement',:via=>[:get]
match 'about_us',:to=>'account#about_us',:as=>'about_us',:via=>[:get]
- match 'account/register', :via => [:get, :post], :as => 'register'
+ match 'account/register',:to=>'account#register', :via => [:get, :post], :as => 'register'
match 'account/lost_password', :via => [:get, :post], :as => 'lost_password'
match 'account/activate', :via => :get
match 'account/valid_ajax', :via => :get
From 4a4c613c55c626c8a1cd4d3312674563f44a48af Mon Sep 17 00:00:00 2001
From: huang
Date: Fri, 24 Jun 2016 19:38:08 +0800
Subject: [PATCH 04/64] =?UTF-8?q?utf-8=E7=BC=96=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/helpers/quality_analysis_helper.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb
index e13882f6f..9c6c07109 100644
--- a/app/helpers/quality_analysis_helper.rb
+++ b/app/helpers/quality_analysis_helper.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
module QualityAnalysisHelper
def sqale_rating_status val
From 69f7dab04d68142a53c8953d43f77e21f09d6a0b Mon Sep 17 00:00:00 2001
From: Your Name
Date: Fri, 24 Jun 2016 21:33:35 +0800
Subject: [PATCH 05/64] some modified
---
app/controllers/quality_analysis_controller.rb | 11 +++++++----
app/controllers/repositories_controller.rb | 7 +++++++
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb
index 83e5960b9..6453ef5a8 100644
--- a/app/controllers/quality_analysis_controller.rb
+++ b/app/controllers/quality_analysis_controller.rb
@@ -21,11 +21,11 @@ class QualityAnalysisController < ApplicationController
#@client.exists?(job_name)
@g = Gitlab.client
user_name = User.find(params[:user_id]).try(:login)
- branch = params[:branch].nil? ? "master" : params[:branch]
+ branch = params[:branch].blank? ? "master" : params[:branch]
language = params[:language]
path = params[:path]
identifier = params[:identifier]
- qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
+ qa = QualityAnalysis.where(:project_id => @project.id).first
version = qa.nil? ? 1 : qa.sonar_version + 1
properties = "sonar.projectKey=#{user_name}:#{identifier}
sonar.projectName=#{user_name}:#{identifier}
@@ -42,16 +42,19 @@ class QualityAnalysisController < ApplicationController
@doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties #sonar-properties
#
# replace config.xml of jenkins
- @client = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
+ @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
# relace gitlab hook
# genkins address
@g.add_project_hook(@project.gpid, jenkins_address + "/project/#{user_name}_#{identifier}")
- if qa.nil?
+ 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)
else
qa.update_attribute(:sonar_version, version)
end
+
+ # scan
+ @client.job.build("#{user_name}_#{identifier}")
end
def index
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index cbb5b2f69..7c3acb2cc 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -20,6 +20,8 @@ require 'SVG/Graph/BarHorizontal'
require 'digest/sha1'
require 'redmine/scm/adapters/abstract_adapter'
require 'tempfile'
+require 'json'
+require 'open-uri'
class ChangesetNotFound < Exception; end
class InvalidRevisionParam < Exception; end
@@ -358,6 +360,11 @@ update
end
def show
+ # sonar_address = Redmine::Configuration['sonar_address']
+ # projects_date = open(sonar_address + "/api/projects/index").read
+ # arr = JSON.parse(projects_date).map {|m| m["nm"]}
+ # arr.map
+
## TODO: the below will move to filter, done.
if !User.current.member_of?(@project) && @project.hidden_repo
render_403
From e5b93ac7ed7c8cdad1e02d7a726f2e1730b712b8 Mon Sep 17 00:00:00 2001
From: Your Name
Date: Mon, 27 Jun 2016 18:13:46 +0800
Subject: [PATCH 06/64] modified main method
---
.../quality_analysis_controller.rb | 109 +++++++++---------
app/helpers/quality_analysis_helper.rb | 38 +++---
app/views/quality_analysis/_show.html.erb | 20 ++--
app/views/repositories/show.html.erb | 8 +-
...0624103411_add_name_to_quality_analyses.rb | 5 -
...0316_add_sonar_name_to_quality_analyses.rb | 5 +
db/schema.rb | 3 +-
7 files changed, 93 insertions(+), 95 deletions(-)
delete mode 100644 db/migrate/20160624103411_add_name_to_quality_analyses.rb
create mode 100644 db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb
diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb
index 6453ef5a8..9a5745dc1 100644
--- a/app/controllers/quality_analysis_controller.rb
+++ b/app/controllers/quality_analysis_controller.rb
@@ -1,6 +1,7 @@
class QualityAnalysisController < ApplicationController
before_filter :find_project_by_project_id#, :except => [:getattachtype]
before_filter :authorize
+ before_filter :connect_jenkins, :only => [:create]
layout "base_projects"
include ApplicationHelper
require 'jenkins_api_client'
@@ -13,74 +14,61 @@ class QualityAnalysisController < ApplicationController
end
def create
- gitlab_address = Redmine::Configuration['gitlab_address']
- jenkins_address = Redmine::Configuration['jenkins_address']
- @client = JenkinsApi::Client.new(:server_url => jenkins_address,
- :username => "temp",
- :password => '123123')
- #@client.exists?(job_name)
- @g = Gitlab.client
user_name = User.find(params[:user_id]).try(:login)
- branch = params[:branch].blank? ? "master" : params[:branch]
- language = params[:language]
- path = params[:path]
identifier = params[:identifier]
- qa = QualityAnalysis.where(:project_id => @project.id).first
- version = qa.nil? ? 1 : qa.sonar_version + 1
- properties = "sonar.projectKey=#{user_name}:#{identifier}
+ job_name = "#{user_name}:#{identifier}"
+ # Checks if the given job exists in Jenkins.
+ unless @client.job.exists?(job_name)
+ @g = Gitlab.client
+ branch = params[:branch].blank? ? "master" : params[:branch]
+ language = params[:language]
+ path = params[:path]
+ qa = QualityAnalysis.where(:project_id => @project.id).first
+ version = qa.nil? ? 1 : qa.sonar_version + 1
+ properties = "sonar.projectKey=#{user_name}:#{identifier}
sonar.projectName=#{user_name}:#{identifier}
sonar.projectVersion=#{version}
sonar.sources=#{path}
sonar.language=#{language.downcase}
sonar.sourceEncoding=utf-8"
- git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier + "."+"git"
-
- # # # modify config
- @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
- #
- # replace config.xml of jenkins
- @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
- # relace gitlab hook
- # genkins address
- @g.add_project_hook(@project.gpid, jenkins_address + "/project/#{user_name}_#{identifier}")
- 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)
-
- else
- qa.update_attribute(:sonar_version, version)
+ 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
+ @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
+ # relace gitlab hook
+ @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}")
+ # build job
+ opts = {'build_start_timeout' => 30, 'cancel_on_build_start_timeout' => true}
+ code = @client.job.build("#{user_name}_#{identifier}", opts)
+ # sucessed will return "201"
+ raise "Unable to build job: #{user_name}_#{identifier}" unless code == '201'
+ if qa.blank? && code == '201'
+ QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier,
+ :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => job_name)
+ else
+ qa.update_attribute(:sonar_version, version)
+ end
end
-
- # scan
- @client.job.build("#{user_name}_#{identifier}")
end
def index
@sonar_address = Redmine::Configuration['sonar_address']
- # if params[:resource_id].nil?
- # @name_flag = true
- # @quality_analyses = QualityAnalysis.where(:project_id => @project.id)
- # # @quality_analyses.map {|qa| qa.}
- # # if @quality_analyses.count > 0
- # # @quality_analyses.each do |qa|
- # # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
- # #
- # # end
- # # end
- # # projects_date = open(@sonar_address + "/api/projects/index").read
- # # arr = JSON.parse(projects_date).map {|m| m["nm"]}
- # # arr.map
- # else
- qa = QualityAnalysis.where(:project_id => @project.id).first
- @resource_id = qa.author_login+":"+qa.rep_identifier
- @name_flag = false
- 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
- @sonar_issues = JSON.parse(issue_date).first
- # end
+ projects_date = open(@sonar_address + "/api/projects/index").read
+ arr = JSON.parse(projects_date).map {|m| m["nm"]} # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
+ if params[:resource_id].nil?
+ @quality_analyses = QualityAnalysis.where("sonar_name in #{arr}")
+ else
+ qa = QualityAnalysis.where(:project_id => @project.id).first
+ @resource_id = qa.author_login+":"+qa.rep_identifier
+ @name_flag = false
+ 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
+ # @sonar_issues = JSON.parse(issue_date).first
+ end
end
# Find project of id params[:project_id]
@@ -99,4 +87,13 @@ class QualityAnalysisController < ApplicationController
end
end
+ def connect_jenkins
+ @gitlab_address = Redmine::Configuration['gitlab_address']
+ @jenkins_address = Redmine::Configuration['jenkins_address']
+ # connect jenkins
+ @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123')
+ rescue
+ logger.error("failed to connect Jenkins")
+ end
+
end
diff --git a/app/helpers/quality_analysis_helper.rb b/app/helpers/quality_analysis_helper.rb
index 9c6c07109..d2948e02b 100644
--- a/app/helpers/quality_analysis_helper.rb
+++ b/app/helpers/quality_analysis_helper.rb
@@ -3,19 +3,19 @@ module QualityAnalysisHelper
def sqale_rating_status val
arr = []
- if val.to_i > 0 && val.to_i < 5
+ if val > 0 && val < 5
arr << "很好"
arr << "b_green2"
- elsif val.to_i > 5 && val.to_i < 10
+ elsif val. > 5 && val < 10
arr << "较好"
arr << "b_slow_yellow"
- elsif val.to_i > 10 && val.to_i < 20
+ elsif val > 10 && val < 20
arr << "中等"
arr << "b_yellow"
- elsif val.to_i > 20 && val.to_i < 50
+ elsif val > 20 && val < 50
arr << "较差"
arr << "b_slow_red"
- elsif val.to_i > 20
+ elsif val > 20
arr << "很差"
arr << "b_red"
end
@@ -23,13 +23,13 @@ module QualityAnalysisHelper
def complexity_status val
arr = []
- if val.to_i < 10
+ if val < 10
arr << "良好"
arr << "b_green2"
- elsif val.to_i > 10 && val.to_i < 15
+ elsif val > 10 && val < 15
arr << "较高"
arr << "b_yellow"
- elsif val.to_i > 15
+ elsif val > 15
arr << "很高"
arr << "b_red"
end
@@ -37,13 +37,13 @@ module QualityAnalysisHelper
def duplicated_lines_density_status val
arr = []
- if val.to_i < 30
+ if val < 30
arr << "良好"
arr << "b_green2"
- elsif val.to_i > 30 && val.to_i < 50
+ elsif val > 30 && val < 50
arr << "较高"
arr << "b_yellow"
- elsif val.to_i > 50
+ elsif val > 50
arr << "很高"
arr << "b_red"
end
@@ -51,28 +51,28 @@ module QualityAnalysisHelper
def comment_lines_density_status val
arr = []
- if val.to_i < 20
+ if val < 20
arr << "较低"
arr << "b_yellow"
- elsif val.to_i > 20 && val.to_i < 50
+ elsif val > 20 && val < 50
arr << "正常"
arr << "b_green2"
- elsif val.to_i > 50
+ elsif val > 50
arr << "较高"
arr << "b_red"
end
end
def score_sqale_rating val
- if val.to_i > 0 && val.to_i < 5
+ if val > 0 && val < 5
"5"
- elsif val.to_i > 5 && val.to_i < 10
+ elsif val > 5 && val < 10
"4"
- elsif val.to_i > 10 && val.to_i < 20
+ elsif val > 10 && val < 20
"3"
- elsif val.to_i > 20 && val.to_i < 50
+ elsif val > 20 && val < 50
"2"
- elsif val.to_i > 20
+ elsif val > 20
"1"
end
end
diff --git a/app/views/quality_analysis/_show.html.erb b/app/views/quality_analysis/_show.html.erb
index 8f1cb8443..864512bdd 100644
--- a/app/views/quality_analysis/_show.html.erb
+++ b/app/views/quality_analysis/_show.html.erb
@@ -1,8 +1,8 @@
<%= javascript_include_tag 'highcharts','highcharts-more' %>
- <%= render :partial => "hightchars" %>
-
-
质量分析
-
+<%= render :partial => "hightchars" %>
+
+
质量分析
+
当前分支:<%= params[:branch] %>
项目代码质量分析报告
@@ -12,28 +12,28 @@
质量等级
-
<%= @complexity["msr"][9]["frmt_val"] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
+
<%= @complexity["msr"][9]["frmt_val"] %> borderRadius"><%= sqale_rating_status(@complexity["msr"][9]["val"].to_i)[0] %>
复杂度
-
<%= @complexity["msr"][6]["val"] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"])[0] %>
+
<%= @complexity["msr"][6]["val"] %> borderRadius"><%= complexity_status(@complexity["msr"][6]["val"].to_i)[0] %>
代码重复度
-
<%= @complexity["msr"][7]["frmt_val"] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"])[0] %>
+
<%= @complexity["msr"][7]["frmt_val"] %> borderRadius"><%= duplicated_lines_density_status(@complexity["msr"][7]["val"].to_i)[0] %>
注释率
-
<%= @complexity["msr"][5]["frmt_val"] %>
+
<%= @complexity["msr"][5]["frmt_val"] %>
- 质量等级<%= score_sqale_rating(@complexity["msr"][9]["val"]) %>/5分可定性评价为:质量<%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
+ 质量等级<%= score_sqale_rating(@complexity["msr"][9]["val"].to_i) %>/5分可定性评价为:质量<%= sqale_rating_status(@complexity["msr"][9]["val"])[0] %>
技术债务<%= @complexity["msr"][8]["frmt_val"] %>查看详情
质量问题
@@ -46,7 +46,7 @@
信息<%= @sonar_issues["msr"][5]["frmt_val"] %>%;">
- 代码规模可定性评价为:<%= lines_scale(@complexity["msr"][0]["frmt_val"]) %>
+ 代码规模可定性评价为:<%= lines_scale(@complexity["msr"][0]["frmt_val"].to_i) %>
代码行数
diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb
index 124e3ef4d..5f4288262 100644
--- a/app/views/repositories/show.html.erb
+++ b/app/views/repositories/show.html.erb
@@ -2,13 +2,13 @@
<%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>
ZIP下载
- <% if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %>
+ <%# if is_project_manager?(User.current, @project.id) && QualityAnalysis.where(:project_id => @project.id).first.nil? %>
<%# if User.current.member_of?(@project) %>
<%= link_to "质量分析", quality_analysis_path(:id => @project.id), :remote => true, :class => "btn_zipdown fr" %>
<%# end %>
- <% else %>
- <%= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %>
- <% end %>
+ <%# else %>
+ <%#= link_to "质量分析", project_quality_analysis_path(:project_id => @project.id, :resource_id => @proje), :class => "btn_zipdown fr" %>
+ <%# end %>
<% if @entries.nil? %>
diff --git a/db/migrate/20160624103411_add_name_to_quality_analyses.rb b/db/migrate/20160624103411_add_name_to_quality_analyses.rb
deleted file mode 100644
index bf61fd5ac..000000000
--- a/db/migrate/20160624103411_add_name_to_quality_analyses.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class AddNameToQualityAnalyses < ActiveRecord::Migration
- def change
- add_column :quality_analyses, :language, :string
- end
-end
diff --git a/db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb b/db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb
new file mode 100644
index 000000000..c69b5c909
--- /dev/null
+++ b/db/migrate/20160627090316_add_sonar_name_to_quality_analyses.rb
@@ -0,0 +1,5 @@
+class AddSonarNameToQualityAnalyses < ActiveRecord::Migration
+ def change
+ add_column :quality_analyses, :sonar_name, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ee2da177b..16f39f6a1 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20160624055127) do
+ActiveRecord::Schema.define(:version => 20160627090316) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -1844,6 +1844,7 @@ ActiveRecord::Schema.define(:version => 20160624055127) do
t.string "path"
t.string "branch"
t.string "language"
+ t.string "sonar_name"
end
create_table "queries", :force => true do |t|
From f930bbddad7eb88c1884878dade392e132627342 Mon Sep 17 00:00:00 2001
From: Your Name
Date: Tue, 28 Jun 2016 09:45:45 +0800
Subject: [PATCH 07/64] modified create
---
.../quality_analysis_controller.rb | 77 +++++++++++--------
1 file changed, 44 insertions(+), 33 deletions(-)
diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb
index 9a5745dc1..bff369eaf 100644
--- a/app/controllers/quality_analysis_controller.rb
+++ b/app/controllers/quality_analysis_controller.rb
@@ -14,43 +14,53 @@ class QualityAnalysisController < ApplicationController
end
def create
- user_name = User.find(params[:user_id]).try(:login)
- identifier = params[:identifier]
- job_name = "#{user_name}:#{identifier}"
- # Checks if the given job exists in Jenkins.
- unless @client.job.exists?(job_name)
- @g = Gitlab.client
- branch = params[:branch].blank? ? "master" : params[:branch]
- language = params[:language]
- path = params[:path]
- qa = QualityAnalysis.where(:project_id => @project.id).first
- version = qa.nil? ? 1 : qa.sonar_version + 1
- properties = "sonar.projectKey=#{user_name}:#{identifier}
+ begin
+ user_name = User.find(params[:user_id]).try(:login)
+ identifier = params[:identifier]
+ # REDO
+ job_name = "#{user_name}:#{identifier}"
+
+ # Checks if the given job exists in Jenkins.
+ unless @client.job.exists?(job_name)
+ @g = Gitlab.client
+ branch = params[:branch].blank? ? "master" : params[:branch]
+ language = params[:language]
+ path = params[:path]
+ qa = QualityAnalysis.where(:project_id => @project.id).first
+ version = qa.nil? ? 1 : qa.sonar_version + 1
+ properties = "sonar.projectKey=#{user_name}:#{identifier}
sonar.projectName=#{user_name}:#{identifier}
sonar.projectVersion=#{version}
sonar.sources=#{path}
sonar.language=#{language.downcase}
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
- @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
- # relace gitlab hook
- @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}")
- # build job
- opts = {'build_start_timeout' => 30, 'cancel_on_build_start_timeout' => true}
- code = @client.job.build("#{user_name}_#{identifier}", opts)
- # sucessed will return "201"
- raise "Unable to build job: #{user_name}_#{identifier}" unless code == '201'
- if qa.blank? && code == '201'
- QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier,
- :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => job_name)
- else
- qa.update_attribute(:sonar_version, version)
+ 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 = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
+
+ # replace gitlab hook
+ @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}")
+ # build job
+ logger.error("Test#{jenkins_job}")
+
+ # return '201' if successed
+ code = @client.job.build("#{user_name}_#{identifier}")
+ 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 => job_name)
+ else
+ qa.update_attribute(:sonar_version, version)
+ end
end
+ rescue => e
+ puts e
end
end
@@ -90,10 +100,11 @@ class QualityAnalysisController < ApplicationController
def connect_jenkins
@gitlab_address = Redmine::Configuration['gitlab_address']
@jenkins_address = Redmine::Configuration['jenkins_address']
+
# connect jenkins
@client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123')
- rescue
- logger.error("failed to connect Jenkins")
+ rescue => e
+ logger.error("failed to connect Jenkins ==> #{e}")
end
end
From dd6b19a8b543234d1f9d2fa879a583bf3d1f4cb7 Mon Sep 17 00:00:00 2001
From: Your Name
Date: Tue, 28 Jun 2016 14:48:09 +0800
Subject: [PATCH 08/64] some status of sonar
---
.../quality_analysis_controller.rb | 66 +++++++++++--------
app/models/quality_analysis.rb | 2 +-
.../quality_analysis/_result_list.html.erb | 6 +-
.../repositories/_quality_analysis.html.erb | 2 +-
4 files changed, 45 insertions(+), 31 deletions(-)
diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb
index bff369eaf..7de4bedab 100644
--- a/app/controllers/quality_analysis_controller.rb
+++ b/app/controllers/quality_analysis_controller.rb
@@ -17,19 +17,20 @@ class QualityAnalysisController < ApplicationController
begin
user_name = User.find(params[:user_id]).try(:login)
identifier = params[:identifier]
+ rep_id = params[:rep_id]
# REDO
- job_name = "#{user_name}:#{identifier}"
+ job_name = "#{user_name}-#{rep_id}"
# Checks if the given job exists in Jenkins.
unless @client.job.exists?(job_name)
@g = Gitlab.client
- branch = params[:branch].blank? ? "master" : params[:branch]
+ branch = params[:branch]
language = params[:language]
path = params[:path]
- qa = QualityAnalysis.where(:project_id => @project.id).first
+ qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
version = qa.nil? ? 1 : qa.sonar_version + 1
- properties = "sonar.projectKey=#{user_name}:#{identifier}
- sonar.projectName=#{user_name}:#{identifier}
+ properties = "sonar.projectKey=#{user_name}:#{rep_id}
+ sonar.projectName=#{user_name}:#{rep_id}
sonar.projectVersion=#{version}
sonar.sources=#{path}
sonar.language=#{language.downcase}
@@ -43,18 +44,20 @@ class QualityAnalysisController < ApplicationController
@doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties # sonar-properties
# return '200' if successed
- jenkins_job = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
+ jenkins_job = @client.job.create("#{job_name}", @doc.to_xml)
# replace gitlab hook
- @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{user_name}_#{identifier}")
+ @g.add_project_hook(@project.gpid, @jenkins_address + "/project/#{job_name}")
# build job
- logger.error("Test#{jenkins_job}")
-
- # return '201' if successed
- code = @client.job.build("#{user_name}_#{identifier}")
- if qa.blank?
+ logger.error("Jenkins status of create ==> #{jenkins_job}")
+ # return '201' if build successed
+ code = @client.job.build("#{job_name}")
+ logger.error("build result ==> #{code}")
+ d = @client.delete("#{job_name}") if jenkins_job == '200' && code != '201'
+ logger.error("delete result ==> #{code}")
+ if qa.blank? && code == '201'
QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier,
- :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => job_name)
+ :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}")
else
qa.update_attribute(:sonar_version, version)
end
@@ -62,23 +65,34 @@ 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 => "#{user_name}:#{rep_id}")}
+ format.js
+ end
end
+ # resource_id: login + @repository.id
def index
- @sonar_address = Redmine::Configuration['sonar_address']
- projects_date = open(@sonar_address + "/api/projects/index").read
- arr = JSON.parse(projects_date).map {|m| m["nm"]} # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
- if params[:resource_id].nil?
- @quality_analyses = QualityAnalysis.where("sonar_name in #{arr}")
- else
- qa = QualityAnalysis.where(:project_id => @project.id).first
- @resource_id = qa.author_login+":"+qa.rep_identifier
- @name_flag = false
- 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
- # @sonar_issues = JSON.parse(issue_date).first
+ begin
+ @resource_id = params[:resource_id]
+ @sonar_address = Redmine::Configuration['sonar_address']
+ # projects_date = open(@sonar_address + "/api/projects/index").read
+ # @arr = JSON.parse(projects_date).map {|m| m["nm"]} # ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
+ if params[:resource_id].nil?
+ @name_flag = true
+ # @quality_analyses = QualityAnalysis.where("sonar_name in (#{arr.empty? ? '0': arr.join(',')})")
+ @quality_analyses = QualityAnalysis.where(:project_id => @project.id)
+ else
+ qa = QualityAnalysis.where(:project_id => @project.id).first
+ 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
+ @sonar_issues = JSON.parse(issue_date).first
+ end
+ rescue => e
+ puts e
end
+
end
# Find project of id params[:project_id]
diff --git a/app/models/quality_analysis.rb b/app/models/quality_analysis.rb
index 229be9826..8b8034c65 100644
--- a/app/models/quality_analysis.rb
+++ b/app/models/quality_analysis.rb
@@ -1,5 +1,5 @@
class QualityAnalysis < ActiveRecord::Base
- attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version, :branch, :path, :rep_identifier, :language
+ attr_accessible :author_login, :project_id, :rep_identifier, :sonar_version, :branch, :path, :rep_identifier, :language, :sonar_name
def user_rep_name
self.author_login+":"+self.rep_identifier
diff --git a/app/views/quality_analysis/_result_list.html.erb b/app/views/quality_analysis/_result_list.html.erb
index 507ded0fe..845049cea 100644
--- a/app/views/quality_analysis/_result_list.html.erb
+++ b/app/views/quality_analysis/_result_list.html.erb
@@ -6,17 +6,17 @@
版本
分支
语言
- 时间
+ lujing
<% if @quality_analyses.count >0 %>
<% @quality_analyses.each do |qa| %>
- - <%=link_to "#{qa.author_login}:#{qa.rep_identifier}", project_quality_analysis_path(:resource_id => qa.author_login+":"+qa.rep_identifier, :branch => qa.branch.nil? ? "master" : qa.branch), :class => "analysis-result-name fl fontBlue2" %>
+ - <%=link_to "#{qa.author_login}:#{qa.rep_identifier}", project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => qa.branch.nil? ? "master" : qa.branch), :class => "analysis-result-name fl fontBlue2" %>
- 1.0
- <%= qa.branch %>
- <%= qa.language %>
- - <%= format_time(qa.created_at) %>
+ - <%= qa.path %>
<% end %>
diff --git a/app/views/repositories/_quality_analysis.html.erb b/app/views/repositories/_quality_analysis.html.erb
index f9726fb9b..0b3f38ee3 100644
--- a/app/views/repositories/_quality_analysis.html.erb
+++ b/app/views/repositories/_quality_analysis.html.erb
@@ -1,6 +1,6 @@
代码质量分析
- <%= form_tag( url_for(:controller => 'quality_analysis', :action => 'create', :project_id => @project.id, :user_id => User.current.id, :identifier => @repository.identifier), :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), :remote => true, :id => 'quality_analyses_form') do %>