2018-09-23 15:44:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-15 11:31:14 -05:00
|
|
|
class Import::GiteaController < Import::GithubController
|
2018-11-07 11:44:21 -05:00
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
|
2016-12-15 11:31:14 -05:00
|
|
|
def new
|
2018-11-07 11:44:21 -05:00
|
|
|
if session[access_token_key].present? && provider_url.present?
|
2016-12-15 11:31:14 -05:00
|
|
|
redirect_to status_import_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def personal_access_token
|
2016-12-16 11:43:34 -05:00
|
|
|
session[host_key] = params[host_key]
|
2016-12-15 11:31:14 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-11-07 11:44:21 -05:00
|
|
|
# Must be defined or it will 404
|
2016-12-15 11:31:14 -05:00
|
|
|
def status
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-12-16 11:43:34 -05:00
|
|
|
def host_key
|
|
|
|
:"#{provider}_host_url"
|
|
|
|
end
|
|
|
|
|
2018-11-07 11:44:21 -05:00
|
|
|
override :provider
|
2016-12-15 11:31:14 -05:00
|
|
|
def provider
|
|
|
|
:gitea
|
|
|
|
end
|
|
|
|
|
2018-11-07 11:44:21 -05:00
|
|
|
override :provider_url
|
|
|
|
def provider_url
|
|
|
|
session[host_key]
|
|
|
|
end
|
|
|
|
|
2016-12-15 11:31:14 -05:00
|
|
|
# Gitea is not yet an OAuth provider
|
|
|
|
# See https://github.com/go-gitea/gitea/issues/27
|
2018-11-07 11:44:21 -05:00
|
|
|
override :logged_in_with_provider?
|
2016-12-15 11:31:14 -05:00
|
|
|
def logged_in_with_provider?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-11-07 11:44:21 -05:00
|
|
|
override :provider_auth
|
2016-12-15 11:31:14 -05:00
|
|
|
def provider_auth
|
2018-11-07 11:44:21 -05:00
|
|
|
if session[access_token_key].blank? || provider_url.blank?
|
2016-12-15 11:31:14 -05:00
|
|
|
redirect_to new_import_gitea_url,
|
2019-03-27 12:52:52 -04:00
|
|
|
alert: _('You need to specify both an Access Token and a Host URL.')
|
2016-12-15 11:31:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-07 11:44:21 -05:00
|
|
|
override :client_options
|
2016-12-15 11:31:14 -05:00
|
|
|
def client_options
|
2018-11-07 11:44:21 -05:00
|
|
|
{ host: provider_url, api_version: 'v1' }
|
2016-12-15 11:31:14 -05:00
|
|
|
end
|
|
|
|
end
|