commit_controller.rb 1.1 KB
Newer Older
R
Robert Speicher 已提交
1 2 3
# Controller for a specific Commit
#
# Not to be confused with CommitsController, plural.
4
class Projects::CommitController < Projects::ApplicationController
R
Robert Speicher 已提交
5
  # Authorize
6 7 8
  before_action :require_non_empty_project
  before_action :authorize_download_code!
  before_action :commit
R
Robert Speicher 已提交
9 10

  def show
11
    return git_not_found! unless @commit
R
Robert Speicher 已提交
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

    respond_to do |format|
26
      format.html
R
Riyad Preukschas 已提交
27
      format.diff  { render text: @commit.to_diff }
R
Riyad Preukschas 已提交
28
      format.patch { render text: @commit.to_patch }
R
Robert Speicher 已提交
29 30
    end
  end
31

32 33 34 35 36 37
  def branches
    @branches = @project.repository.branch_names_contains(commit.id)
    @tags = @project.repository.tag_names_contains(commit.id)
    render layout: false
  end

38
  def commit
39
    @commit ||= @project.commit(params[:id])
40
  end
R
Robert Speicher 已提交
41
end