diff --git a/app/controllers/quality_analyses_controller.rb b/app/controllers/quality_analyses_controller.rb
index 962ce2524..cba3cd537 100644
--- a/app/controllers/quality_analyses_controller.rb
+++ b/app/controllers/quality_analyses_controller.rb
@@ -1,46 +1,55 @@
class QualityAnalysesController < ApplicationController
before_filter :find_project_by_project_id#, :except => [:getattachtype]
+ before_filter :authorize
layout "base_projects"
include ApplicationHelper
require 'jenkins_api_client'
require 'nokogiri'
+ require 'json'
+ require 'open-uri'
def new
end
def create
+ @client = JenkinsApi::Client.new(:server_url => 'http://123.59.135.93:8890',
+ :username => "temp",
+ :password => '123123')
+ #@client.exists?(job_name)
+ @g = Gitlab.client
gitlab_address = Redmine::Configuration['gitlab_address']
user_name = User.find(params[:user_id]).try(:login)
branch = params[:branch].nil? ? "master" : params[:branch]
language = params[:language]
path = params[:path]
- properties = "sonar.projectKey=#{user_name}:#{@project.name}
- sonar.projectName=My #{@project.name}
- sonar.projectVersion=1.11
+ identifier = params[:identifier]
+ properties = "sonar.projectKey=#{user_name}:#{identifier}
+ sonar.projectName=#{user_name}:#{identifier}
+ sonar.projectVersion=1.0
sonar.sources=#{path}
- sonar.language=#{language}
+ sonar.language=#{language.downcase}
sonar.sourceEncoding=utf-8"
- git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+@repository.identifier+"."+"git"
- @client = JenkinsApi::Client.new(:server_url => 'http://123.59.135.93:8890',
- :username => user_name,
- :password => '')
+ git_url = gitlab_address.to_s+"/"+@project.owner.to_s+"/"+ identifier+"."+"git"
+
- # modify config
+ # # 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.git.BranchSpec/properties").content = properties
- sonar_properties = @doc.xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").text #sonar-properties
+ @doc.at_xpath("//hudson.plugins.sonar.SonarRunnerBuilder/properties").content = properties #sonar-properties
# replace config.xml of jenkins
- @client = @client.job.create("tesc_create", File.read(File.join(Rails.root, 'tmp', 'config.xml')))
-
-
+ @client = @client.job.create("#{user_name}_#{identifier}", @doc.to_xml)
+ # relace gitlab hook
+ # genkins address
+ @g.add_project_hook(@project.gpid,"http://123.59.135.93:8890/project/#{user_name}_#{identifier}")
end
def index
-
+ data = open('http://123.59.135.93:8891/api/resources/index?resource=my:project985&depth=-1&metrics=complexity,class_complexity,lines,comment_lines,blocker_violations').read
+ cc=JSON.parse(data)
+ p cc
end
# Find project of id params[:project_id]
@@ -49,4 +58,14 @@ class QualityAnalysesController < ApplicationController
rescue ActiveRecord::RecordNotFound
render_404
end
+
+ # Authorize the user for the requested action
+ def authorize(ctrl = params[:controller], action = params[:action], global = false)
+ unless @project.archived? && @project.gpid.nil?
+ true
+ else
+ render_403 :message => :notice_not_authorized_archived_project
+ end
+ end
+
end
diff --git a/app/views/repositories/_quality_analyses.html.erb b/app/views/repositories/_quality_analyses.html.erb
index 56951f3b6..7809c5e36 100644
--- a/app/views/repositories/_quality_analyses.html.erb
+++ b/app/views/repositories/_quality_analyses.html.erb
@@ -1,4 +1,4 @@
-<%= form_tag( url_for(:controller => 'quality_analyses', :action => 'create', :project_id => @project.id), :remote => true , :class => 'resourcesSearchloadBox mt10', :id => 'quality_analyses_form') do %>
+<%= form_tag( url_for(:controller => 'quality_analyses', :action => 'create', :project_id => @project.id, :identifier => @repository.identifier, :user_id => User.current.id), :remote => true , :class => 'resourcesSearchloadBox mt10', :id => 'quality_analyses_form') do %>
<%= select_tag :branch, options_for_select(["#{@gitlab_default_branch}"]+ @branch_names, @rev), :id => 'branch' %>
<%= select_tag :language, options_for_select(["Java","C","PHP", "Web"]), :id => 'branch' %>
diff --git a/config.xml b/config.xml
deleted file mode 100644
index 7e0029986..000000000
--- a/config.xml
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
-
-
- false
-
-
- trustie-gitlab
-
-
-
- 2
-
-
- http://192.168.8.158:8889/root/badboy.git
-
-
-
-
- */master
-
-
- false
-
-
-
- true
- false
- false
- false
-
-
-
- true
- true
- never
- true
- true
- true
- false
- true
- All
-
-
-
- false
-
-
- false
-
-
-
-
- sonar.projectKey=my:project985
- sonar.projectName=My project985
- sonar.projectVersion=1.11
- sonar.sources=src
- sonar.language=java
- sonar.sourceEncoding=utf-8
-
-
-
- (Inherit From Job)
-
-
-
-
-
-