forked from Gitlink/forgeplus
add: gitea response process
This commit is contained in:
parent
b22330d146
commit
a9c0d18a5f
|
@ -149,12 +149,12 @@ class PullRequestsController < ApplicationController
|
|||
begin
|
||||
result = PullRequests::MergeService.call(@owner, @repository, @pull_request, current_user, params)
|
||||
|
||||
if result && @pull_request.merge!
|
||||
if result.status == 200 && @pull_request.merge!
|
||||
@pull_request.project_trend_status!
|
||||
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
||||
normal_status(1, "合并成功")
|
||||
else
|
||||
normal_status(-1, "合并失败")
|
||||
normal_status(-1, result.message)
|
||||
end
|
||||
rescue => e
|
||||
normal_status(-1, e.message)
|
||||
|
|
|
@ -176,6 +176,25 @@ class Gitea::ClientService < ApplicationService
|
|||
[status, message, body]
|
||||
end
|
||||
|
||||
def render_gitea_response(response)
|
||||
status = response.status
|
||||
body = response&.body
|
||||
|
||||
log_error(status, body)
|
||||
message = nil
|
||||
begin
|
||||
translate = YAML.load(File.read('config/gitea_response.yml'))
|
||||
|
||||
self.class.to_s.underscore.split("/").map{|i| translate=translate[i]}
|
||||
message = body.nil? ? translate[status]['default'] : JSON.parse(body)['message']
|
||||
message = translate[status][message].nil? ? message : translate[status][message]
|
||||
|
||||
return [status, message]
|
||||
rescue
|
||||
return [status, message]
|
||||
end
|
||||
end
|
||||
|
||||
def get_body_by_status(status, body)
|
||||
body, message =
|
||||
case status
|
||||
|
|
|
@ -20,7 +20,7 @@ class Gitea::PullRequest::MergeService < Gitea::ClientService
|
|||
def call
|
||||
response = post(url, request_params)
|
||||
|
||||
render_200_no_body(response)
|
||||
render_gitea_response(response)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class PullRequests::MergeService < ApplicationService
|
||||
attr_reader :owner, :repo, :pull, :current_user, :params
|
||||
|
||||
attr_accessor :status, :message
|
||||
# eq:
|
||||
# PullRequests::MergeService.call(owner, repo, pull, current_user, params)
|
||||
def initialize(owner, repo, pull, current_user, params)
|
||||
|
@ -15,6 +15,7 @@ class PullRequests::MergeService < ApplicationService
|
|||
ActiveRecord::Base.transaction do
|
||||
gitea_pull_merge!
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -22,8 +23,7 @@ class PullRequests::MergeService < ApplicationService
|
|||
def gitea_pull_merge!
|
||||
result = Gitea::PullRequest::MergeService.call(@current_user.gitea_token, @owner.login,
|
||||
@repo.identifier, @pull.gpid, gitea_merge_pull_params)
|
||||
|
||||
result[:status] === 200 ? true : false
|
||||
@status, @message = result
|
||||
end
|
||||
|
||||
def gitea_merge_pull_params
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
gitea:
|
||||
pull_request:
|
||||
merge_service:
|
||||
405:
|
||||
default: "此合并请求有变更与目标分支冲突。"
|
||||
'User not allowed to merge PR': "用户没有合并请求的权限"
|
||||
403:
|
Loading…
Reference in New Issue