Commit 986697a99bde07ea0d7e878f8618f801b6b81a8c

Authored by Dmitriy Zaporozhets
1 parent c77d957b

Refactor Create/Update file context and lib

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/contexts/files/create_context.rb
@@ -33,11 +33,10 @@ module Files @@ -33,11 +33,10 @@ module Files
33 return error("Your changes could not be commited, because file with such name exists") 33 return error("Your changes could not be commited, because file with such name exists")
34 end 34 end
35 35
36 - new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, path) 36 + new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, file_path)
37 created_successfully = new_file_action.commit!( 37 created_successfully = new_file_action.commit!(
38 params[:content], 38 params[:content],
39 - params[:commit_message],  
40 - file_name, 39 + params[:commit_message]
41 ) 40 )
42 41
43 if created_successfully 42 if created_successfully
app/contexts/files/update_context.rb
@@ -24,8 +24,7 @@ module Files @@ -24,8 +24,7 @@ module Files
24 new_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path) 24 new_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path)
25 created_successfully = new_file_action.commit!( 25 created_successfully = new_file_action.commit!(
26 params[:content], 26 params[:content],
27 - params[:commit_message],  
28 - params[:last_commit] 27 + params[:commit_message]
29 ) 28 )
30 29
31 if created_successfully 30 if created_successfully
lib/gitlab/satellite/files/edit_file_action.rb
@@ -10,9 +10,7 @@ module Gitlab @@ -10,9 +10,7 @@ module Gitlab
10 # Returns false if committing the change fails 10 # Returns false if committing the change fails
11 # Returns false if pushing from the satellite to Gitolite failed or was rejected 11 # Returns false if pushing from the satellite to Gitolite failed or was rejected
12 # Returns true otherwise 12 # Returns true otherwise
13 - def commit!(content, commit_message, last_commit)  
14 - return false unless can_edit?(last_commit)  
15 - 13 + def commit!(content, commit_message)
16 in_locked_and_timed_satellite do |repo| 14 in_locked_and_timed_satellite do |repo|
17 prepare_satellite!(repo) 15 prepare_satellite!(repo)
18 16
lib/gitlab/satellite/files/file_action.rb
@@ -8,13 +8,6 @@ module Gitlab @@ -8,13 +8,6 @@ module Gitlab
8 @file_path = file_path 8 @file_path = file_path
9 @ref = ref 9 @ref = ref
10 end 10 end
11 -  
12 - protected  
13 -  
14 - def can_edit?(last_commit)  
15 - current_last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, ref, file_path).sha  
16 - last_commit == current_last_commit  
17 - end  
18 end 11 end
19 end 12 end
20 end 13 end
lib/gitlab/satellite/files/new_file_action.rb
@@ -9,7 +9,7 @@ module Gitlab @@ -9,7 +9,7 @@ module Gitlab
9 # Returns false if committing the change fails 9 # Returns false if committing the change fails
10 # Returns false if pushing from the satellite to Gitolite failed or was rejected 10 # Returns false if pushing from the satellite to Gitolite failed or was rejected
11 # Returns true otherwise 11 # Returns true otherwise
12 - def commit!(content, commit_message, file_name) 12 + def commit!(content, commit_message)
13 in_locked_and_timed_satellite do |repo| 13 in_locked_and_timed_satellite do |repo|
14 prepare_satellite!(repo) 14 prepare_satellite!(repo)
15 15
@@ -17,7 +17,7 @@ module Gitlab @@ -17,7 +17,7 @@ module Gitlab
17 repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}") 17 repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}")
18 18
19 # update the file in the satellite's working dir 19 # update the file in the satellite's working dir
20 - file_path_in_satellite = File.join(repo.working_dir, file_path || '', file_name) 20 + file_path_in_satellite = File.join(repo.working_dir, file_path)
21 File.open(file_path_in_satellite, 'w') { |f| f.write(content) } 21 File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
22 22
23 # add new file 23 # add new file