summaryrefslogtreecommitdiff
path: root/app/helpers/import_helper.rb
blob: fb79e2a4eefcd5e538d7fcde2818555bbff3d85f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module ImportHelper
  def import_project_target(owner, name)
    namespace = current_user.can_create_group? ? owner : current_user.namespace_path
    "#{namespace}/#{name}"
  end

  def github_project_link(path_with_namespace)
    link_to path_with_namespace, github_project_url(path_with_namespace), target: '_blank'
  end

  def gitea_project_link(root_url, path_with_namespace)
    link_to path_with_namespace, gitea_project_url(root_url, path_with_namespace), target: '_blank'
  end

  private

  def github_project_url(path_with_namespace)
    "#{github_root_url}/#{path_with_namespace}"
  end

  def github_root_url
    return @github_url if defined?(@github_url)

    provider = Gitlab.config.omniauth.providers.find { |p| p.name == 'github' }
    @github_url = provider.fetch('url', 'https://github.com') if provider
  end

  def gitea_project_url(root_url, path_with_namespace)
    "#{root_url}/#{path_with_namespace}"
  end
end