diff options
-rw-r--r-- | app/assets/stylesheets/generic/files.scss | 2 | ||||
-rw-r--r-- | app/contexts/files/create_context.rb | 3 | ||||
-rw-r--r-- | app/contexts/files/update_context.rb | 7 | ||||
-rw-r--r-- | app/views/projects/new_tree/show.html.haml | 6 | ||||
-rw-r--r-- | doc/api/repositories.md | 2 | ||||
-rw-r--r-- | lib/api/files.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/satellite/files/edit_file_action.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/satellite/files/file_action.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/satellite/files/new_file_action.rb | 4 |
9 files changed, 30 insertions, 11 deletions
diff --git a/app/assets/stylesheets/generic/files.scss b/app/assets/stylesheets/generic/files.scss index 6607ae327e0..11bb715f7b5 100644 --- a/app/assets/stylesheets/generic/files.scss +++ b/app/assets/stylesheets/generic/files.scss @@ -45,7 +45,7 @@ text-align: center; img { padding: 100px; - max-width: 300px; + max-width: 50%; } } diff --git a/app/contexts/files/create_context.rb b/app/contexts/files/create_context.rb index b3d62a028c7..3b684d3ee92 100644 --- a/app/contexts/files/create_context.rb +++ b/app/contexts/files/create_context.rb @@ -33,7 +33,8 @@ module Files new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, file_path) created_successfully = new_file_action.commit!( params[:content], - params[:commit_message] + params[:commit_message], + params[:encoding] ) if created_successfully diff --git a/app/contexts/files/update_context.rb b/app/contexts/files/update_context.rb index 556027a3256..8f0185df74d 100644 --- a/app/contexts/files/update_context.rb +++ b/app/contexts/files/update_context.rb @@ -23,10 +23,11 @@ module Files return error("You can only edit text files") end - new_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path) - created_successfully = new_file_action.commit!( + edit_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path) + created_successfully = edit_file_action.commit!( params[:content], - params[:commit_message] + params[:commit_message], + params[:encoding] ) if created_successfully diff --git a/app/views/projects/new_tree/show.html.haml b/app/views/projects/new_tree/show.html.haml index 078a4b80d0d..9d7c7afbeac 100644 --- a/app/views/projects/new_tree/show.html.haml +++ b/app/views/projects/new_tree/show.html.haml @@ -15,6 +15,12 @@ %span= @ref .form-group.commit_message-group + = label_tag :encoding, class: "control-label" do + Encoding + .col-sm-10 + = select_tag :encoding, options_for_select([ "base64", "text" ], "text"), class: 'form-control' + + .form-group.commit_message-group = label_tag 'commit_message', class: "control-label" do Commit message .col-sm-10 diff --git a/doc/api/repositories.md b/doc/api/repositories.md index 35f7ad7ae95..01607263008 100644 --- a/doc/api/repositories.md +++ b/doc/api/repositories.md @@ -400,6 +400,7 @@ Parameters: + `file_path` (optional) - Full path to new file. Ex. lib/class.rb + `branch_name` (required) - The name of branch ++ `encoding` (optional) - 'text' or 'base64'. Text is default. + `content` (required) - File content + `commit_message` (required) - Commit message @@ -413,6 +414,7 @@ Parameters: + `file_path` (required) - Full path to file. Ex. lib/class.rb + `branch_name` (required) - The name of branch ++ `encoding` (optional) - 'text' or 'base64'. Text is default. + `content` (required) - New file content + `commit_message` (required) - Commit message diff --git a/lib/api/files.rb b/lib/api/files.rb index 6a5419a580f..8e87ae52e64 100644 --- a/lib/api/files.rb +++ b/lib/api/files.rb @@ -18,7 +18,7 @@ module API # post ":id/repository/files" do required_attributes! [:file_path, :branch_name, :content, :commit_message] - attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message] + attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message, :encoding] branch_name = attrs.delete(:branch_name) file_path = attrs.delete(:file_path) result = ::Files::CreateContext.new(user_project, current_user, attrs, branch_name, file_path).execute @@ -48,7 +48,7 @@ module API # put ":id/repository/files" do required_attributes! [:file_path, :branch_name, :content, :commit_message] - attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message] + attrs = attributes_for_keys [:file_path, :branch_name, :content, :commit_message, :encoding] branch_name = attrs.delete(:branch_name) file_path = attrs.delete(:file_path) result = ::Files::UpdateContext.new(user_project, current_user, attrs, branch_name, file_path).execute diff --git a/lib/gitlab/satellite/files/edit_file_action.rb b/lib/gitlab/satellite/files/edit_file_action.rb index f410ecb7984..cbdf70f7d12 100644 --- a/lib/gitlab/satellite/files/edit_file_action.rb +++ b/lib/gitlab/satellite/files/edit_file_action.rb @@ -10,7 +10,7 @@ module Gitlab # Returns false if committing the change fails # Returns false if pushing from the satellite to bare repo failed or was rejected # Returns true otherwise - def commit!(content, commit_message) + def commit!(content, commit_message, encoding) in_locked_and_timed_satellite do |repo| prepare_satellite!(repo) @@ -26,7 +26,8 @@ module Gitlab return false end - File.open(file_path_in_satellite, 'w') { |f| f.write(content) } + # Write file + write_file(file_path_in_satellite, content, encoding) # commit the changes # will raise CommandFailed when commit fails diff --git a/lib/gitlab/satellite/files/file_action.rb b/lib/gitlab/satellite/files/file_action.rb index 0f7afde647d..7701a6d5d60 100644 --- a/lib/gitlab/satellite/files/file_action.rb +++ b/lib/gitlab/satellite/files/file_action.rb @@ -12,6 +12,14 @@ module Gitlab def safe_path?(path) File.absolute_path(path) == path end + + def write_file(abs_file_path, content, file_encoding = 'text') + if file_encoding == 'base64' + File.open(abs_file_path, 'wb') { |f| f.write(Base64.decode64(content)) } + else + File.open(abs_file_path, 'w') { |f| f.write(content) } + end + end end end end diff --git a/lib/gitlab/satellite/files/new_file_action.rb b/lib/gitlab/satellite/files/new_file_action.rb index 57d101ff535..15e9b7a6f77 100644 --- a/lib/gitlab/satellite/files/new_file_action.rb +++ b/lib/gitlab/satellite/files/new_file_action.rb @@ -9,7 +9,7 @@ module Gitlab # Returns false if committing the change fails # Returns false if pushing from the satellite to bare repo failed or was rejected # Returns true otherwise - def commit!(content, commit_message) + def commit!(content, commit_message, encoding) in_locked_and_timed_satellite do |repo| prepare_satellite!(repo) @@ -29,7 +29,7 @@ module Gitlab FileUtils.mkdir_p(dir_name_in_satellite) # Write file - File.open(file_path_in_satellite, 'w') { |f| f.write(content) } + write_file(file_path_in_satellite, content, encoding) # add new file repo.add(file_path_in_satellite) |