Class: KCommercial::KCPipeline::Publisher
- Inherits:
-
Object
- Object
- KCommercial::KCPipeline::Publisher
- Defined in:
- lib/KCommercialPipeline/core/component_publisher.rb
Instance Attribute Summary collapse
-
#auto_version ⇒ Object
Returns the value of attribute auto_version.
-
#component ⇒ Object
Returns the value of attribute component.
-
#email ⇒ Object
Returns the value of attribute email.
-
#influence ⇒ Object
Returns the value of attribute influence.
-
#pwd ⇒ Object
Returns the value of attribute pwd.
-
#server ⇒ Object
Returns the value of attribute server.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(component, type, influence, auto_version) ⇒ Publisher
constructor
A new instance of Publisher.
- #login_cocoadepot ⇒ Object
- #mentioned_list ⇒ Object
- #prepare ⇒ Object
- #publish ⇒ Object
- #publish_components(components_list) ⇒ Object
- #robot_keys ⇒ Object
Constructor Details
#initialize(component, type, influence, auto_version) ⇒ Publisher
Returns a new instance of Publisher.
18 19 20 21 22 23 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 18 def initialize(component, type, influence, auto_version) @component = component @type = type @influence = influence @auto_version = auto_version end |
Instance Attribute Details
#auto_version ⇒ Object
Returns the value of attribute auto_version.
16 17 18 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 16 def auto_version @auto_version end |
#component ⇒ Object
Returns the value of attribute component.
13 14 15 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 13 def component @component end |
#email ⇒ Object
Returns the value of attribute email.
10 11 12 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 10 def email @email end |
#influence ⇒ Object
Returns the value of attribute influence.
15 16 17 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 15 def influence @influence end |
#pwd ⇒ Object
Returns the value of attribute pwd.
11 12 13 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 11 def pwd @pwd end |
#server ⇒ Object
Returns the value of attribute server.
9 10 11 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 9 def server @server end |
#type ⇒ Object
Returns the value of attribute type.
14 15 16 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 14 def type @type end |
Instance Method Details
#login_cocoadepot ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 88 def login_cocoadepot @email = "[email protected]" @pwd = "keep2021" @server = "https://cocoadepot.corp.kuaishou.com" payload = { 'email' => @email, 'password' => @pwd } RestClient::Request RestClient::Request.new({ method: :post, url: "#{@server}/api/v1/users/login", headers:{ "Content-Type" => 'application/json', 'Accept' => 'application/json' }, payload: payload.to_json }).execute do |response| rs = JSON.parse(response) if rs.is_a?Hash error = rs['error'] if error KCommercial::UI.error(error) else KCommercial::UI.info("depot 登录成功") user = "access_token=#{rs["token"]["access-token"]}&uid=#{rs["token"]["uid"]}&client=#{rs["token"]["client"]}" end end end end |
#mentioned_list ⇒ Object
80 81 82 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 80 def mentioned_list @mentioned_list ||= KimConfig.configs["ComponentPublisher"]['kim']["mentioned_list"] || [] end |
#prepare ⇒ Object
25 26 27 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 25 def prepare login_cocoadepot end |
#publish ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 29 def publish influence = '' type = 'pre' user = prepare token = "--user=#{user}" type = 'patch' if @type == 'patch' auto_version = "--auto-version=#{type}" if @auto_version influence = '--influence' if @influence cmd = "depot pod publish #{component} #{auto_version} #{influence} '#{token}'" KCommercial::UI.info("执行命令:" + cmd) output = `#{cmd}` KCommercial::UI.info(output) unless $?.exitstatus.zero? raise '组件发布失败' exit! 1 end unless output.include?('No components changed, it will publish nothing.') component_str = output.split('Published components:').last components = component_str.split("\n\t ").select { |s| !s.empty?} puts "#{components}" components_list = components.map do |s| if s.include?("[32m") s.gsub!("[32m",'') end if s.include?("[0m") s.gsub!("[0m",'') end list = s.split(" ") list end publish_components(components_list) end end |
#publish_components(components_list) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/KCommercialPipeline/core/component_publisher.rb', line 64 def publish_components(components_list) title = "组件发布成功" labels = %w[组件名称 版本] table = MarkdownTables.make_table(labels, components_list, is_rows: true, align: %w[l c c l]) msg = <<EOF # #{title} #{table} EOF kim_model = KimModel.new(MessageType::Markdown, "", msg, "", mentioned_list || ['huzongxing']) robot_keys.each do |robot_key| kim = Kim.new(robot_key, kim_model) kim.notifi_kim end end |