aqulity analysis

This commit is contained in:
Your Name 2016-06-21 16:46:34 +08:00
parent d5631defb5
commit 26b7c3e70b
3 changed files with 35 additions and 85 deletions

View File

@ -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

View File

@ -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 %>
<textarea id="path_description" name="path" rows="8" placeholder="目录相当于根目录用半逗号隔开。如src/main/java,libs"></textarea>
<%= 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' %>

View File

@ -1,69 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.2.3">
<gitLabConnection>trustie-gitlab</gitLabConnection>
</com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
</properties>
<scm class="hudson.plugins.git.GitSCM" plugin="git@2.4.4">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>http://192.168.8.158:8889/root/badboy.git</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions/>
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers>
<com.dabsquared.gitlabjenkins.GitLabPushTrigger plugin="gitlab-plugin@1.2.3">
<spec></spec>
<triggerOnPush>true</triggerOnPush>
<triggerOnMergeRequest>true</triggerOnMergeRequest>
<triggerOpenMergeRequestOnPush>never</triggerOpenMergeRequestOnPush>
<ciSkip>true</ciSkip>
<setBuildDescription>true</setBuildDescription>
<addNoteOnMergeRequest>true</addNoteOnMergeRequest>
<addCiMessage>false</addCiMessage>
<addVoteOnMergeRequest>true</addVoteOnMergeRequest>
<branchFilterType>All</branchFilterType>
<includeBranchesSpec></includeBranchesSpec>
<excludeBranchesSpec></excludeBranchesSpec>
<targetBranchRegex></targetBranchRegex>
<acceptMergeRequestOnSuccess>false</acceptMergeRequestOnSuccess>
</com.dabsquared.gitlabjenkins.GitLabPushTrigger>
</triggers>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.plugins.sonar.SonarRunnerBuilder plugin="sonar@2.4.2">
<project></project>
<properties>
sonar.projectKey=my:project985
sonar.projectName=My project985
sonar.projectVersion=1.11
sonar.sources=src
sonar.language=java
sonar.sourceEncoding=utf-8
</properties>
<javaOpts></javaOpts>
<additionalArguments></additionalArguments>
<jdk>(Inherit From Job)</jdk>
<task></task>
</hudson.plugins.sonar.SonarRunnerBuilder>
</builders>
<publishers/>
<buildWrappers/>
</project>