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 6 7 8
  # Authorize
  before_filter :authorize_read_project!
  before_filter :authorize_code_access!
  before_filter :require_non_empty_project
9
  before_filter :commit
R
Robert Speicher 已提交
10 11

  def show
12
    return git_not_found! unless @commit
R
Robert Speicher 已提交
13

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

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

  def commit
    @commit ||= project.repository.commit(params[:id])
  end
R
Robert Speicher 已提交
37
end