commit_controller.rb 1.5 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 26
    @ci_commit = project.ci_commit(commit.sha)

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 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 45 46 47 48
  def cancel_builds
    @ci_commit = @project.ci_commit(@commit.sha)
    @ci_commit.builds.running_or_pending.each(&:cancel)

    redirect_to namespace_project_commit_path(project.namespace, project, commit.sha)
  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
R
Robert Speicher 已提交
58
end