新增:新版gitea路由请求地址

This commit is contained in:
yystopf 2023-01-16 18:05:27 +08:00
parent 9c5d1e2900
commit 8e9c2232b0
33 changed files with 88 additions and 47 deletions

View File

@ -8,7 +8,7 @@ gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0' gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0' gem 'uglifier', '>= 1.3.0'
# gem 'coffee-rails', '~> 4.2' # gem 'coffee-rails', '~> 4.2'[p-qwa9aq]
gem 'turbolinks', '~> 5' gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5' gem 'jbuilder', '~> 2.5'
gem 'groupdate', '~> 4.1.0' gem 'groupdate', '~> 4.1.0'

View File

@ -106,6 +106,8 @@ GEM
activerecord (>= 3.1.0, < 7) activerecord (>= 3.1.0, < 7)
diff-lcs (1.3) diff-lcs (1.3)
diffy (3.3.0) diffy (3.3.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
doorkeeper (5.5.1) doorkeeper (5.5.1)
railties (>= 5) railties (>= 5)
doorkeeper-jwt (0.4.1) doorkeeper-jwt (0.4.1)
@ -127,12 +129,14 @@ GEM
execjs (2.7.0) execjs (2.7.0)
faraday (0.15.4) faraday (0.15.4)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
ffi (1.12.2) ffi (1.15.5)
font-awesome-sass (4.7.0) font-awesome-sass (4.7.0)
sass (>= 3.2) sass (>= 3.2)
fugit (1.4.1) fugit (1.4.1)
et-orbi (~> 1.1, >= 1.1.8) et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4) raabro (~> 1.4)
gitea-client (0.11.1)
rest-client (~> 2.1.0)
globalid (0.4.2) globalid (0.4.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
grape-entity (0.7.1) grape-entity (0.7.1)
@ -143,6 +147,9 @@ GEM
harmonious_dictionary (0.0.1) harmonious_dictionary (0.0.1)
hashie (3.6.0) hashie (3.6.0)
htmlentities (4.3.4) htmlentities (4.3.4)
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
i18n (1.8.2) i18n (1.8.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
io-like (0.3.1) io-like (0.3.1)
@ -180,6 +187,9 @@ GEM
mimemagic (~> 0.3.2) mimemagic (~> 0.3.2)
maruku (0.7.3) maruku (0.7.3)
method_source (0.9.2) method_source (0.9.2)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mimemagic (0.3.10) mimemagic (0.3.10)
nokogiri (~> 1) nokogiri (~> 1)
rake rake
@ -193,6 +203,7 @@ GEM
mustermann (1.1.1) mustermann (1.1.1)
ruby2_keywords (~> 0.0.1) ruby2_keywords (~> 0.0.1)
mysql2 (0.5.3) mysql2 (0.5.3)
netrc (0.11.0)
nio4r (2.5.2) nio4r (2.5.2)
nokogiri (1.10.8) nokogiri (1.10.8)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
@ -209,9 +220,21 @@ GEM
addressable (~> 2.3) addressable (~> 2.3)
nokogiri (~> 1.5) nokogiri (~> 1.5)
omniauth (~> 1.2) omniauth (~> 1.2)
omniauth-gitee (1.0.0)
omniauth (>= 1.5, < 3.0)
omniauth-oauth2 (>= 1.4.0, < 2.0)
omniauth-github (1.4.0)
omniauth (~> 1.5)
omniauth-oauth2 (>= 1.4.0, < 2.0)
omniauth-oauth2 (1.6.0) omniauth-oauth2 (1.6.0)
oauth2 (~> 1.1) oauth2 (~> 1.1)
omniauth (~> 1.9) omniauth (~> 1.9)
omniauth-rails_csrf_protection (0.1.2)
actionpack (>= 4.2)
omniauth (>= 1.3.1)
omniauth-wechat-oauth2 (0.2.2)
omniauth (>= 1.3.2)
omniauth-oauth2 (>= 1.1.1)
parallel (1.19.1) parallel (1.19.1)
parser (2.7.1.1) parser (2.7.1.1)
ast (~> 2.4.0) ast (~> 2.4.0)
@ -292,6 +315,11 @@ GEM
regexp_parser (1.7.0) regexp_parser (1.7.0)
request_store (1.5.0) request_store (1.5.0)
rack (>= 1.4) rack (>= 1.4)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
reverse_markdown (1.4.0) reverse_markdown (1.4.0)
nokogiri nokogiri
roo (2.8.3) roo (2.8.3)
@ -346,7 +374,7 @@ GEM
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3) tilt (>= 1.1, < 3)
sassc (2.2.1) sassc (2.4.0)
ffi (~> 1.9) ffi (~> 1.9)
sassc-rails (2.1.2) sassc-rails (2.1.2)
railties (>= 4.0.0) railties (>= 4.0.0)
@ -418,6 +446,9 @@ GEM
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (4.2.0) uglifier (4.2.0)
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (1.6.1) unicode-display_width (1.6.1)
web-console (3.7.0) web-console (3.7.0)
actionview (>= 5.0) actionview (>= 5.0)
@ -459,6 +490,7 @@ DEPENDENCIES
enumerize enumerize
faraday (~> 0.15.4) faraday (~> 0.15.4)
font-awesome-sass (= 4.7.0) font-awesome-sass (= 4.7.0)
gitea-client (~> 0.11.1)
grape-entity (~> 0.7.1) grape-entity (~> 0.7.1)
groupdate (~> 4.1.0) groupdate (~> 4.1.0)
harmonious_dictionary (~> 0.0.1) harmonious_dictionary (~> 0.0.1)
@ -472,7 +504,11 @@ DEPENDENCIES
oauth2 oauth2
omniauth (~> 1.9.0) omniauth (~> 1.9.0)
omniauth-cas omniauth-cas
omniauth-gitee (~> 1.0.0)
omniauth-github
omniauth-oauth2 (~> 1.6.0) omniauth-oauth2 (~> 1.6.0)
omniauth-rails_csrf_protection
omniauth-wechat-oauth2
parallel (~> 1.19, >= 1.19.1) parallel (~> 1.19, >= 1.19.1)
pdfkit pdfkit
prettier prettier
@ -512,4 +548,4 @@ DEPENDENCIES
wkhtmltopdf-binary wkhtmltopdf-binary
BUNDLED WITH BUNDLED WITH
2.1.4 2.3.26

View File

@ -18,19 +18,19 @@ class Gitea::ClientService < ApplicationService
# token: {}, # token: {},
# data: {} # data: {}
# } # }
def post(url, params={}) def post(url, params={}, is_hat=false)
puts "[gitea] request params: #{params}" puts "[gitea] request params: #{params}"
auth_token = authen_params(params[:token]) auth_token = authen_params(params[:token])
conn(auth_token).post do |req| conn(auth_token).post do |req|
req.url full_url(url) req.url full_url(url, "post", is_hat)
req.body = params[:data].to_json req.body = params[:data].to_json
end end
end end
def get(url, params={}) def get(url, params={}, is_hat = false)
auth_token = authen_params(params[:token]) auth_token = authen_params(params[:token])
conn(auth_token).get do |req| conn(auth_token).get do |req|
req.url full_url(url, 'get') req.url full_url(url, 'get', is_hat)
params.except(:token).each_pair do |key, value| params.except(:token).each_pair do |key, value|
req.params["#{key}"] = value req.params["#{key}"] = value
end end
@ -41,27 +41,27 @@ class Gitea::ClientService < ApplicationService
# end #=> 响应头 # end #=> 响应头
end end
def delete(url, params={}) def delete(url, params={}, is_hat = false)
auth_token = authen_params(params[:token]) auth_token = authen_params(params[:token])
conn(auth_token).delete do |req| conn(auth_token).delete do |req|
req.url full_url(url) req.url full_url(url, "delete", is_hat)
req.body = params[:data].to_json req.body = params[:data].to_json
end end
end end
def patch(url, params={}) def patch(url, params={}, is_hat=false)
puts "[gitea] request params: #{params}" puts "[gitea] request params: #{params}"
auth_token = authen_params(params[:token]) auth_token = authen_params(params[:token])
conn(auth_token).patch do |req| conn(auth_token).patch do |req|
req.url full_url(url) req.url full_url(url, 'patch', is_hat)
req.body = params[:data].to_json req.body = params[:data].to_json
end end
end end
def put(url, params={}) def put(url, params={}, is_hat=false)
puts "[gitea] put request params: #{params}" puts "[gitea] put request params: #{params}"
conn(authen_params(params[:token])).put do |req| conn(authen_params(params[:token])).put do |req|
req.url full_url(url) req.url full_url(url, "put", is_hat)
req.body = params[:data].to_json req.body = params[:data].to_json
end end
end end
@ -99,16 +99,20 @@ class Gitea::ClientService < ApplicationService
GiteaService.gitea_config[:base_url] GiteaService.gitea_config[:base_url]
end end
def hat_base_url
GiteaService.gitea_config[:hat_base_url]
end
def domain def domain
GiteaService.gitea_config[:domain] GiteaService.gitea_config[:domain]
end end
def api_url def api_url(is_hat=false)
[domain, base_url].join('') is_hat ? [domain, hat_base_url].join('') : [domain, base_url].join('')
end end
def full_url(api_rest, action='post') def full_url(api_rest, action='post', is_hat=false)
url = [api_url, api_rest].join('').freeze url = [api_url(is_hat), api_rest].join('').freeze
url = action === 'get' ? url : URI.escape(url) url = action === 'get' ? url : URI.escape(url)
url = URI.escape(url) unless url.ascii_only? url = URI.escape(url) unless url.ascii_only?
puts "[gitea] request url: #{url}" puts "[gitea] request url: #{url}"

View File

@ -24,7 +24,7 @@ class Gitea::Hooks::CreateService < Gitea::ClientService
end end
def call def call
response = post(url, params) response = post(url, params, true)
render_201_response(response) render_201_response(response)
end end

View File

@ -7,7 +7,7 @@ class Gitea::Organization::CreateService < Gitea::ClientService
end end
def call def call
response = post(url, request_params) response = post(url, request_params, true)
render_status(response) render_status(response)
end end

View File

@ -8,7 +8,7 @@ class Gitea::Organization::UpdateService < Gitea::ClientService
end end
def call def call
response = patch(url, request_params) response = patch(url, request_params, true)
render_status(response) render_status(response)
end end

View File

@ -16,7 +16,7 @@ class Gitea::PullRequest::CommitsService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -17,7 +17,7 @@ class Gitea::PullRequest::FilesService < Gitea::ClientService
end end
def call def call
response = get(url, params.merge(token: token)) response = get(url, params.merge(token: token), true)
render_result(response) render_result(response)
end end

View File

@ -12,7 +12,7 @@ class Gitea::PullRequest::GetService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -8,7 +8,7 @@ class Gitea::Repository::Branches::ListNameService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_200_response(response) render_200_response(response)
end end

View File

@ -7,7 +7,7 @@ class Gitea::Repository::Branches::ListSliceService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_200_response(response) render_200_response(response)
end end

View File

@ -14,7 +14,7 @@ class Gitea::Repository::Commits::CompareService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_status(response) render_status(response)
end end

View File

@ -14,7 +14,7 @@ class Gitea::Repository::Commits::FileListService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -14,7 +14,7 @@ class Gitea::Repository::Commits::GetService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_status(response) render_status(response)
end end

View File

@ -13,7 +13,7 @@ class Gitea::Repository::Commits::ListSliceService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -7,7 +7,7 @@ class Gitea::Repository::Contributors::GetService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_status(response) render_status(response)
end end

View File

@ -13,7 +13,7 @@ class Gitea::Repository::Entries::GetService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -10,7 +10,7 @@ class Gitea::Repository::Entries::ListService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -10,7 +10,7 @@ class Gitea::Repository::Files::GetService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_status(response) render_status(response)
end end

View File

@ -11,7 +11,7 @@ module Gitea
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -10,7 +10,7 @@ class Gitea::Repository::Readme::DirService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
status, message, body = render_response(response) status, message, body = render_response(response)
json_format(status, message, body) json_format(status, message, body)
end end

View File

@ -15,7 +15,7 @@ class Gitea::Repository::Readme::GetService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
status, message, body = render_response(response) status, message, body = render_response(response)
json_format(status, message, body) json_format(status, message, body)
end end

View File

@ -8,7 +8,7 @@ class Gitea::Repository::Tags::ListNameService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_200_response(response) render_200_response(response)
end end

View File

@ -11,7 +11,7 @@ class Gitea::Repository::Tags::ListService < Gitea::ClientService
end end
def call def call
response = get(url, request_params) response = get(url, request_params, true)
render_result(response) render_result(response)
end end

View File

@ -9,7 +9,7 @@ class Gitea::Repository::TransferService < Gitea::ClientService
end end
def call def call
response = post(url, request_params) response = post(url, request_params, true)
render_status(response) render_status(response)
end end

View File

@ -11,7 +11,7 @@ class Gitea::Repository::Webhooks::TasksService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_response(response) render_response(response)
end end

View File

@ -8,7 +8,7 @@ class Gitea::User::HeadmapService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_response(response) render_response(response)
end end

View File

@ -24,7 +24,7 @@ class Gitea::User::UpdateService < Gitea::ClientService
end end
def call def call
patch(url, data_params) patch(url, data_params, true)
end end
private private

View File

@ -18,7 +18,7 @@ class Gitea::Versions::CreateService < Gitea::ClientService
end end
def call def call
response = post(url, request_params) response = post(url, request_params, true)
render_status(response) render_status(response)
end end

View File

@ -12,7 +12,7 @@ class Gitea::Versions::GetService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -11,7 +11,7 @@ class Gitea::Versions::ListService < Gitea::ClientService
end end
def call def call
response = get(url, params) response = get(url, params, true)
render_result(response) render_result(response)
end end

View File

@ -19,7 +19,7 @@ class Gitea::Versions::UpdateService < Gitea::ClientService
end end
def call def call
patch(url, request_params) patch(url, request_params, true)
end end
private private

View File

@ -55,6 +55,7 @@ default: &default
access_key_secret: '' access_key_secret: ''
domain: 'https://testgit.trustie.net' domain: 'https://testgit.trustie.net'
base_url: '/api/v1' base_url: '/api/v1'
hat_base_url: '/api/hat'
accelerator: accelerator:
access_key_id: '' access_key_id: ''
access_key_secret: '' access_key_secret: ''