parent
50571cf498
commit
485267021a
@ -0,0 +1,34 @@
|
|||||||
|
module Gitea
|
||||||
|
def self.client(options={})
|
||||||
|
puts "------ init gitea -----"
|
||||||
|
username = options[:username] || Gitea.gitea_config[:access_key_id]
|
||||||
|
password = options[:password] || Gitea.gitea_config[:access_key_secret]
|
||||||
|
url = gitea_config[:domain]
|
||||||
|
|
||||||
|
puts "gitea username: #{username} -- password: #{password}"
|
||||||
|
@client ||= begin
|
||||||
|
Faraday.new(url: url) do |req|
|
||||||
|
req.request :url_encoded
|
||||||
|
req.response :logger # 显示日志
|
||||||
|
req.adapter Faraday.default_adapter
|
||||||
|
req.basic_auth(username, password)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@client
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.gitea_config
|
||||||
|
begin
|
||||||
|
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||||
|
gitea_config = config[:gitea].symbolize_keys!
|
||||||
|
raise 'gitea config missing' if gitea_config.blank?
|
||||||
|
rescue => ex
|
||||||
|
raise ex if Rails.env.production?
|
||||||
|
|
||||||
|
puts %Q{\033[33m [warning] gitea config or configuration.yml missing,
|
||||||
|
please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m}
|
||||||
|
gitea_config = {}
|
||||||
|
end
|
||||||
|
gitea_config
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue