Class: KCommercial::KCPipeline::FeatureSender

Inherits:
Object
  • Object
show all
Defined in:
lib/KCommercialPipeline/core/feature_send.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



9
10
11
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 9

def check
  compare_trunk_diff
end

#compare_trunk_diffObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 21

def compare_trunk_diff
  last_rb_name = last_release_branch
  raise "未发现合法rb分支,任务结束!" if last_rb_name.nil? || last_rb_name.empty?
  diffs = KCBranchDiffs.new("develop", last_release_branch).diffs
  #读取配置正则
  regular = KimConfig.configs["common_regulars"]["feat_regular"]
  unless regular.size > 0
    regular = "^(\\[[a-zA-Z0-9]+\\])?feat(\\(.*\\))?:.*"
  end
  feats = diffs.find_all { |c| c.message =~ /#{regular}/ }
  content = data_to_markdown(feats)
  notify_kim(content)
end

#data_to_markdown(diffs) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 44

def data_to_markdown(diffs)
  if diffs.empty?
    KCommercial::UI.info("本周暂无需求入版")
    title = "温馨提示:本周#{KimConfig.configs["common_cfg"]["app_name"]}可能暂无需求入版..."
    <<EOF
# #{title}
EOF
  else
    title = "温馨提示:本周#{KimConfig.configs["common_cfg"]["app_name"]}可能有<font color = red size =4 >#{diffs.count}个</font>feature 待封版"
    labels = ['feature', 'commit', 'author', "date"]
    table = MarkdownTables.make_table(labels, diff_to_data(diffs), is_rows: true, align: %w[l c c l])
    <<EOF
# #{title}
#{table}
EOF
  end
end

#diff_to_data(diffs) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 62

def diff_to_data(diffs)
  datas = []
  KCommercial::UI.info("本周可能#{diffs.count}个需求入版")
  diffs.each do |c|
    data = []
    msg = (c.message.split("\n\n")[0] || "").gsub("\n","").gsub('',':')
    data << msg
    data << c.ori_commit_id || ""
    data << c.author.author || ""
    unless mentioned_list.include?(c.author.author)
      mentioned_list << c.author.author
    end
    data << c.date || ""
    datas << data
  end
  datas
end

#last_release_branchObject



35
36
37
38
39
40
41
42
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 35

def last_release_branch
  branchs = BranchTool.all_release_branchs_sorted || []
  unless branchs.size == 0
    last_branch = branchs[-1]
    last_branch.name || ""
  end

end

#mentioned_listObject



13
14
15
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 13

def mentioned_list
  @mentioned_list ||= KimConfig.configs["FeatureSend"]["kim"]["mentioned_list"] || []
end

#notify_kim(content) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 79

def notify_kim(content)
  kim_model = KimModel.new(MessageType::Markdown, "", content, "", mentioned_list)
  robot_keys.each do |robot_key|
    kim = Kim.new(robot_key, kim_model)
    kim.notifi_kim
  end
end

#robot_keysObject



17
18
19
# File 'lib/KCommercialPipeline/core/feature_send.rb', line 17

def robot_keys
  @robot_keys ||= KimConfig.configs["FeatureSend"]['kim']["robot_key"] || []
end