Module: CreatesCommit
- Extended by:
- ActiveSupport::Concern
- Includes:
- Gitlab::Utils::StrongMemoize
- Defined in:
- app/controllers/concerns/creates_commit.rb
Instance Method Summary collapse
-
#authorize_edit_tree! ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables.
-
#create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil, target_project: nil) ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
Instance Method Details
#authorize_edit_tree! ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables
60 61 62 63 64 |
# File 'app/controllers/concerns/creates_commit.rb', line 60 def return if can_collaborate_with_project?(project, ref: branch_name_or_ref) access_denied! end |
#create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil, target_project: nil) ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables
8 9 10 11 12 13 14 15 16 17 18 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 57 |
# File 'app/controllers/concerns/creates_commit.rb', line 8 def create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil, target_project: nil) target_project ||= @project if user_access(target_project).can_push_to_branch?(branch_name_or_ref) @project_to_commit_into = target_project @different_project = false @branch_name ||= @ref else @project_to_commit_into = current_user.fork_of(target_project) @different_project = true @branch_name ||= @project_to_commit_into.repository.next_branch('patch') end @start_branch ||= @ref || @branch_name commit_params = @commit_params.merge( start_project: @project_to_commit_into, start_branch: @start_branch, source_project: @project, target_project: target_project, branch_name: @branch_name ) result = service.new(@project_to_commit_into, current_user, commit_params).execute if result[:status] == :success update_flash_notice(success_notice) success_path = final_success_path(success_path, target_project) respond_to do |format| format.html { redirect_to success_path } format.json { render json: { message: _("success"), filePath: success_path } } end else flash[:alert] = result[:message] failure_path = failure_path.call if failure_path.respond_to?(:call) respond_to do |format| format.html do if failure_view render failure_view else redirect_to failure_path end end format.json { render json: { message: _("failed"), filePath: failure_path } } end end end |