gitlab-org--gitlab-foss/app/controllers/projects/refs_controller.rb

80 lines
2.3 KiB
Ruby
Raw Normal View History

class Projects::RefsController < Projects::ApplicationController
2013-04-14 08:08:16 -04:00
include ExtractsPath
include TreeHelper
2011-11-16 00:38:53 -05:00
before_action :require_non_empty_project
before_action :validate_ref_id
before_action :assign_ref_vars
before_action :authorize_download_code!
2011-11-16 00:38:53 -05:00
def switch
respond_to do |format|
format.html do
new_path =
case params[:destination]
when "tree"
namespace_project_tree_path(@project.namespace, @project, @id)
when "blob"
namespace_project_blob_path(@project.namespace, @project, @id)
when "graph"
namespace_project_network_path(@project.namespace, @project, @id, @options)
when "graphs"
namespace_project_graph_path(@project.namespace, @project, @id)
when "find_file"
namespace_project_find_file_path(@project.namespace, @project, @id)
when "graphs_commits"
commits_namespace_project_graph_path(@project.namespace, @project, @id)
when "badges"
namespace_project_pipelines_settings_path(@project.namespace, @project, ref: @id)
else
namespace_project_commits_path(@project.namespace, @project, @id)
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
@offset = if params[:offset].present?
2015-02-03 00:38:50 -05:00
params[:offset].to_i
else
0
end
@limit = 25
@path = params[:path]
contents = []
2014-10-09 03:47:47 -04:00
contents.push(*tree.trees)
contents.push(*tree.blobs)
contents.push(*tree.submodules)
@logs = contents[@offset, @limit].to_a.map do |content|
file = @path ? File.join(@path, content.name) : content.name
last_commit = @repo.last_commit_for_path(@commit.id, file)
2012-07-22 07:08:24 -04:00
{
2012-09-17 13:49:57 -04:00
file_name: content.name,
commit: last_commit
2012-07-10 15:52:38 -04:00
}
end
offset = (@offset + @limit)
if contents.size > offset
@more_log_url = logs_file_namespace_project_ref_path(@project.namespace, @project, @ref, @path || '', offset: offset)
end
respond_to do |format|
format.html { render_404 }
format.js
end
2012-07-10 15:52:38 -04:00
end
private
def validate_ref_id
return not_found! if params[:id].present? && params[:id] !~ Gitlab::PathRegex.git_reference_regex
end
2011-11-16 00:38:53 -05:00
end