require 'KCommercialPipeline/core/branch_diffs' require 'markdown-tables' require 'KCommercialPipeline/core/kim_notify' require "KCommercialPipeline/core/git" require 'KCommercialPipeline/core/kim_cfg' module KCommercial module KCPipeline class FeatureSender def check compare_trunk_diff end def mentioned_list @mentioned_list ||= KimConfig.configs["FeatureSend"]["kim"]["mentioned_list"] || [] end def robot_keys @robot_keys ||= KimConfig.configs["FeatureSend"]['kim']["robot_key"] || [] end 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 def last_release_branch branchs = BranchTool.all_release_branchs_sorted || [] unless branchs.size == 0 last_branch = branchs[-1] last_branch.name || "" end end def data_to_markdown(diffs) if diffs.empty? KCommercial::UI.info("本周暂无需求入版") title = "温馨提示:本周#{KimConfig.configs["common_cfg"]["app_name"]}可能暂无需求入版..." <#{diffs.count}个feature 待封版" labels = ['feature', 'commit', 'author', "date"] table = MarkdownTables.make_table(labels, diff_to_data(diffs), is_rows: true, align: %w[l c c l]) <