commit_controller.rb 1.75 KB
Newer Older
Robert Speicher's avatar
Robert Speicher committed
1 2 3
# Controller for a specific Commit
#
# Not to be confused with CommitsController, plural.
4
class Projects::CommitController < Projects::ApplicationController
Robert Speicher's avatar
Robert Speicher committed
5
  # Authorize
6
  before_action :require_non_empty_project
7 8
  before_action :authorize_download_code!, except: [:cancel_builds]
  before_action :authorize_manage_builds!, only: [:cancel_builds]
9
  before_action :commit
Robert Speicher's avatar
Robert Speicher committed
10 11

  def show
12
    return git_not_found! unless @commit
Robert Speicher's avatar
Robert Speicher committed
13

14
    @line_notes = commit.notes.inline
15
    @diffs = @commit.diffs
16
    @note = @project.build_commit_note(commit)
17 18
    @notes_count = commit.notes.count
    @notes = commit.notes.not_inline.fresh
19
    @noteable = @commit
20
    @comments_allowed = @reply_allowed = true
21 22 23 24
    @comments_target  = {
      noteable_type: 'Commit',
      commit_id: @commit.id
    }
25

26 27
    @ci_commit = project.ci_commit(commit.sha)

28
    respond_to do |format|
29
      format.html
30
      format.diff  { render text: @commit.to_diff }
31
      format.patch { render text: @commit.to_patch }
Robert Speicher's avatar
Robert Speicher committed
32 33
    end
  end
34

35 36 37 38 39 40 41
  def ci
    @ci_commit = @project.ci_commit(@commit.sha)
    @builds = @ci_commit.builds if @ci_commit
    @notes_count = @commit.notes.count
    @ci_project = @project.gitlab_ci_project
  end

42 43 44 45
  def cancel_builds
    @ci_commit = @project.ci_commit(@commit.sha)
    @ci_commit.builds.running_or_pending.each(&:cancel)

46
    redirect_to ci_namespace_project_commit_path(project.namespace, project, commit.sha)
47 48 49
  end


50 51 52 53 54 55
  def branches
    @branches = @project.repository.branch_names_contains(commit.id)
    @tags = @project.repository.tag_names_contains(commit.id)
    render layout: false
  end

56
  def commit
57
    @commit ||= @project.commit(params[:id])
58
  end
59 60 61 62 63 64 65 66

  private

  def authorize_manage_builds!
    unless can?(current_user, :manage_builds, project)
      return page_404
    end
  end
Robert Speicher's avatar
Robert Speicher committed
67
end