BigW Consortium Gitlab

refs_controller.rb 2.36 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
      end
35
      format.js do
36 37
        @ref = params[:ref]
        define_tree_vars
38
        tree
39 40 41
        render "tree"
      end
    end
gitlabhq committed
42 43
  end

44
  def logs_tree
45
    @offset = if params[:offset].present?
46 47 48 49
                params[:offset].to_i
              else
                0
              end
50

51
    @limit = 25
52 53 54 55

    @path = params[:path]

    contents = []
56 57 58
    contents.push(*tree.trees)
    contents.push(*tree.blobs)
    contents.push(*tree.submodules)
59 60 61

    @logs = contents[@offset, @limit].to_a.map do |content|
      file = @path ? File.join(@path, content.name) : content.name
62
      last_commit = @repo.last_commit_for_path(@commit.id, file)
63
      {
64
        file_name: content.name,
65
        commit: last_commit
66 67
      }
    end
68

69
    offset = (@offset + @limit)
70 71
    if contents.size > offset
      @more_log_url = logs_file_namespace_project_ref_path(@project.namespace, @project, @ref, @path || '', offset: offset)
72 73
    end

74 75 76 77
    respond_to do |format|
      format.html { render_404 }
      format.js
    end
78
  end
79 80 81 82 83 84

  private

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