Class: Gct::Command::Robot

Inherits:
Gct::Command show all
Defined in:
lib/gct/command/robot.rb,
lib/gct/command/robot/start.rb,
lib/gct/command/robot/finish.rb,
lib/gct/command/robot/podfile.rb

Direct Known Subclasses

Finish, Podfile, Start

Defined Under Namespace

Classes: Finish, Podfile, Start

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Gct::Command

#auto_add_tag, #check_branch_can_be_update, #config_gitlab, #current_branch, #file_contents, #get_project, #gitlab_error, run

Constructor Details

#initialize(argv) ⇒ Robot

Returns a new instance of Robot.



22
23
24
25
# File 'lib/gct/command/robot.rb', line 22

def initialize(argv)
  @test = argv.flag?('test', false)
  super
end

Class Method Details

.optionsObject



16
17
18
19
20
# File 'lib/gct/command/robot.rb', line 16

def self.options
  [
    ['--test', '测试机器人,测试webhook'],
  ].concat(super)
end

Instance Method Details

#robot_send(content) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gct/command/robot.rb', line 27

def robot_send(content)
  if @test
    webhook = FileBase.get_config("gitlab-robot-webhook-test")
  else
    webhook = FileBase.get_config("gitlab-robot-webhook")
  end
  raise "请先设置webhook --> gct config set gitlab-robot-webhook WEBHOOK_URL" if webhook.nil? || webhook.empty? 
  url = URI(webhook)
    
  http = Net::HTTP.new(url.host, url.port)
  if url.scheme == "https"
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE 
  end
  
  data = {
    "msgtype": "markdown",
    "markdown": {
      "content": "#{content}"
    }
  }.to_json
  
  header = {'content-type':'application/json'}
  response = http.post(url, data, header)
end