debian-mirror-gitlab/app/controllers/import/gitea_controller.rb

58 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class Import::GiteaController < Import::GithubController
2019-05-18 00:54:41 +05:30
extend ::Gitlab::Utils::Override
2017-08-17 22:00:37 +05:30
def new
2019-05-18 00:54:41 +05:30
if session[access_token_key].present? && provider_url.present?
2017-08-17 22:00:37 +05:30
redirect_to status_import_url
end
end
def personal_access_token
session[host_key] = params[host_key]
super
end
2019-05-18 00:54:41 +05:30
# Must be defined or it will 404
2017-08-17 22:00:37 +05:30
def status
super
end
private
def host_key
:"#{provider}_host_url"
end
2019-05-18 00:54:41 +05:30
override :provider
2017-08-17 22:00:37 +05:30
def provider
:gitea
end
2019-05-18 00:54:41 +05:30
override :provider_url
def provider_url
session[host_key]
end
2017-08-17 22:00:37 +05:30
# Gitea is not yet an OAuth provider
# See https://github.com/go-gitea/gitea/issues/27
2019-05-18 00:54:41 +05:30
override :logged_in_with_provider?
2017-08-17 22:00:37 +05:30
def logged_in_with_provider?
false
end
2019-05-18 00:54:41 +05:30
override :provider_auth
2017-08-17 22:00:37 +05:30
def provider_auth
2019-05-18 00:54:41 +05:30
if session[access_token_key].blank? || provider_url.blank?
2017-08-17 22:00:37 +05:30
redirect_to new_import_gitea_url,
2019-05-18 00:54:41 +05:30
alert: _('You need to specify both an Access Token and a Host URL.')
2017-08-17 22:00:37 +05:30
end
end
2019-05-18 00:54:41 +05:30
override :client_options
2017-08-17 22:00:37 +05:30
def client_options
2019-05-18 00:54:41 +05:30
{ host: provider_url, api_version: 'v1' }
2017-08-17 22:00:37 +05:30
end
end