You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trustieforge/app/controllers/quality_analyses_controller.rb

53 lines
1.8 KiB

class QualityAnalysesController < ApplicationController
before_filter :find_project_by_project_id#, :except => [:getattachtype]
layout "base_projects"
include ApplicationHelper
require 'jenkins_api_client'
require 'nokogiri'
def new
end
def create
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
sonar.sources=#{path}
sonar.language=#{language}
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 => '')
# 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
# replace config.xml of jenkins
@client = @client.job.create("tesc_create", File.read(File.join(Rails.root, 'tmp', 'config.xml')))
end
def index
end
# Find project of id params[:project_id]
def find_project_by_project_id
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
render_404
end
end