summaryrefslogtreecommitdiff
path: root/app/controllers/import/gitea_controller.rb
blob: f067ef625aa0019fd454105601565d5db1eb8849 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

class Import::GiteaController < Import::GithubController
  def new
    if session[access_token_key].present? && session[host_key].present?
      redirect_to status_import_url
    end
  end

  def personal_access_token
    session[host_key] = params[host_key]
    super
  end

  def status
    @gitea_host_url = session[host_key]
    super
  end

  private

  def host_key
    :"#{provider}_host_url"
  end

  # Overridden methods
  def provider
    :gitea
  end

  # Gitea is not yet an OAuth provider
  # See https://github.com/go-gitea/gitea/issues/27
  def logged_in_with_provider?
    false
  end

  def provider_auth
    if session[access_token_key].blank? || session[host_key].blank?
      redirect_to new_import_gitea_url,
        alert: 'You need to specify both an Access Token and a Host URL.'
    end
  end

  def client_options
    { host: session[host_key], api_version: 'v1' }
  end
end