ADD build socks shop request

This commit is contained in:
Jasder 2019-10-24 23:47:07 +08:00
parent 9a88a47f4e
commit b57f5d5d3b
3 changed files with 38 additions and 6 deletions

View File

@ -37,13 +37,13 @@ class RepositoriesController < ApplicationController
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,
:to_gitlab, :forked, :export_rep_static, :training_project_extend, :che_request]
:to_gitlab, :forked, :export_rep_static, :training_project_extend, :che_request, :build_socks_shop]
# 连接gitlab
# before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff]
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
# before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff]
before_filter :authorize_visible , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :che_request]
before_filter :authorize_visible , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :che_request, :build_socks_shop]
# 版本库新增权限
# before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ]
accept_rss_auth :revisions
@ -75,6 +75,37 @@ class RepositoriesController < ApplicationController
end
def build_socks_shop
begin
# r = RestClient::Request.execute(method: :get, url: 'http://106.75.6.173:8080/job/socks-shop/build?token=socks-shop&j_username=jenkins&j_password=12', max_redirects: 0)
# logger.info "socks shop request success-===========> #{r.response}"
RestClient.get('http://106.75.6.173:8080/job/socks-shop/build?token=socks-shop&j_username=jenkins&j_password=12') { |response, request, result|
case response.code
when 200, 201
logger.info "socks shop request success-===========> #{response}"
render :json => {:result => "succuss", :message => "ok"}
when 423
logger.info "socks shop request failed---------> #{response}"
render :json => {:result => "fail", :message => "SomeCustomExceptionIfYouWant"}
raise SomeCustomExceptionIfYouWant
else
logger.info "return else ======> #{response}"
render :json => {:result => "fail", :message => "...."}
end
}
rescue RestClient::ExceptionWithResponse => err
render :json => {:result => "failed", :message => "fail"}
logger.info "socks shop request failed---------> #{err}"
rescue RestClient::Unauthorized, RestClient::Forbidden => err
render :json => {:result => "failed", :message => "Access denied"}
logger.info "Access denied======> #{err.response}"
rescue RestClient::ImATeapot => err
render :json => {:result => "failed", :message => "The server is a teapot! # RFC 2324"}
logger.info "The server is a teapot! # RFC 2324 ==> #{err.response}"
return err.response
end
end
def export_rep_static
# 管理员界面导出所有项目
@project = Project.find(params[:id])

View File

@ -25,9 +25,9 @@
<% else %>
<%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fl ml10" %>
<% end %>
<% if @project.id == 5787 %>
<% if true %>
<%= link_to '云端编程', "http://106.75.119.131:8080/dashboard/#/ide/che/trustie_che_demo", :class => "btn_zipdown fl ml10"%>
<%= link_to '云端部署', "javascript:void(0)", :class => "btn_zipdown fl ml10", :onclick => "deploy()"%>
<%= link_to '云端部署', "javascript:void(0)", :class => "btn_zipdown fl ml10", :onclick => "deploy()", :remote => true%>
<% end %>
<% end %>
<% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %>
@ -82,8 +82,8 @@
function deploy(){
if (i == 0) {
$.ajax({
url: 'http://106.75.6.173:8080/job/socks-shop/build?token=socks-shop&j_username=jenkins&j_password=123',
type:'get',
url: "<%= build_socks_shop_project_repositories_path(@project) %>",
type:'post',
contentType: "application/json; charset=utf-8",
success: function(){
console.log('request success!')

View File

@ -1086,6 +1086,7 @@ RedmineApp::Application.routes.draw do
member do
match 'committers', :via => [:get, :post]
end
match 'build_socks_shop', :via => :post, :on => :collection
end
resources :repositories, :except => [:index, :show] do
member do