Class: FlashFlow::Merge::Acceptance
- Inherits:
-
Base
- Object
- Base
- FlashFlow::Merge::Acceptance
show all
- Defined in:
- lib/flash_flow/merge/acceptance.rb
Instance Method Summary
collapse
Methods inherited from Base
#check_repo, #check_version, #git_merge, #logger, #merge_branches, #pending_release, #ready_to_merge_release, #release_ahead_of_master?, #write_data
Constructor Details
#initialize(opts = {}) ⇒ Acceptance
Returns a new instance of Acceptance.
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/flash_flow/merge/acceptance.rb', line 8
def initialize(opts={})
super(opts)
@data = Data::Base.new(Config.configuration.branches, Config.configuration.branch_info_file, @git, logger: logger)
@do_not_merge = opts[:do_not_merge]
@force = opts[:force]
@rerere_forget = opts[:rerere_forget]
@stories = [opts[:stories]].flatten.compact
end
|
Instance Method Details
#commit_branch_info ⇒ Object
58
59
60
61
62
63
|
# File 'lib/flash_flow/merge/acceptance.rb', line 58
def commit_branch_info
@stories.each do |story_id|
@data.add_story(@git.working_branch, story_id)
end
@data.save!
end
|
#commit_message ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/flash_flow/merge/acceptance.rb', line 133
def commit_message
message ="Flash Flow run from branch: \#{@local_git.working_branch}\n\nMerged branches:\n\#{@data.successes.empty? ? 'None' : @data.successes.sort_by(&:merge_order).map(&:ref).join(\"\\n\")}\n\nFailed branches:\n\#{@data.failures.empty? ? 'None' : @data.failures.map(&:ref).join(\"\\n\")}\n\nRemoved branches:\n\#{@data.removals.empty? ? 'None' : @data.removals.map(&:ref).join(\"\\n\")}\n EOS\n message.gsub(/'/, '')\nend\n"
|
#commit_rerere ⇒ Object
65
66
67
68
69
70
|
# File 'lib/flash_flow/merge/acceptance.rb', line 65
def commit_rerere
current_branches = @data.to_a.select { |branch| !@git.master_branch_contains?(branch.sha) && (Time.now - branch.updated_at < TimeHelper.two_weeks) }
current_rereres = current_branches.map { |branch| branch.resolutions.to_h.values }.flatten
@git.commit_rerere(current_rereres)
end
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/flash_flow/merge/acceptance.rb', line 114
def format_errors
errors = []
branch_not_merged = nil
@data.failures.each do |branch|
if branch.ref == @local_git.working_branch
branch_not_merged = "ERROR: Your branch did not merge to #{@local_git.merge_branch}. Run 'flash_flow --resolve', fix the merge conflict(s) and then re-run this script\n"
else
errors << "WARNING: Unable to merge branch #{@local_git.remote}/#{branch.ref} to #{@local_git.merge_branch} due to conflicts."
end
end
errors << branch_not_merged if branch_not_merged
if errors.empty?
"Success!"
else
errors.join("\n")
end
end
|
#is_working_branch(branch) ⇒ Object
93
94
95
|
# File 'lib/flash_flow/merge/acceptance.rb', line 93
def is_working_branch(branch)
branch.ref == @git.working_branch
end
|
#open_pull_request ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/flash_flow/merge/acceptance.rb', line 97
def open_pull_request
return false if [@local_git.master_branch, @local_git.merge_branch].include?(@local_git.working_branch)
@local_git.push(@local_git.working_branch, @force)
raise OutOfSyncWithRemote.new("Your branch is out of sync with the remote. If you want to force push, run 'flash_flow -f'") unless @local_git.last_success?
if @do_not_merge
@data.remove_from_merge(@local_git.remote, @local_git.working_branch)
else
@data.add_to_merge(@local_git.working_branch)
end
end
|
#print_errors ⇒ Object
110
111
112
|
# File 'lib/flash_flow/merge/acceptance.rb', line 110
def print_errors
puts format_errors
end
|
#process_result(branch, merger) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/flash_flow/merge/acceptance.rb', line 72
def process_result(branch, merger)
case merger.result
when :deleted
@data.mark_deleted(branch)
@notifier.deleted_branch(branch) unless is_working_branch(branch)
when :success
branch.sha = merger.sha
@data.mark_success(branch)
@data.set_resolutions(branch, merger.resolutions)
when :conflict
if is_working_branch(branch)
@data.mark_failure(branch, merger.conflict_sha)
else
@data.mark_failure(branch, nil)
@notifier.merge_conflict(branch)
end
end
end
|
#run ⇒ Object
19
20
21
22
23
24
25
26
27
28
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
|
# File 'lib/flash_flow/merge/acceptance.rb', line 19
def run
check_version
check_repo
puts "Building #{@local_git.merge_branch}... Log can be found in #{FlashFlow::Config.configuration.log_file}"
logger.info "\n\n### Beginning #{@local_git.merge_branch} merge ###\n\n"
begin
open_pull_request
@lock.with_lock do
@git.in_original_merge_branch do
@git.initialize_rerere
end
@git.reset_temp_merge_branch
@git.in_temp_merge_branch do
merge_branches(@data.mergeable) do |branch, merger|
process_result(branch, merger)
end
commit_branch_info
commit_rerere
end
@git.copy_temp_to_branch(@git.merge_branch, commit_message)
@git.delete_temp_merge_branch
@git.push(@git.merge_branch)
end
raise OutOfSyncWithRemote.new("#{@git.merge_branch} is out of sync with the remote.") unless @git.last_success?
print_errors
logger.info "### Finished #{@local_git.merge_branch} merge ###"
rescue Lock::Error, OutOfSyncWithRemote => e
puts 'Failure!'
puts e.message
ensure
@local_git.run("checkout #{@local_git.working_branch}")
end
end
|