项目添加语言配置/Jenkins分析和Merge Request关联
This commit is contained in:
parent
26177f7154
commit
ca8952581a
|
@ -743,6 +743,7 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@project.safe_attributes = params[:project]
|
@project.safe_attributes = params[:project]
|
||||||
|
@project.language = params[:language].try(:strip)
|
||||||
@project.organization_id = params[:organization_id]
|
@project.organization_id = params[:organization_id]
|
||||||
params[:project][:is_public] == "on" ? @project.is_public = 1 : @project.is_public = 0
|
params[:project][:is_public] == "on" ? @project.is_public = 1 : @project.is_public = 0
|
||||||
params[:project][:hidden_repo] == "on" ? @project.hidden_repo = 1 : @project.hidden_repo = 0
|
params[:project][:hidden_repo] == "on" ? @project.hidden_repo = 1 : @project.hidden_repo = 0
|
||||||
|
|
|
@ -103,16 +103,15 @@ class PullRequestsController < ApplicationController
|
||||||
job_name = "pr-" + "#{Time.now.to_i}"
|
job_name = "pr-" + "#{Time.now.to_i}"
|
||||||
# 如果分支有改动
|
# 如果分支有改动
|
||||||
if compare_pull_request(source_branch, target_project_id, target_branch)
|
if compare_pull_request(source_branch, target_project_id, target_branch)
|
||||||
if @project.try(:id).to_i == 4665
|
logger.info("2222222222222222222222")
|
||||||
logger.info("2222222222222222222222")
|
# 自动生成配置Jenkinsjob,在merge事件的时候触发jenkins、sonar
|
||||||
# 自动生成配置Jenkinsjob,在merge事件的时候触发jenkins、sonar
|
# merge发送的时候还没有接收,所以分析对象应该源项目
|
||||||
# merge发送的时候还没有接收,所以分析对象应该源项目
|
language = swith_language_type(@project.language)
|
||||||
exec_jenkins(source_branch, @project.gpid, git_url, job_name)
|
exec_jenkins(source_branch, @project.gpid, git_url, job_name, language)
|
||||||
logger.info("33333333333333333333")
|
logger.info("33333333333333333333")
|
||||||
qa = QualityAnalysis.create(:project_id => @project.id, :author_login => User.current.login, :sonar_version => 1, :path => "./",
|
qa = QualityAnalysis.create(:project_id => @project.id, :author_login => User.current.login, :sonar_version => 1, :path => "./",
|
||||||
:branch => source_branch, :language => "java", :sonar_name => "#{job_name}")
|
:branch => source_branch, :language => "java", :sonar_name => "#{job_name}")
|
||||||
logger.info("4444444444444444444444444")
|
logger.info("4444444444444444444444444")
|
||||||
end
|
|
||||||
|
|
||||||
# 如果传送了目标项目ID即向fork源项目发送请求
|
# 如果传送了目标项目ID即向fork源项目发送请求
|
||||||
# if params[:forked_project_id] && params[:source_project] == "forked_project_name"
|
# if params[:forked_project_id] && params[:source_project] == "forked_project_name"
|
||||||
|
@ -149,8 +148,8 @@ class PullRequestsController < ApplicationController
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec_jenkins branch, gpid, git_url, job_name
|
def exec_jenkins branch, gpid, git_url, job_name, language
|
||||||
# 发送PR之前先发送创建Jenkins Job、gitlab hook,调用sonar自动分析代码
|
# 发送PR之前先发送创建Jenkins Job、gitlab hook,调用sonar自动分析代码
|
||||||
logger.info("5555555555555555#{branch}, git_url#{git_url}, job_name #{job_name}")
|
logger.info("5555555555555555#{branch}, git_url#{git_url}, job_name #{job_name}")
|
||||||
|
|
||||||
@jenkins_address = Redmine::Configuration['jenkins_address']
|
@jenkins_address = Redmine::Configuration['jenkins_address']
|
||||||
|
@ -159,7 +158,7 @@ class PullRequestsController < ApplicationController
|
||||||
# connect jenkins
|
# connect jenkins
|
||||||
@client_jenkins = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => jenkins_username, :password => jenkins_password)
|
@client_jenkins = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => jenkins_username, :password => jenkins_password)
|
||||||
@g = Gitlab.client
|
@g = Gitlab.client
|
||||||
language = "java"
|
language = language.present? ? language : "java"
|
||||||
path = "./"
|
path = "./"
|
||||||
# qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
|
# qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
|
||||||
version = 1
|
version = 1
|
||||||
|
|
|
@ -144,19 +144,6 @@ class QualityAnalysisController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# get language type
|
|
||||||
def swith_language_type language
|
|
||||||
if language == "c#"
|
|
||||||
"cs"
|
|
||||||
elsif language == "python"
|
|
||||||
"py"
|
|
||||||
elsif language == "c"
|
|
||||||
"c++"
|
|
||||||
else
|
|
||||||
language
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@g = Gitlab.client
|
@g = Gitlab.client
|
||||||
gitlab_branches = @g.branches(@project.gpid)
|
gitlab_branches = @g.branches(@project.gpid)
|
||||||
|
|
|
@ -37,6 +37,19 @@ module ApplicationHelper
|
||||||
# super
|
# super
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
# get language type
|
||||||
|
def swith_language_type language
|
||||||
|
if language == "c#"
|
||||||
|
"cs"
|
||||||
|
elsif language == "python"
|
||||||
|
"py"
|
||||||
|
elsif language == "c"
|
||||||
|
"c++"
|
||||||
|
else
|
||||||
|
language
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# 读取excel数据
|
# 读取excel数据
|
||||||
def readData(xlsx)
|
def readData(xlsx)
|
||||||
doc = SimpleXlsxReader.open(xlsx)
|
doc = SimpleXlsxReader.open(xlsx)
|
||||||
|
|
|
@ -32,11 +32,15 @@
|
||||||
<!--<textarea class="fl ml5 w690" style="height:192px; padding-top:5px;" id="project_description" name="project[description]" rows="8" placeholder="项目描述作为项目的简介,将始终显示在动态页的顶部 最多3000个汉字(或6000个英文字符)"><%= @project.description%></textarea>-->
|
<!--<textarea class="fl ml5 w690" style="height:192px; padding-top:5px;" id="project_description" name="project[description]" rows="8" placeholder="项目描述作为项目的简介,将始终显示在动态页的顶部 最多3000个汉字(或6000个英文字符)"><%= @project.description%></textarea>-->
|
||||||
</li>
|
</li>
|
||||||
<% if !@project.gpid.nil? && !@gitlab_branches.blank? %>
|
<% if !@project.gpid.nil? && !@gitlab_branches.blank? %>
|
||||||
<li class="clear">
|
<li class="clear mb10">
|
||||||
<label class="fl"> 默认分支 :</label>
|
<label class="fl"> 默认分支 :</label>
|
||||||
<%= select_tag :branch, options_for_select(["#{@gitlab_default_branch}"]+ @branch_names, @rev), :id => 'branch', :class => "ml5", :style => "height: 28px;" %>
|
<%= select_tag :branch, options_for_select(["#{@gitlab_default_branch}"]+ @branch_names, @rev), :id => 'branch', :class => "ml5", :style => "height: 28px;" %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<li class="clear">
|
||||||
|
<label class="fl"> 语言 :</label>
|
||||||
|
<%= select_tag :language, options_for_select(["","java","python","c#"], :selected => "#{@project.language}"), :id => 'language', :class => "ml5", :style => "height: 28px;" %>
|
||||||
|
</li>
|
||||||
<li class="clear">
|
<li class="clear">
|
||||||
<label class="fl">公开 :</label>
|
<label class="fl">公开 :</label>
|
||||||
<input class="fl mt8 ml5" id="project_is_public" name="project[is_public]" type="checkbox" <%= @project.is_public ? "checked" : ""%>>
|
<input class="fl mt8 ml5" id="project_is_public" name="project[is_public]" type="checkbox" <%= @project.is_public ? "checked" : ""%>>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddLanguageToProjects < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :projects, :language, :string
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue