Module: SubmoduleHelper

Extended by:
SubmoduleHelper
Included in:
SubmoduleHelper
Defined in:
app/helpers/submodule_helper.rb

Constant Summary collapse

VALID_SUBMODULE_PROTOCOLS =
%w[http https git ssh].freeze

Instance Method Summary collapse

Instance Method Details

links to files listing for submodule if submodule is a project on this server


9
10
11
# File 'app/helpers/submodule_helper.rb', line 9

def submodule_links(submodule_item, ref = nil, repository = @repository, diff_file = nil)
  repository.submodule_links.for(submodule_item, ref, diff_file)
end

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/submodule_helper.rb', line 13

def submodule_links_for_url(submodule_item_id, url, repository, old_submodule_item_id = nil)
  return [nil, nil, nil] unless url

  if url == '.' || url == './'
    url = File.join(Gitlab.config.gitlab.url, repository.project.full_path)
  end

  if url =~ %r{([^/:]+)/([^/]+(?:\.git)?)\Z}
    namespace, project = Regexp.last_match(1), Regexp.last_match(2)
    gitlab_hosts = [Gitlab.config.gitlab.url,
                    Gitlab.config.gitlab_shell.ssh_path_prefix]

    gitlab_hosts.each do |host|
      if url.start_with?(host)
        namespace, _, project = url.sub(host, '').rpartition('/')
        break
      end
    end

    namespace.sub!(%r{\A/}, '')
    project.rstrip!
    project.sub!(/\.git\z/, '')

    if self_url?(url, namespace, project)
      [
        url_helpers.namespace_project_path(namespace, project),
        url_helpers.namespace_project_tree_path(namespace, project, submodule_item_id),
        (url_helpers.namespace_project_compare_path(namespace, project, to: submodule_item_id, from: old_submodule_item_id) if old_submodule_item_id)
      ]
    elsif relative_self_url?(url)
      relative_self_links(url, submodule_item_id, old_submodule_item_id, repository.project)
    elsif gist_github_dot_com_url?(url)
      gist_github_com_tree_links(namespace, project, submodule_item_id)
    elsif github_dot_com_url?(url)
      github_com_tree_links(namespace, project, submodule_item_id, old_submodule_item_id)
    elsif gitlab_dot_com_url?(url)
      gitlab_com_tree_links(namespace, project, submodule_item_id, old_submodule_item_id)
    else
      [sanitize_submodule_url(url), nil, nil]
    end
  else
    [sanitize_submodule_url(url), nil, nil]
  end
end