BigW Consortium Gitlab

refs_controller.rb 2.25 KB
Newer Older
1
class Projects::RefsController < Projects::ApplicationController
2
  include ExtractsPath
3
  include TreeHelper
gitlabhq committed
4

5
  before_action :require_non_empty_project
6
  before_action :validate_ref_id
7 8
  before_action :assign_ref_vars
  before_action :authorize_download_code!
gitlabhq committed
9

10 11 12
  def switch
    respond_to do |format|
      format.html do
13 14 15 16 17 18 19 20 21 22
        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)
23 24
          when "find_file"
            namespace_project_find_file_path(@project.namespace, @project, @id)
25 26
          when "graphs_commits"
            commits_namespace_project_graph_path(@project.namespace, @project, @id)
27
          when "badges"
28
            namespace_project_pipelines_settings_path(@project.namespace, @project, ref: @id)
29 30 31
          else
            namespace_project_commits_path(@project.namespace, @project, @id)
          end
gitlabhq committed
32

33
        redirect_to new_path
34 35
      end
    end
gitlabhq committed
36 37
  end

38
  def logs_tree
39
    @offset = if params[:offset].present?
40 41 42 43
                params[:offset].to_i
              else
                0
              end
44

45
    @limit = 25
46 47 48 49

    @path = params[:path]

    contents = []
50 51 52
    contents.push(*tree.trees)
    contents.push(*tree.blobs)
    contents.push(*tree.submodules)
53 54 55

    @logs = contents[@offset, @limit].to_a.map do |content|
      file = @path ? File.join(@path, content.name) : content.name
56
      last_commit = @repo.last_commit_for_path(@commit.id, file)
57
      {
58
        file_name: content.name,
59
        commit: last_commit
60 61
      }
    end
62

63
    offset = (@offset + @limit)
64 65
    if contents.size > offset
      @more_log_url = logs_file_namespace_project_ref_path(@project.namespace, @project, @ref, @path || '', offset: offset)
66 67
    end

68 69 70 71
    respond_to do |format|
      format.html { render_404 }
      format.js
    end
72
  end
73 74 75 76 77 78

  private

  def validate_ref_id
    return not_found! if params[:id].present? && params[:id] !~ Gitlab::Regex.git_reference_regex
  end
gitlabhq committed
79
end