2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-23 12:47:22 -04:00
|
|
|
class Projects::RefsController < Projects::ApplicationController
|
2013-04-14 08:08:16 -04:00
|
|
|
include ExtractsPath
|
2015-07-26 05:17:34 -04:00
|
|
|
include TreeHelper
|
2011-11-16 00:38:53 -05:00
|
|
|
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project
|
2015-10-13 00:43:24 -04:00
|
|
|
before_action :validate_ref_id
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :assign_ref_vars
|
|
|
|
before_action :authorize_download_code!
|
2011-11-16 00:38:53 -05:00
|
|
|
|
2012-10-09 15:09:46 -04:00
|
|
|
def switch
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2015-07-02 14:12:24 -04:00
|
|
|
new_path =
|
|
|
|
case params[:destination]
|
|
|
|
when "tree"
|
2017-06-29 13:06:35 -04:00
|
|
|
project_tree_path(@project, @id)
|
2015-07-02 14:12:24 -04:00
|
|
|
when "blob"
|
2017-06-29 13:06:35 -04:00
|
|
|
project_blob_path(@project, @id)
|
2015-07-02 14:12:24 -04:00
|
|
|
when "graph"
|
2017-06-29 13:06:35 -04:00
|
|
|
project_network_path(@project, @id, @options)
|
2015-07-02 14:12:24 -04:00
|
|
|
when "graphs"
|
2017-06-29 13:06:35 -04:00
|
|
|
project_graph_path(@project, @id)
|
2016-01-07 06:56:18 -05:00
|
|
|
when "find_file"
|
2017-06-29 13:06:35 -04:00
|
|
|
project_find_file_path(@project, @id)
|
2015-07-02 14:12:24 -04:00
|
|
|
when "graphs_commits"
|
2017-06-29 13:06:35 -04:00
|
|
|
commits_project_graph_path(@project, @id)
|
2016-04-04 04:40:40 -04:00
|
|
|
when "badges"
|
2018-03-22 10:31:41 -04:00
|
|
|
project_settings_ci_cd_path(@project, ref: @id)
|
2015-07-02 14:12:24 -04:00
|
|
|
else
|
2017-06-29 13:06:35 -04:00
|
|
|
project_commits_path(@project, @id)
|
2015-07-02 14:12:24 -04:00
|
|
|
end
|
2011-11-16 12:19:18 -05:00
|
|
|
|
2012-09-17 13:49:57 -04:00
|
|
|
redirect_to new_path
|
2012-01-29 14:30:03 -05:00
|
|
|
end
|
|
|
|
end
|
2011-11-16 12:19:18 -05:00
|
|
|
end
|
|
|
|
|
2012-07-10 15:52:38 -04:00
|
|
|
def logs_tree
|
2018-09-04 12:30:52 -04:00
|
|
|
summary = ::Gitlab::TreeSummary.new(
|
|
|
|
@commit,
|
|
|
|
@project,
|
|
|
|
path: @path,
|
|
|
|
offset: params[:offset],
|
|
|
|
limit: 25
|
|
|
|
)
|
2014-06-12 05:01:54 -04:00
|
|
|
|
2018-09-04 12:30:52 -04:00
|
|
|
@logs, commits = summary.summarize
|
|
|
|
@more_log_url = more_url(summary.next_offset) if summary.more?
|
2015-07-26 05:17:34 -04:00
|
|
|
|
2015-04-06 23:02:06 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render_404 }
|
2017-11-01 12:08:06 -04:00
|
|
|
format.json do
|
2018-09-04 12:30:52 -04:00
|
|
|
response.headers["More-Logs-Url"] = @more_log_url if summary.more?
|
2017-11-01 12:08:06 -04:00
|
|
|
render json: @logs
|
|
|
|
end
|
2018-09-04 12:30:52 -04:00
|
|
|
|
|
|
|
# The commit titles must be rendered and redacted before being shown.
|
|
|
|
# Doing it here allows us to apply performance optimizations that avoid
|
|
|
|
# N+1 problems
|
|
|
|
format.js do
|
|
|
|
prerender_commit_full_titles!(commits)
|
|
|
|
end
|
2015-04-06 23:02:06 -04:00
|
|
|
end
|
2012-07-10 15:52:38 -04:00
|
|
|
end
|
2015-10-13 00:43:24 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-09-04 12:30:52 -04:00
|
|
|
def more_url(offset)
|
|
|
|
logs_file_project_ref_path(@project, @ref, @path, offset: offset)
|
2018-09-04 11:52:00 -04:00
|
|
|
end
|
|
|
|
|
2018-09-04 12:30:52 -04:00
|
|
|
def prerender_commit_full_titles!(commits)
|
2018-09-05 18:05:09 -04:00
|
|
|
# Preload commit authors as they are used in rendering
|
|
|
|
commits.each(&:lazy_author)
|
|
|
|
|
2018-09-04 08:51:02 -04:00
|
|
|
renderer = Banzai::ObjectRenderer.new(user: current_user, default_project: @project)
|
2018-09-04 11:52:00 -04:00
|
|
|
renderer.render(commits, :full_title)
|
2018-09-04 08:51:02 -04:00
|
|
|
end
|
|
|
|
|
2015-10-13 00:43:24 -04:00
|
|
|
def validate_ref_id
|
2017-05-24 16:59:26 -04:00
|
|
|
return not_found! if params[:id].present? && params[:id] !~ Gitlab::PathRegex.git_reference_regex
|
2015-10-13 00:43:24 -04:00
|
|
|
end
|
2011-11-16 00:38:53 -05:00
|
|
|
end
|