FIX merge pr's bug

This commit is contained in:
Jasder 2020-07-03 16:23:06 +08:00
parent 04f98f1c10
commit 795e06f6c5
2 changed files with 11 additions and 6 deletions

View File

@ -181,6 +181,8 @@ class PullRequestsController < ApplicationController
end
def pr_merge
return render_forbidden("你没有权限操作.") if @project.reporter?(current_user)
if params[:do].blank?
normal_status(-1, "请选择合并方式")
else
@ -191,7 +193,8 @@ class PullRequestsController < ApplicationController
MergeMessageField: params[:body],
MergeTitleField: params[:title]
}
merge_pr = Gitea::PullRequest::MergeService.new(current_user, @repository.try(:identifier), @pull_request.try(:gpid), requests_params).call
merge_pr = Gitea::PullRequest::MergeService.call(current_user.gitea_token, @repository.owner.login,
@repository.try(:identifier), @pull_request.try(:gpid), requests_params)
if @pull_request.update_attribute(:status, 1) && merge_pr[:status].to_i == 200
@pull_request&.project_trends&.update_all(action_type: "close")
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)

View File

@ -1,6 +1,6 @@
# Merge a pull request
class Gitea::PullRequest::MergeService < Gitea::ClientService
attr_reader :user, :repo, :pull_request_id, :params
attr_reader :token, :owner, :repo, :pull_request_id, :params
# parameters:
# repo: name of the repo
@ -8,8 +8,10 @@ class Gitea::PullRequest::MergeService < Gitea::ClientService
# params:
# title: merge标题
# message: merge说明
def initialize(user, repo, pull_request_id, params={})
@user = user
# eq: Gitea::PullRequest::MergeService.call(current_user.gitea_token, @repo.owner.lgoin, @repo.identifier, params)
def initialize(token, owner, repo, pull_request_id, params={})
@token = token
@owner = owner
@repo = repo
@params = params
@pull_request_id = pull_request_id
@ -21,11 +23,11 @@ class Gitea::PullRequest::MergeService < Gitea::ClientService
private
def url
"/repos/#{user.login}/#{repo}/pulls/#{pull_request_id}/merge"
"/repos/#{owner}/#{repo}/pulls/#{pull_request_id}/merge"
end
def request_params
Hash.new.merge(token: user.gitea_token, data: params)
Hash.new.merge(token: token, data: params)
end
end