debian-mirror-gitlab/app/controllers/projects/refs_controller.rb

80 lines
2 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::RefsController < Projects::ApplicationController
include ExtractsPath
2015-09-11 14:41:01 +05:30
include TreeHelper
2014-09-02 18:07:02 +05:30
2015-09-11 14:41:01 +05:30
before_action :require_non_empty_project
2015-10-24 18:46:33 +05:30
before_action :validate_ref_id
2015-09-11 14:41:01 +05:30
before_action :assign_ref_vars
before_action :authorize_download_code!
2014-09-02 18:07:02 +05:30
def switch
respond_to do |format|
format.html do
2015-09-11 14:41:01 +05:30
new_path =
case params[:destination]
when "tree"
2017-09-10 17:25:29 +05:30
project_tree_path(@project, @id)
2015-09-11 14:41:01 +05:30
when "blob"
2017-09-10 17:25:29 +05:30
project_blob_path(@project, @id)
2015-09-11 14:41:01 +05:30
when "graph"
2017-09-10 17:25:29 +05:30
project_network_path(@project, @id, @options)
2015-09-11 14:41:01 +05:30
when "graphs"
2017-09-10 17:25:29 +05:30
project_graph_path(@project, @id)
when "find_file"
2017-09-10 17:25:29 +05:30
project_find_file_path(@project, @id)
2015-09-11 14:41:01 +05:30
when "graphs_commits"
2017-09-10 17:25:29 +05:30
commits_project_graph_path(@project, @id)
2016-06-02 11:05:42 +05:30
when "badges"
2017-09-10 17:25:29 +05:30
project_pipelines_settings_path(@project, ref: @id)
2015-09-11 14:41:01 +05:30
else
2017-09-10 17:25:29 +05:30
project_commits_path(@project, @id)
2015-09-11 14:41:01 +05:30
end
2014-09-02 18:07:02 +05:30
redirect_to new_path
end
end
end
def logs_tree
@offset = if params[:offset].present?
2015-04-26 12:48:37 +05:30
params[:offset].to_i
else
0
end
2014-09-02 18:07:02 +05:30
@limit = 25
@path = params[:path]
contents = []
2015-04-26 12:48:37 +05:30
contents.push(*tree.trees)
contents.push(*tree.blobs)
contents.push(*tree.submodules)
2014-09-02 18:07:02 +05:30
@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)
{
file_name: content.name,
commit: last_commit
}
end
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
offset = (@offset + @limit)
if contents.size > offset
2017-09-10 17:25:29 +05:30
@more_log_url = logs_file_project_ref_path(@project, @ref, @path || '', offset: offset)
2015-09-11 14:41:01 +05:30
end
2015-04-26 12:48:37 +05:30
respond_to do |format|
format.html { render_404 }
format.js
end
2014-09-02 18:07:02 +05:30
end
2015-10-24 18:46:33 +05:30
private
def validate_ref_id
2017-09-10 17:25:29 +05:30
return not_found! if params[:id].present? && params[:id] !~ Gitlab::PathRegex.git_reference_regex
2015-10-24 18:46:33 +05:30
end
2014-09-02 18:07:02 +05:30
end