diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 56fabe7eb..a25c00fd0 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -489,7 +489,7 @@ update def che_request begin - Trustie::Che.avd() + send_to_che rescue Exception => e raise(e.backtrace.join("\n")) end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index e8cbcadf7..80fa76217 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -17,6 +17,10 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require 'net/http' +require 'uri' + module RepositoriesHelper if Rails.env.development? ROOT_PATH="/private/tmp/" @@ -408,6 +412,124 @@ module RepositoriesHelper end max_space end + + def 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 + Rails.logger.info("#############info: #{send_che_uri.request_uri}") + 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 diff --git a/lib/trustie/che/che.rb b/lib/trustie/che/che.rb index 129aec8be..d3f4d7a10 100644 --- a/lib/trustie/che/che.rb +++ b/lib/trustie/che/che.rb @@ -5,14 +5,6 @@ require 'uri' module Trustie module Che - extend ActiveSupport::Concern - module ClassMethods - def avd - Rails.logger.info("####################che avd start") - end - end - - def self.che_send() begin Rails.logger.info("####################che send start")