Commit 5d56da6bddcaa4d510fd97a8e38d80e750e3e20f
1 parent
489fa5d7
Exists in
master
and in
4 other branches
MR on fork: Some cleanup, test updates
-The forked merge request test now tests it's componenets again, and seems to work every time (did this by reordering the branch updates so their is more time for update_branches to run) -- this could still technically fail, but after several runs it doesn't seem to. -Removed todo in merge_request, pushed wrapping of grit down to the satellite -updated action test to check flock status, made it nolonger pending -moved all logging on failure to helper method in satellite GITLAB-592 Change-Id: If0554ca35eedc3d3e8461f7d93d4b3939fa2cd75
Showing
7 changed files
with
101 additions
and
106 deletions
Show diff stats
app/assets/stylesheets/common.scss
@@ -415,6 +415,7 @@ img.emoji { | @@ -415,6 +415,7 @@ img.emoji { | ||
415 | @extend .light-well; | 415 | @extend .light-well; |
416 | @extend .light; | 416 | @extend .light; |
417 | margin-bottom: 10px; | 417 | margin-bottom: 10px; |
418 | +} | ||
418 | 419 | ||
419 | .label-project { | 420 | .label-project { |
420 | @include border-radius(4px); | 421 | @include border-radius(4px); |
app/models/merge_request.rb
@@ -26,12 +26,10 @@ class MergeRequest < ActiveRecord::Base | @@ -26,12 +26,10 @@ class MergeRequest < ActiveRecord::Base | ||
26 | 26 | ||
27 | include Issuable | 27 | include Issuable |
28 | 28 | ||
29 | - belongs_to :target_project,:foreign_key => :target_project_id, class_name: "Project" | ||
30 | - belongs_to :source_project, :foreign_key => :source_project_id,class_name: "Project" | 29 | + belongs_to :target_project, :foreign_key => :target_project_id, class_name: "Project" |
30 | + belongs_to :source_project, :foreign_key => :source_project_id, class_name: "Project" | ||
31 | 31 | ||
32 | - BROKEN_DIFF = "--broken-diff" | ||
33 | - | ||
34 | - attr_accessible :title, :assignee_id, :source_project_id, :source_branch, :target_project_id, :target_branch, :milestone_id,:author_id_of_changes, :state_event | 32 | + attr_accessible :title, :assignee_id, :source_project_id, :source_branch, :target_project_id, :target_branch, :milestone_id, :author_id_of_changes, :state_event |
35 | 33 | ||
36 | 34 | ||
37 | attr_accessor :should_remove_source_branch | 35 | attr_accessor :should_remove_source_branch |
@@ -87,8 +85,8 @@ class MergeRequest < ActiveRecord::Base | @@ -87,8 +85,8 @@ class MergeRequest < ActiveRecord::Base | ||
87 | validates :target_branch, presence: true | 85 | validates :target_branch, presence: true |
88 | validate :validate_branches | 86 | validate :validate_branches |
89 | 87 | ||
90 | - scope :of_group, ->(group) { where("source_project_id in (:group_project_ids) OR target_project_id in (:group_project_ids)",group_project_ids:group.project_ids) } | ||
91 | - scope :of_user_team, ->(team) { where("(source_project_id in (:team_project_ids) OR target_project_id in (:team_project_ids) AND assignee_id in (:team_member_ids))",team_project_ids:team.project_ids,team_member_ids:team.member_ids) } | 88 | + scope :of_group, ->(group) { where("source_project_id in (:group_project_ids) OR target_project_id in (:group_project_ids)", group_project_ids: group.project_ids) } |
89 | + scope :of_user_team, ->(team) { where("(source_project_id in (:team_project_ids) OR target_project_id in (:team_project_ids) AND assignee_id in (:team_member_ids))", team_project_ids: team.project_ids, team_member_ids: team.member_ids) } | ||
92 | scope :opened, -> { with_state(:opened) } | 90 | scope :opened, -> { with_state(:opened) } |
93 | scope :closed, -> { with_state(:closed) } | 91 | scope :closed, -> { with_state(:closed) } |
94 | scope :merged, -> { with_state(:merged) } | 92 | scope :merged, -> { with_state(:merged) } |
@@ -151,13 +149,8 @@ class MergeRequest < ActiveRecord::Base | @@ -151,13 +149,8 @@ class MergeRequest < ActiveRecord::Base | ||
151 | end | 149 | end |
152 | 150 | ||
153 | def unmerged_diffs | 151 | def unmerged_diffs |
154 | - #TODO:[IA-8] this needs to be handled better -- logged etc | ||
155 | - diffs = Gitlab::Satellite::MergeAction.new(author, self).diffs_between_satellite | ||
156 | - if diffs | ||
157 | - diffs = diffs.map { |diff| Gitlab::Git::Diff.new(diff) } | ||
158 | - else | ||
159 | - diffs = [] | ||
160 | - end | 152 | + diffs = Gitlab::Satellite::MergeAction.new(author, self).diffs_between_satellite |
153 | + diffs ||= [] | ||
161 | diffs | 154 | diffs |
162 | end | 155 | end |
163 | 156 | ||
@@ -192,12 +185,11 @@ class MergeRequest < ActiveRecord::Base | @@ -192,12 +185,11 @@ class MergeRequest < ActiveRecord::Base | ||
192 | end | 185 | end |
193 | 186 | ||
194 | def unmerged_commits | 187 | def unmerged_commits |
195 | - commits = Gitlab::Satellite::MergeAction.new(self.author,self).commits_between | ||
196 | - commits = commits.map{ |commit| Gitlab::Git::Commit.new(commit, nil) } | 188 | + commits = Gitlab::Satellite::MergeAction.new(self.author, self).commits_between |
197 | if commits.present? | 189 | if commits.present? |
198 | commits = Commit.decorate(commits). | 190 | commits = Commit.decorate(commits). |
199 | - sort_by(&:created_at). | ||
200 | - reverse | 191 | + sort_by(&:created_at). |
192 | + reverse | ||
201 | end | 193 | end |
202 | commits | 194 | commits |
203 | end | 195 | end |
@@ -222,6 +214,7 @@ class MergeRequest < ActiveRecord::Base | @@ -222,6 +214,7 @@ class MergeRequest < ActiveRecord::Base | ||
222 | commit_ids = commits.map(&:id) | 214 | commit_ids = commits.map(&:id) |
223 | Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND commit_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) | 215 | Note.where("(noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR (noteable_type = 'Commit' AND commit_id IN (:commit_ids))", mr_id: id, commit_ids: commit_ids) |
224 | end | 216 | end |
217 | + | ||
225 | # Returns the raw diff for this merge request | 218 | # Returns the raw diff for this merge request |
226 | # | 219 | # |
227 | # see "git diff" | 220 | # see "git diff" |
features/steps/project/project_forked_merge_requests.rb
@@ -5,6 +5,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | @@ -5,6 +5,7 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | ||
5 | include SharedPaths | 5 | include SharedPaths |
6 | 6 | ||
7 | 7 | ||
8 | + | ||
8 | Given 'I am a member of project "Shop"' do | 9 | Given 'I am a member of project "Shop"' do |
9 | @project = Project.find_by_name "Shop" | 10 | @project = Project.find_by_name "Shop" |
10 | @project ||= create(:project_with_code, name: "Shop") | 11 | @project ||= create(:project_with_code, name: "Shop") |
@@ -34,22 +35,42 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | @@ -34,22 +35,42 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | ||
34 | current_path.should == project_merge_request_path(@project, @merge_request) | 35 | current_path.should == project_merge_request_path(@project, @merge_request) |
35 | @merge_request.title.should == "Merge Request On Forked Project" | 36 | @merge_request.title.should == "Merge Request On Forked Project" |
36 | @merge_request.source_project.should == @forked_project | 37 | @merge_request.source_project.should == @forked_project |
38 | + @merge_request.source_branch.should == "master" | ||
39 | + @merge_request.target_branch.should == "stable" | ||
40 | + page.should have_content @forked_project.path_with_namespace | ||
41 | + page.should have_content @project.path_with_namespace | ||
42 | + page.should have_content @merge_request.source_branch | ||
43 | + page.should have_content @merge_request.target_branch | ||
37 | end | 44 | end |
38 | 45 | ||
39 | And 'I fill out a "Merge Request On Forked Project" merge request' do | 46 | And 'I fill out a "Merge Request On Forked Project" merge request' do |
47 | + #The ordering here is a bit whacky on purpose: | ||
48 | + #Select the target right away, to give update_branches time to run and clean up the target_branches | ||
49 | + find(:select, "merge_request_target_project_id", {}).value.should == @forked_project.id.to_s | ||
50 | + select @project.path_with_namespace, from: "merge_request_target_project_id" | ||
51 | + | ||
52 | + | ||
40 | fill_in "merge_request_title", with: "Merge Request On Forked Project" | 53 | fill_in "merge_request_title", with: "Merge Request On Forked Project" |
41 | find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s | 54 | find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s |
42 | - find(:select, "merge_request_target_project_id", {}).value.should == @forked_project.id.to_s | ||
43 | 55 | ||
44 | - select @project.path_with_namespace, from: "merge_request_target_project_id" | ||
45 | find(:select, "merge_request_target_project_id", {}).value.should == @project.id.to_s | 56 | find(:select, "merge_request_target_project_id", {}).value.should == @project.id.to_s |
57 | + | ||
58 | + #Ensure the option exists in the select | ||
59 | + find(:select, "merge_request_source_branch", {}).should have_content "master" | ||
46 | select "master", from: "merge_request_source_branch" | 60 | select "master", from: "merge_request_source_branch" |
61 | + #Ensure the option is selected | ||
47 | find(:select, "merge_request_source_branch", {}).value.should have_content "master" | 62 | find(:select, "merge_request_source_branch", {}).value.should have_content "master" |
48 | - #Force the page to wait until the javascript finishes, so the stable option shows up | ||
49 | - select "stable", from: "merge_request_target_branch" | 63 | + verify_commit_link(".mr_source_commit",@forked_project) |
64 | + | ||
65 | + | ||
66 | + #This could fail if the javascript hasn't run yet, there is a timing issue here -- this is why we do the select at the top | ||
67 | + #Ensure the option exists in the select | ||
50 | find(:select, "merge_request_target_branch", {}).should have_content "stable" | 68 | find(:select, "merge_request_target_branch", {}).should have_content "stable" |
69 | + #We must give apparently lots of time for update branches to finish | ||
51 | 70 | ||
52 | - verify_commit_link(".mr_source_commit",@forked_project) | 71 | + (find(:select, "merge_request_target_branch", {}).find(:option, "stable",{}).select_option).should be_true |
72 | + #Ensure the option is selected | ||
73 | + find(:select, "merge_request_target_branch", {}).value.should have_content "stable" | ||
53 | verify_commit_link(".mr_target_commit",@project) | 74 | verify_commit_link(".mr_target_commit",@project) |
54 | end | 75 | end |
55 | 76 | ||
@@ -126,14 +147,8 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | @@ -126,14 +147,8 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | ||
126 | find("#merge_request_target_project_id").value.should == @project.id.to_s | 147 | find("#merge_request_target_project_id").value.should == @project.id.to_s |
127 | find("#merge_request_source_branch").value.should have_content "master" | 148 | find("#merge_request_source_branch").value.should have_content "master" |
128 | verify_commit_link(".mr_source_commit",@forked_project) | 149 | verify_commit_link(".mr_source_commit",@forked_project) |
129 | - #TODO[IA-08] reienstate these -- not sure why they started repeatedly breaking | ||
130 | - #sleep 3 | ||
131 | - #puts "Source text:#{find("#merge_request_source_branch").text}" | ||
132 | - #puts "Source value:#{find("#merge_request_source_branch").value}" | ||
133 | - #puts "Target text:#{find("#merge_request_target_branch").text}" | ||
134 | - #puts "Target value:#{find("#merge_request_target_branch").value}" | ||
135 | - #find("#merge_request_target_branch").value.should have_content "stable" | ||
136 | - #verify_commit_link(".mr_target_commit",@project) | 150 | + find("#merge_request_target_branch").value.should have_content "stable" |
151 | + verify_commit_link(".mr_target_commit",@project) | ||
137 | end | 152 | end |
138 | 153 | ||
139 | 154 | ||
@@ -144,16 +159,8 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | @@ -144,16 +159,8 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps | ||
144 | #Verify a link is generated against the correct project | 159 | #Verify a link is generated against the correct project |
145 | def verify_commit_link(container_div, container_project) | 160 | def verify_commit_link(container_div, container_project) |
146 | #This should force a wait for the javascript to execute | 161 | #This should force a wait for the javascript to execute |
147 | - #puts "text: #{find(:div,container_div).text}" | ||
148 | find(:div,container_div).should have_css ".browse_code_link_holder" | 162 | find(:div,container_div).should have_css ".browse_code_link_holder" |
149 | find(:div,container_div).find(".commit_short_id")['href'].should have_content "#{container_project.path_with_namespace}/commit" | 163 | find(:div,container_div).find(".commit_short_id")['href'].should have_content "#{container_project.path_with_namespace}/commit" |
150 | - #commit_links = commit.all("a").map(&:text) | ||
151 | - #links = commit_links.collect {|e|commit.find(:link,e)['href']} | ||
152 | - #links.size.should == 4 | ||
153 | - #links[0].should have_content "#{container_project.path_with_namespace}/tree" | ||
154 | - #links[1].should have_content "#{container_project.path_with_namespace}/commit" | ||
155 | - #links[3].should have_content "#{container_project.path_with_namespace}/commit" | ||
156 | - | ||
157 | end | 164 | end |
158 | 165 | ||
159 | end | 166 | end |
lib/gitlab/satellite/action.rb
1 | module Gitlab | 1 | module Gitlab |
2 | module Satellite | 2 | module Satellite |
3 | class Action | 3 | class Action |
4 | - DEFAULT_OPTIONS = { git_timeout: 30.seconds} | 4 | + DEFAULT_OPTIONS = {git_timeout: 30.seconds} |
5 | 5 | ||
6 | attr_accessor :options, :project, :user | 6 | attr_accessor :options, :project, :user |
7 | 7 | ||
@@ -25,11 +25,9 @@ module Gitlab | @@ -25,11 +25,9 @@ module Gitlab | ||
25 | end | 25 | end |
26 | end | 26 | end |
27 | rescue Errno::ENOMEM => ex | 27 | rescue Errno::ENOMEM => ex |
28 | - Gitlab::GitLogger.error(ex.message) | ||
29 | - return false | 28 | + return handle_exception(ex) |
30 | rescue Grit::Git::GitTimeout => ex | 29 | rescue Grit::Git::GitTimeout => ex |
31 | - Gitlab::GitLogger.error(ex.message) | ||
32 | - return false | 30 | + return handle_exception(ex) |
33 | ensure | 31 | ensure |
34 | Gitlab::ShellEnv.reset_env | 32 | Gitlab::ShellEnv.reset_env |
35 | end | 33 | end |
@@ -48,6 +46,11 @@ module Gitlab | @@ -48,6 +46,11 @@ module Gitlab | ||
48 | def default_options(options = {}) | 46 | def default_options(options = {}) |
49 | {raise: true, timeout: true}.merge(options) | 47 | {raise: true, timeout: true}.merge(options) |
50 | end | 48 | end |
49 | + | ||
50 | + def handle_exception(exception) | ||
51 | + Gitlab::GitLogger.error(exception.message) | ||
52 | + false | ||
53 | + end | ||
51 | end | 54 | end |
52 | end | 55 | end |
53 | end | 56 | end |
lib/gitlab/satellite/merge_action.rb
@@ -41,8 +41,7 @@ module Gitlab | @@ -41,8 +41,7 @@ module Gitlab | ||
41 | end | 41 | end |
42 | end | 42 | end |
43 | rescue Grit::Git::CommandFailed => ex | 43 | rescue Grit::Git::CommandFailed => ex |
44 | - Gitlab::GitLogger.error(ex.message) | ||
45 | - false | 44 | + handle_exception(ex) |
46 | end | 45 | end |
47 | 46 | ||
48 | 47 | ||
@@ -61,8 +60,7 @@ module Gitlab | @@ -61,8 +60,7 @@ module Gitlab | ||
61 | return diff | 60 | return diff |
62 | end | 61 | end |
63 | rescue Grit::Git::CommandFailed => ex | 62 | rescue Grit::Git::CommandFailed => ex |
64 | - Gitlab::GitLogger.error(ex.message) | ||
65 | - false | 63 | + handle_exception(ex) |
66 | end | 64 | end |
67 | 65 | ||
68 | # Only show what is new in the source branch compared to the target branch, not the other way around. | 66 | # Only show what is new in the source branch compared to the target branch, not the other way around. |
@@ -81,11 +79,11 @@ module Gitlab | @@ -81,11 +79,11 @@ module Gitlab | ||
81 | #this method doesn't take default options | 79 | #this method doesn't take default options |
82 | diffs = merge_repo.diff(common_commit, "#{merge_request.source_branch}") | 80 | diffs = merge_repo.diff(common_commit, "#{merge_request.source_branch}") |
83 | end | 81 | end |
82 | + diffs = diffs.map { |diff| Gitlab::Git::Diff.new(diff) } | ||
84 | return diffs | 83 | return diffs |
85 | end | 84 | end |
86 | rescue Grit::Git::CommandFailed => ex | 85 | rescue Grit::Git::CommandFailed => ex |
87 | - Gitlab::GitLogger.error(ex.message) | ||
88 | - false | 86 | + handle_exception(ex) |
89 | end | 87 | end |
90 | 88 | ||
91 | # Get commit as an email patch | 89 | # Get commit as an email patch |
@@ -101,8 +99,7 @@ module Gitlab | @@ -101,8 +99,7 @@ module Gitlab | ||
101 | return patch | 99 | return patch |
102 | end | 100 | end |
103 | rescue Grit::Git::CommandFailed => ex | 101 | rescue Grit::Git::CommandFailed => ex |
104 | - Gitlab::GitLogger.error(ex.message) | ||
105 | - false | 102 | + handle_exception(ex) |
106 | end | 103 | end |
107 | 104 | ||
108 | # Retrieve an array of commits between the source and the target | 105 | # Retrieve an array of commits between the source and the target |
@@ -115,12 +112,12 @@ module Gitlab | @@ -115,12 +112,12 @@ module Gitlab | ||
115 | else | 112 | else |
116 | commits = merge_repo.commits_between("#{merge_request.target_branch}", "#{merge_request.source_branch}") | 113 | commits = merge_repo.commits_between("#{merge_request.target_branch}", "#{merge_request.source_branch}") |
117 | end | 114 | end |
115 | + commits = commits.map { |commit| Gitlab::Git::Commit.new(commit, nil) } | ||
118 | return commits | 116 | return commits |
119 | 117 | ||
120 | end | 118 | end |
121 | rescue Grit::Git::CommandFailed => ex | 119 | rescue Grit::Git::CommandFailed => ex |
122 | - Gitlab::GitLogger.error(ex.message) | ||
123 | - false | 120 | + handle_exception(ex) |
124 | end | 121 | end |
125 | 122 | ||
126 | private | 123 | private |
@@ -142,8 +139,7 @@ module Gitlab | @@ -142,8 +139,7 @@ module Gitlab | ||
142 | repo.git.pull(default_options({no_ff: true}), 'origin', merge_request.source_branch) | 139 | repo.git.pull(default_options({no_ff: true}), 'origin', merge_request.source_branch) |
143 | end | 140 | end |
144 | rescue Grit::Git::CommandFailed => ex | 141 | rescue Grit::Git::CommandFailed => ex |
145 | - Gitlab::GitLogger.error(ex.message) | ||
146 | - false | 142 | + handle_exception(ex) |
147 | end | 143 | end |
148 | 144 | ||
149 | # Assumes a satellite exists that is a fresh clone of the projects repo, prepares satellite for merges, diffs etc | 145 | # Assumes a satellite exists that is a fresh clone of the projects repo, prepares satellite for merges, diffs etc |
@@ -159,11 +155,9 @@ module Gitlab | @@ -159,11 +155,9 @@ module Gitlab | ||
159 | repo.git.checkout(default_options, "#{merge_request.target_branch}") | 155 | repo.git.checkout(default_options, "#{merge_request.target_branch}") |
160 | end | 156 | end |
161 | rescue Grit::Git::CommandFailed => ex | 157 | rescue Grit::Git::CommandFailed => ex |
162 | - Gitlab::GitLogger.error(ex.message) | ||
163 | - false | 158 | + handle_exception(ex) |
164 | end | 159 | end |
165 | 160 | ||
166 | - | ||
167 | end | 161 | end |
168 | end | 162 | end |
169 | end | 163 | end |
spec/lib/gitlab/satellite/action_spec.rb
@@ -78,52 +78,43 @@ describe 'Gitlab::Satellite::Action' do | @@ -78,52 +78,43 @@ describe 'Gitlab::Satellite::Action' do | ||
78 | end | 78 | end |
79 | 79 | ||
80 | it 'should be able to use the satellite after locking' do | 80 | it 'should be able to use the satellite after locking' do |
81 | - pending "can't test this, doesn't seem to be a way to the the flock status on a file, throwing piles of processes at it seems lousy too" | ||
82 | repo = project.satellite.repo | 81 | repo = project.satellite.repo |
83 | - first_call = false | ||
84 | - | ||
85 | - (File.exists? project.satellite.lock_file).should be_false | ||
86 | - | ||
87 | - test_file = ->(called) { | ||
88 | - File.exists?(project.satellite.lock_file).should be_true | ||
89 | - called.should be_true | ||
90 | - File.readlines.should == "some test code" | ||
91 | - File.truncate(project.satellite.lock, 0) | ||
92 | - File.readlines.should == "" | ||
93 | - } | ||
94 | - | ||
95 | - write_file = ->(called, checker) { | ||
96 | - if (File.exists?(project.satellite.lock_file)) | ||
97 | - file = File.open(project.satellite.lock, '+w') | ||
98 | - file.write("some test code") | ||
99 | - file.close | ||
100 | - checker.call(called) | ||
101 | - end | ||
102 | - } | 82 | + called = false |
103 | 83 | ||
84 | + # Set base assumptions | ||
85 | + if File.exists? project.satellite.lock_file | ||
86 | + FileLockStatusChecker.new(project.satellite.lock_file).flocked?.should be_false | ||
87 | + end | ||
104 | 88 | ||
105 | satellite_action = Gitlab::Satellite::Action.new(user, project) | 89 | satellite_action = Gitlab::Satellite::Action.new(user, project) |
106 | satellite_action.send(:in_locked_and_timed_satellite) do |sat_repo| | 90 | satellite_action.send(:in_locked_and_timed_satellite) do |sat_repo| |
107 | - write_file.call(first_call, test_file) | ||
108 | - first_call = true | 91 | + called = true |
109 | repo.should == sat_repo | 92 | repo.should == sat_repo |
110 | (File.exists? project.satellite.lock_file).should be_true | 93 | (File.exists? project.satellite.lock_file).should be_true |
111 | - | 94 | + FileLockStatusChecker.new(project.satellite.lock_file).flocked?.should be_true |
112 | end | 95 | end |
113 | 96 | ||
114 | - first_call.should be_true | ||
115 | - puts File.stat(project.satellite.lock_file).inspect | 97 | + called.should be_true |
98 | + FileLockStatusChecker.new(project.satellite.lock_file).flocked?.should be_false | ||
116 | 99 | ||
117 | - second_call = false | ||
118 | - satellite_action.send(:in_locked_and_timed_satellite) do |sat_repo| | ||
119 | - write_file.call(second_call, test_file) | ||
120 | - second_call = true | ||
121 | - repo.should == sat_repo | ||
122 | - (File.exists? project.satellite.lock_file).should be_true | ||
123 | - end | 100 | + end |
124 | 101 | ||
125 | - second_call.should be_true | ||
126 | - (File.exists? project.satellite.lock_file).should be_true | 102 | + class FileLockStatusChecker < File |
103 | + def flocked? &block | ||
104 | + status = flock LOCK_EX|LOCK_NB | ||
105 | + case status | ||
106 | + when false | ||
107 | + return true | ||
108 | + when 0 | ||
109 | + begin | ||
110 | + block ? block.call : false | ||
111 | + ensure | ||
112 | + flock LOCK_UN | ||
113 | + end | ||
114 | + else | ||
115 | + raise SystemCallError, status | ||
116 | + end | ||
117 | + end | ||
127 | end | 118 | end |
128 | 119 | ||
129 | end | 120 | end |
spec/lib/gitlab/satellite/merge_action_spec.rb
@@ -8,7 +8,7 @@ describe 'Gitlab::Satellite::MergeAction' do | @@ -8,7 +8,7 @@ describe 'Gitlab::Satellite::MergeAction' do | ||
8 | @wiki_branch = ['wiki', '635d3e09b72232b6e92a38de6cc184147e5bcb41'] #this is the commit sha where the wiki branch goes off from master | 8 | @wiki_branch = ['wiki', '635d3e09b72232b6e92a38de6cc184147e5bcb41'] #this is the commit sha where the wiki branch goes off from master |
9 | @conflicting_metior = ['metior', '313d96e42b313a0af5ab50fa233bf43e27118b3f'] #this branch conflicts with the wiki branch | 9 | @conflicting_metior = ['metior', '313d96e42b313a0af5ab50fa233bf43e27118b3f'] #this branch conflicts with the wiki branch |
10 | 10 | ||
11 | - #these commits are quite close together, itended to make string diffs/format patches small | 11 | + #these commits are quite close together, itended to make string diffs/format patches small |
12 | @close_commit1 = ['2_3_notes_fix', '8470d70da67355c9c009e4401746b1d5410af2e3'] | 12 | @close_commit1 = ['2_3_notes_fix', '8470d70da67355c9c009e4401746b1d5410af2e3'] |
13 | @close_commit2 = ['scss_refactoring', 'f0f14c8eaba69ebddd766498a9d0b0e79becd633'] | 13 | @close_commit2 = ['scss_refactoring', 'f0f14c8eaba69ebddd766498a9d0b0e79becd633'] |
14 | 14 | ||
@@ -18,19 +18,23 @@ describe 'Gitlab::Satellite::MergeAction' do | @@ -18,19 +18,23 @@ describe 'Gitlab::Satellite::MergeAction' do | ||
18 | let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } | 18 | let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } |
19 | let(:merge_request_fork) { create(:merge_request) } | 19 | let(:merge_request_fork) { create(:merge_request) } |
20 | describe '#commits_between' do | 20 | describe '#commits_between' do |
21 | + def verify_commits(commits, first_commit_sha, last_commit_sha) | ||
22 | + commits.each { |commit| commit.class.should == Gitlab::Git::Commit } | ||
23 | + commits.first.id.should == first_commit_sha | ||
24 | + commits.last.id.should == last_commit_sha | ||
25 | + end | ||
26 | + | ||
21 | context 'on fork' do | 27 | context 'on fork' do |
22 | it 'should get proper commits between' do | 28 | it 'should get proper commits between' do |
23 | merge_request_fork.target_branch = @one_after_stable[0] | 29 | merge_request_fork.target_branch = @one_after_stable[0] |
24 | merge_request_fork.source_branch = @master[0] | 30 | merge_request_fork.source_branch = @master[0] |
25 | commits = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).commits_between | 31 | commits = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).commits_between |
26 | - commits.first.id.should == @one_after_stable[1] | ||
27 | - commits.last.id.should == @master[1] | 32 | + verify_commits(commits, @one_after_stable[1], @master[1]) |
28 | 33 | ||
29 | merge_request_fork.target_branch = @wiki_branch[0] | 34 | merge_request_fork.target_branch = @wiki_branch[0] |
30 | merge_request_fork.source_branch = @master[0] | 35 | merge_request_fork.source_branch = @master[0] |
31 | commits = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).commits_between | 36 | commits = Gitlab::Satellite::MergeAction.new(merge_request_fork.author, merge_request_fork).commits_between |
32 | - commits.first.id.should == @wiki_branch[1] | ||
33 | - commits.last.id.should == @master[1] | 37 | + verify_commits(commits, @wiki_branch[1], @master[1]) |
34 | end | 38 | end |
35 | end | 39 | end |
36 | 40 | ||
@@ -39,14 +43,12 @@ describe 'Gitlab::Satellite::MergeAction' do | @@ -39,14 +43,12 @@ describe 'Gitlab::Satellite::MergeAction' do | ||
39 | merge_request.target_branch = @one_after_stable[0] | 43 | merge_request.target_branch = @one_after_stable[0] |
40 | merge_request.source_branch = @master[0] | 44 | merge_request.source_branch = @master[0] |
41 | commits = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between | 45 | commits = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between |
42 | - commits.first.id.should == @one_after_stable[1] | ||
43 | - commits.last.id.should == @master[1] | 46 | + verify_commits(commits, @one_after_stable[1], @master[1]) |
44 | 47 | ||
45 | merge_request.target_branch = @wiki_branch[0] | 48 | merge_request.target_branch = @wiki_branch[0] |
46 | merge_request.source_branch = @master[0] | 49 | merge_request.source_branch = @master[0] |
47 | commits = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between | 50 | commits = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).commits_between |
48 | - commits.first.id.should == @wiki_branch[1] | ||
49 | - commits.last.id.should == @master[1] | 51 | + verify_commits(commits, @wiki_branch[1], @master[1]) |
50 | end | 52 | end |
51 | end | 53 | end |
52 | end | 54 | end |
@@ -81,8 +83,12 @@ describe 'Gitlab::Satellite::MergeAction' do | @@ -81,8 +83,12 @@ describe 'Gitlab::Satellite::MergeAction' do | ||
81 | diff_count = diff.scan('diff --git').size | 83 | diff_count = diff.scan('diff --git').size |
82 | diff_count.should >= 1 | 84 | diff_count.should >= 1 |
83 | diffs.size.should == diff_count | 85 | diffs.size.should == diff_count |
84 | - diffs.each {|a_diff| (diff.include? a_diff.diff).should be_true} | 86 | + diffs.each do |a_diff| |
87 | + a_diff.class.should == Gitlab::Git::Diff | ||
88 | + (diff.include? a_diff.diff).should be_true | ||
89 | + end | ||
85 | end | 90 | end |
91 | + | ||
86 | context 'on fork' do | 92 | context 'on fork' do |
87 | it 'should get proper diffs' do | 93 | it 'should get proper diffs' do |
88 | merge_request_fork.target_branch = @close_commit1[0] | 94 | merge_request_fork.target_branch = @close_commit1[0] |
@@ -93,7 +99,7 @@ describe 'Gitlab::Satellite::MergeAction' do | @@ -93,7 +99,7 @@ describe 'Gitlab::Satellite::MergeAction' do | ||
93 | merge_request_fork.source_branch = @master[0] | 99 | merge_request_fork.source_branch = @master[0] |
94 | diff = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request_fork).diff_in_satellite | 100 | diff = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request_fork).diff_in_satellite |
95 | 101 | ||
96 | - is_a_matching_diff(diff,diffs) | 102 | + is_a_matching_diff(diff, diffs) |
97 | end | 103 | end |
98 | end | 104 | end |
99 | 105 | ||
@@ -108,7 +114,7 @@ describe 'Gitlab::Satellite::MergeAction' do | @@ -108,7 +114,7 @@ describe 'Gitlab::Satellite::MergeAction' do | ||
108 | merge_request.source_branch = @master[0] | 114 | merge_request.source_branch = @master[0] |
109 | diff = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diff_in_satellite | 115 | diff = Gitlab::Satellite::MergeAction.new(merge_request.author, merge_request).diff_in_satellite |
110 | 116 | ||
111 | - is_a_matching_diff(diff,diffs) | 117 | + is_a_matching_diff(diff, diffs) |
112 | end | 118 | end |
113 | end | 119 | end |
114 | end | 120 | end |