BigW Consortium Gitlab

refs_controller.rb 1.99 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
        new_path =
          case params[:destination]
          when "tree"
16
            project_tree_path(@project, @id)
17
          when "blob"
18
            project_blob_path(@project, @id)
19
          when "graph"
20
            project_network_path(@project, @id, @options)
21
          when "graphs"
22
            project_graph_path(@project, @id)
23
          when "find_file"
24
            project_find_file_path(@project, @id)
25
          when "graphs_commits"
26
            commits_project_graph_path(@project, @id)
27
          when "badges"
28
            project_pipelines_settings_path(@project, ref: @id)
29
          else
30
            project_commits_path(@project, @id)
31
          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
    if contents.size > offset
65
      @more_log_url = logs_file_project_ref_path(@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

  private

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