From b04e21f7d170540c1319af2f9d2f38fa86243481 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 27 Jul 2019 14:29:18 +0800 Subject: [PATCH] che --- app/controllers/repositories_controller.rb | 7 ++ app/views/repositories/che_request.js.erb | 0 app/views/repositories/show.html.erb | 6 +- config/routes.rb | 3 + lib/trustie/che/che.rb | 139 +++++++++++++++++++++ 5 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 app/views/repositories/che_request.js.erb create mode 100644 lib/trustie/che/che.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 42c4f7011..bc2eac706 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -563,6 +563,13 @@ update render :layout => 'base_projects' end + def che_request + begin + work_space_id = Trustie::Che.send() + rescue Exception => e + raise(e.message) + end + end def revisions @changeset_count = @repository.changesets.count diff --git a/app/views/repositories/che_request.js.erb b/app/views/repositories/che_request.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 500a947a2..8c4c03a6f 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -30,9 +30,9 @@ <%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fl ml10" %> <% end %> - <% if @project.id == 3993 %> - CHE环境 - <% end %> + <%# if @project.id == 3993 %> + CHE环境 + <%# end %>
diff --git a/config/routes.rb b/config/routes.rb index f206d5454..4c1fea2fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1092,6 +1092,9 @@ RedmineApp::Application.routes.draw do put 'to_gitlab' # get 'create', :via=>[:get, :post] end + collection do + get 'che_request' + end end match 'wiki/index', :via => :get diff --git a/lib/trustie/che/che.rb b/lib/trustie/che/che.rb new file mode 100644 index 000000000..0936d9e89 --- /dev/null +++ b/lib/trustie/che/che.rb @@ -0,0 +1,139 @@ +#coding=utf-8 + +require 'net/http' +require 'uri' + +module Trustie + module Che + def self.send(opt={}) + begin + o = send_to_che() + Rails.logger.info("#############send_che_return: #{o}") + # if o["code"] != 0 + # Rails.logger.error "发送che出错: #{o['msg']}" + # end + return o["id"] + rescue => e + Rails.logger.error "发送che出错: #{e}" + return false + end + end + + def self.send_to_che() + #发送地址 + send_che_uri = URI.parse('http://106.75.119.131:8080') + + params = { + "attributes": { + }, + "description": "string", + "environments": { + "default": { + "recipe": { + "type": "dockerimage", + "content": "eclipse/ubuntu_jdk8" + }, + "machines": { + "dev-machine": { + "env": {}, + "servers": { + "tomcat8-debug": { + "attributes": {}, + "protocol": "http", + "port": "8000" + }, + "codeserver": { + "attributes": {}, + "protocol": "http", + "port": "9876" + }, + "tomcat8": { + "attributes": {}, + "protocol": "http", + "port": "8080" + } + }, + "installers": [ + "org.eclipse.che.exec", + "org.eclipse.che.terminal", + "org.eclipse.che.ws-agent", + "org.eclipse.che.ls.java" + ], + "volumes": { + "m2": { + "path": "/home/user/.m2" + }, + "javadata": { + "path": "/home/user/jdtls/data" + } + }, + "attributes": { + "memoryLimitBytes": "2147483648" + } + } + } + } + }, + "projects": [ + { + "source": { + "location": "https://github.com/looly/hutool.git", + "type": "git", + "parameters": {} + }, + "links": [], + "problems": [], + "mixins": [ + "pullrequest" + ], + "name": "hutool", + "type": "blank", + "path": "/hutool", + "attributes": { + "contribute_to_branch": [ + "v4-master" + ] + } + } + ], + "commands": [ + { + "commandLine": "mvn clean install -f ${current.project.path}", + "name": "build", + "attributes": { + "goal": "Build", + "previewUrl": "" + }, + "type": "mvn" + }, + { + "commandLine": "echo \"hello\"", + "name": "newCustom", + "attributes": { + "goal": "Run", + "previewUrl": "" + }, + "type": "custom" + } + ], + "defaultEnv": "default", + "name": "create-from-api", + "links": [] + } + + http = Net::HTTP.new(send_che_uri.host, send_che_uri.port) + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.use_ssl = true + begin + request = Net::HTTP::Post.new(send_che_uri.request_uri) + request.set_form_data(params) + request['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8' + response = http.start { |http| http.request(request) } + ActiveSupport::JSON.decode(response.body) + rescue =>err + Rails.logger.error("#############sendYunpian_error: #{err.message}") + return nil + end + end + end +end \ No newline at end of file