Class: KCommercial::KCPipeline::KCBranchDiffs

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_branch, target_branch = "develop", type = "branch") ⇒ KCBranchDiffs

Returns a new instance of KCBranchDiffs.



65
66
67
68
69
70
71
72
73
# File 'lib/KCommercialPipeline/core/branch_diffs.rb', line 65

def initialize(source_branch,target_branch = "develop", type = "branch")
   if type == "branch"
      @source_branch = source_branch.include?("origin/") ? source_branch : "origin/#{source_branch}"
      @target_branch = target_branch.include?("origin/") ? target_branch : "origin/#{target_branch}"
   else
      @source_branch = source_branch
      @target_branch = target_branch
   end
end

Instance Attribute Details

#source_branchObject

Returns the value of attribute source_branch.



63
64
65
# File 'lib/KCommercialPipeline/core/branch_diffs.rb', line 63

def source_branch
  @source_branch
end

#target_branchObject

Returns the value of attribute target_branch.



64
65
66
# File 'lib/KCommercialPipeline/core/branch_diffs.rb', line 64

def target_branch
  @target_branch
end

Instance Method Details

#diffsObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/KCommercialPipeline/core/branch_diffs.rb', line 79

def  diffs
   #源分支差异
   source_branch_diff = git.lib.diff_log_between_source_branch_target_branch(@source_branch,@target_branch).map { |c| KCCommit.new(c) }
   #目标分支差异
   target_branch_diff = git.lib.diff_log_between_source_branch_target_branch(@target_branch,@source_branch).map { |c| KCCommit.new(c) }

   target_branch_diff_map = {}
   #目标分支差异转成hash
   target_branch_diff.each do |c|
      target_branch_diff_map[c.commit_id] = c
   end
   #获取不在目标分支的所有commit
   diffs = source_branch_diff.find_all{|c| target_branch_diff_map[c.commit_id].nil? }
end

#gitObject



75
76
77
# File 'lib/KCommercialPipeline/core/branch_diffs.rb', line 75

def git
   @git ||= KCGit.git
end