mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
FIX pull request bug
This commit is contained in:
33
app/services/pull_requests/close_service.rb
Normal file
33
app/services/pull_requests/close_service.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class PullRequests::CloseService < ApplicationService
|
||||
attr_reader :owner, :repo, :pull, :current_user
|
||||
|
||||
# eq:
|
||||
# PullRequests::CloseService.call(owner, repo, pull, current_user)
|
||||
def initialize(owner, repo, pull, current_user)
|
||||
@owner = owner
|
||||
@repo = repo
|
||||
@pull = pull
|
||||
@current_user = current_user
|
||||
end
|
||||
|
||||
def call
|
||||
ActiveRecord::Base.transaction do
|
||||
return false if close_gitea_pull[:status] != :success
|
||||
|
||||
update_pull_status!
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def close_gitea_pull
|
||||
Gitea::PullRequest::CloseService.call(@owner.login, @repo.identifier,
|
||||
@pull.gpid, @pull.base, current_user.gitea_token)
|
||||
end
|
||||
|
||||
def update_pull_status!
|
||||
@pull.update(status: PullRequest::CLOSED)
|
||||
@pull.issue.update(status_id: IssueStatus::CLOSED)
|
||||
end
|
||||
end
|
||||
36
app/services/pull_requests/merge_service.rb
Normal file
36
app/services/pull_requests/merge_service.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class PullRequests::MergeService < ApplicationService
|
||||
attr_reader :owner, :repo, :pull, :current_user, :params
|
||||
|
||||
# eq:
|
||||
# PullRequests::MergeService.call(owner, repo, pull, current_user, params)
|
||||
def initialize(owner, repo, pull, current_user, params)
|
||||
@owner = owner
|
||||
@repo = repo
|
||||
@pull = pull
|
||||
@current_user = current_user
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
ActiveRecord::Base.transaction do
|
||||
gitea_pull_merge!
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def gitea_merge_pull_params
|
||||
{
|
||||
Do: params[:do],
|
||||
MergeMessageField: params[:body],
|
||||
MergeTitleField: params[:title]
|
||||
}
|
||||
end
|
||||
end
|
||||
33
app/services/pull_requests/open_service.rb
Normal file
33
app/services/pull_requests/open_service.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class PullRequests::OpenService < ApplicationService
|
||||
attr_reader :owner, :repo, :pull, :current_user
|
||||
|
||||
# eq:
|
||||
# PullRequests::OpenService.call(owner, repo, pull, current_user)
|
||||
def initialize(owner, repo, pull, current_user)
|
||||
@owner = owner
|
||||
@repo = repo
|
||||
@pull = pull
|
||||
@current_user = current_user
|
||||
end
|
||||
|
||||
def call
|
||||
ActiveRecord::Base.transaction do
|
||||
return false if open_gitea_pull[:status] != :success
|
||||
|
||||
update_pull_status!
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def open_gitea_pull
|
||||
Gitea::PullRequest::OpenService.call(@owner.login, @repo.identifier,
|
||||
@pull.gpid, @pull.base, @current_user.gitea_token)
|
||||
end
|
||||
|
||||
def update_pull_status!
|
||||
@pull.update(status: PullRequest::OPEN)
|
||||
@pull.issue.update(status_id: IssueStatus::SOLVING)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user