Module: CreatesCommit
- Extended by:
- ActiveSupport::Concern
- Includes:
- Gitlab::Utils::StrongMemoize
- Included in:
- Projects::BlobController, Projects::CommitController, Projects::StaticSiteEditorController, Projects::TreeController
- 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) ⇒ Object
rubocop:disable Gitlab/ModuleWithInstanceVariables.
Methods included from Gitlab::Utils::StrongMemoize
#clear_memoization, #strong_memoize, #strong_memoized?
Instance Method Details
#authorize_edit_tree! ⇒ Object
rubocop:enable Gitlab/ModuleWithInstanceVariables
54 55 56 57 58 |
# File 'app/controllers/concerns/creates_commit.rb', line 54 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) ⇒ 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 |
# File 'app/controllers/concerns/creates_commit.rb', line 8 def create_commit(service, success_path:, failure_path:, failure_view: nil, success_notice: nil) if user_access(@project).can_push_to_branch?(branch_name_or_ref) @project_to_commit_into = @project @branch_name ||= @ref else @project_to_commit_into = current_user.fork_of(@project) @branch_name ||= @project_to_commit_into.repository.next_branch('patch') end @start_branch ||= @ref || @branch_name commit_params = @commit_params.merge( start_project: @project, start_branch: @start_branch, 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) 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 |