2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Controller for viewing a file's blame
|
|
|
|
class Projects::BlameController < Projects::ApplicationController
|
|
|
|
include ExtractsPath
|
2019-12-26 22:10:19 +05:30
|
|
|
include RedirectsForMissingPathOnTree
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :assign_ref_vars
|
2023-03-04 22:38:38 +05:30
|
|
|
before_action :authorize_read_code!
|
2023-06-20 00:43:36 +05:30
|
|
|
before_action :load_blob
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :source_code_management
|
2021-12-11 22:18:48 +05:30
|
|
|
urgency :low, [:show]
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def show
|
2023-06-20 00:43:36 +05:30
|
|
|
load_environment
|
|
|
|
load_blame
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
def streaming
|
|
|
|
show
|
|
|
|
render action: 'show'
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def page
|
|
|
|
load_environment
|
|
|
|
load_blame
|
2022-07-16 23:28:13 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
render partial: 'page'
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
private
|
2023-05-27 22:25:52 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def load_blob
|
|
|
|
@blob = @repository.blob_at(@commit.id, @path)
|
2022-11-25 23:54:43 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
return if @blob
|
2023-05-27 22:25:52 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
redirect_to_tree_root_for_missing_path(@project, @ref, @path)
|
2023-05-27 22:25:52 +05:30
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def load_environment
|
2023-05-27 22:25:52 +05:30
|
|
|
environment_params = @repository.branch_exists?(@ref) ? { ref: @ref } : { commit: @commit }
|
|
|
|
environment_params[:find_latest] = true
|
|
|
|
@environment = ::Environments::EnvironmentsByDeploymentsFinder.new(@project, current_user, environment_params).execute.last
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def load_blame
|
|
|
|
@blame_mode = Gitlab::Git::BlameMode.new(@commit.project, blame_params)
|
|
|
|
@blame_pagination = Gitlab::Git::BlamePagination.new(@blob, @blame_mode, blame_params)
|
2023-05-27 22:25:52 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
blame = Gitlab::Blame.new(@blob, @commit, range: @blame_pagination.blame_range)
|
|
|
|
@blame = Gitlab::View::Presenter::Factory.new(blame, project: @project, path: @path, page: @blame_pagination.page).fabricate!
|
2023-05-27 22:25:52 +05:30
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def blame_params
|
|
|
|
params.permit(:page, :no_pagination, :streaming)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
Projects::BlameController.prepend_mod
|