You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1019 B
46 lines
1019 B
# Merge a pull request
|
|
class Gitea::PullRequest::MergeService < Gitea::ClientService
|
|
attr_reader :user, :repo, :pull_request_id, :params
|
|
|
|
# parameters:
|
|
# repo: name of the repo
|
|
# pull_request_id: index of the pull request to merge
|
|
# params:
|
|
# title: merge标题
|
|
# message: merge说明
|
|
def initialize(user, repo, pull_request_id, params={})
|
|
@user = user
|
|
@repo = repo
|
|
@params = params
|
|
@pull_request_id = pull_request_id
|
|
end
|
|
|
|
def call
|
|
response = post(url, request_params)
|
|
render_status(response)
|
|
end
|
|
|
|
private
|
|
def url
|
|
"/repos/#{user.login}/#{repo}/pulls/#{pull_request_id}/merge"
|
|
end
|
|
|
|
def request_params
|
|
Hash.new.merge(token: user.gitea_token, data: params)
|
|
end
|
|
|
|
def render_status(response)
|
|
case response.status
|
|
when 404
|
|
raise Error, "合并请求不存在"
|
|
else
|
|
if response.body.size > 0
|
|
JSON.parse(response&.body)
|
|
else
|
|
{status: 200}
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|