Class: KCommercial::KCPipeline::ReleaseChecker
- Inherits:
-
Object
- Object
- KCommercial::KCPipeline::ReleaseChecker
- Defined in:
- lib/KCommercialPipeline/core/version_pipeline/release_check.rb
Instance Attribute Summary collapse
-
#source_branch ⇒ Object
Returns the value of attribute source_branch.
-
#target_branch ⇒ Object
Returns the value of attribute target_branch.
Instance Method Summary collapse
- #data_to_markdown(diffs) ⇒ Object
-
#initialize(branch_name, target_branch = 'develop') ⇒ ReleaseChecker
constructor
A new instance of ReleaseChecker.
- #mentioned_list ⇒ Object
- #notify_kim(content) ⇒ Object
- #prepare ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(branch_name, target_branch = 'develop') ⇒ ReleaseChecker
Returns a new instance of ReleaseChecker.
22 23 24 25 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 22 def initialize(branch_name,target_branch = 'develop') @source_branch = branch_name @target_branch = target_branch end |
Instance Attribute Details
#source_branch ⇒ Object
Returns the value of attribute source_branch.
20 21 22 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 20 def source_branch @source_branch end |
#target_branch ⇒ Object
Returns the value of attribute target_branch.
21 22 23 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 21 def target_branch @target_branch end |
Instance Method Details
#data_to_markdown(diffs) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 57 def data_to_markdown(diffs) content = "" if diffs.empty? KCommercial::UI.info "#{KimConfig.configs["common_cfg"]["app_name"]}#{@source_branch}分支已合入#{@target_branch}" title = "👍🏻#{KimConfig.configs["common_cfg"]["app_name"]} #{@source_branch}分支全部已合入#{@target_branch}分支,记得打上tag及时清理!" content = <<EOF # #{title} EOF else title = "温馨提示:#{@source_branch}有<font color = red size =4 >#{diffs.count}个</font>commit待合入#{@target_branch}" labels = ['commit', 'message', 'author',"date"] datas = [] diffs.each do |c| data = [] data << c.ori_commit_id || "" data << c..split(" ")[0] || "" data << c.. || "" data << c.date || "" datas << data unless mentioned_list.include?(c..) mentioned_list << c.. || "" end end table = MarkdownTables.make_table(labels, datas, is_rows: true, align: ['l', 'c', 'c','l']) content = <<EOF # #{title} #{table} EOF end KCommercial::UI.info content content end |
#mentioned_list ⇒ Object
27 28 29 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 27 def mentioned_list @mentioned_list ||= KimConfig.configs["ReleaseCheck"]["kim"]["mentioned_list"] || [] end |
#notify_kim(content) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 47 def notify_kim(content) robot_keys = KimConfig.configs["ReleaseCheck"]["kim"]["robot_key"] robot_keys.each do |k| kim_model = KimModel.new(MessageType::Markdown,"",content,"",KimConfig.configs["ReleaseCheck"]["kim"]["mentioned_list"] || []) kim = Kim.new(k,kim_model) kim.notifi_kim end end |
#prepare ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 38 def prepare #读取配置正则 regular = KimConfig.configs["common_regulars"]["release_branch_regular"] unless regular.size > 0 regular = "^(\\[[a-zA-Z0-9]+\\])?feat(\\(.*\\))?:.*" end raise "非法发布分支,不支持!" unless Regexp.new(regular).match(@source_branch) end |
#run! ⇒ Object
31 32 33 34 35 36 |
# File 'lib/KCommercialPipeline/core/version_pipeline/release_check.rb', line 31 def run! prepare diffs = KCBranchDiffs.new(@source_branch,@target_branch).diffs content = data_to_markdown(diffs) notify_kim(content) end |