commit_controller.rb 1.53 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 7 8
  before_action :require_non_empty_project
  before_action :authorize_download_code!
  before_action :commit
Robert Speicher's avatar
Robert Speicher committed
9 10

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

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

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

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

34 35 36 37 38 39 40
  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

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

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


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

55
  def commit
56
    @commit ||= @project.commit(params[:id])
57
  end
Robert Speicher's avatar
Robert Speicher committed
58
end