Class: Gct::Command::Robot::Finish

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Gct::Command::Robot

#robot_send

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) ⇒ Finish

Returns a new instance of Finish.



23
24
25
26
27
28
29
30
31
32
# File 'lib/gct/command/robot/finish.rb', line 23

def initialize(argv)
  @project_name = ENV['CI_PROJECT_NAME']
  @user_name = ENV['GITLAB_USER_NAME']
  @tag = ENV['CI_COMMIT_REF_NAME'] 
  @build_status = argv.shift_argument
  @commit_sha = ENV['CI_COMMIT_SHA'] 
  @ci_url = ENV['CI_PIPELINE_URL']
  @test = argv.flag?('test', false)
  super
end

Class Method Details

.optionsObject



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

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

Instance Method Details

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gct/command/robot/finish.rb', line 34

def run
  puts @build_status.class
  puts "build_status == #{@build_status}"
  if @build_status.eql?("false")
    build_text = "<font color=\"comment\">CI运行失败</font>,请相关人员注意"
  elsif @build_status.eql?("true")
    build_text = "<font color=\"info\">CI运行成功</font>"
  end
  ci_text = "[点击跳转](#{@ci_url})" 

  content = "**#{@project_name}   #{build_text}**\n\n\n>触发人:#{@user_name}\n\n>tag:#{@tag}\n\n>commitid:#{@commit_sha}\n\n>流水线地址:#{ci_text}"
  robot_send(content)
end