修复:请求gitea接口需获取当前用户token

This commit is contained in:
yystopf 2023-03-09 15:37:38 +08:00
parent d7c1ce7595
commit 00eda17c2c
1 changed files with 18 additions and 18 deletions

View File

@ -880,9 +880,9 @@ class ApplicationController < ActionController::Base
}.to_json
resp_body = Blockchain::InvokeBlockchainApi.call(params)
if resp_body['status'] == 10
raise Error, resp_body['message']
raise ApplicationService::Error, resp_body['message']
elsif resp_body['status'] != 0
raise Error, "区块链接口请求失败."
raise ApplicationService::Error, "区块链接口请求失败."
end
elsif activity_type == "issue_comment_create"
@ -951,9 +951,9 @@ class ApplicationController < ActionController::Base
# 调用区块链接口
resp_body = Blockchain::InvokeBlockchainApi.call(params)
if resp_body['status'] == 10
raise Error, resp_body['message']
raise ApplicationService::Error, resp_body['message']
elsif resp_body['status'] != 0
raise Error, "区块链接口请求失败."
raise ApplicationService::Error, "区块链接口请求失败."
end
elsif activity_type == "pull_request_create"
# 调用区块链接口
@ -989,9 +989,9 @@ class ApplicationController < ActionController::Base
updated_at = model['updated_at']
# 查询pull request对应的commit信息
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'])
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'], current_user&.gitea_token)
if commits.nil?
raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
raise ApplicationService::Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
end
commit_shas = []
commits.each do |c|
@ -1018,9 +1018,9 @@ class ApplicationController < ActionController::Base
}.to_json
resp_body = Blockchain::InvokeBlockchainApi.call(params)
if resp_body['status'] == 9
raise Error, resp_body['message']
raise ApplicationService::Error, resp_body['message']
elsif resp_body['status'] != 0
raise Error, "区块链接口请求失败."
raise ApplicationService::Error, "区块链接口请求失败."
end
elsif activity_type == "pull_request_merge"
# 调用区块链接口
@ -1043,9 +1043,9 @@ class ApplicationController < ActionController::Base
updated_at = model['updated_at']
# 查询pull request对应的commit信息
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'])
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'], current_user&.gitea_token)
if commits.nil?
raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
raise ApplicationService::Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
end
commit_shas = []
commits.each do |c|
@ -1074,16 +1074,16 @@ class ApplicationController < ActionController::Base
}.to_json
resp_body = Blockchain::InvokeBlockchainApi.call(params)
if resp_body['status'] == 9
raise Error, resp_body['message']
raise ApplicationService::Error, resp_body['message']
elsif resp_body['status'] != 0
raise Error, "区块链接口请求失败."
raise ApplicationService::Error, "区块链接口请求失败."
end
# 将commit相关信息写入链上
commit_shas.each do |commit_sha|
commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token'])
commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token'])
commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token'], current_user&.gitea_token)
commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token'], current_user&.gitea_token)
params = {
"request-type": "upload commit info",
"commit_hash": commit_sha,
@ -1099,9 +1099,9 @@ class ApplicationController < ActionController::Base
}.to_json
resp_body = Blockchain::InvokeBlockchainApi.call(params)
if resp_body['status'] == 7
raise Error, resp_body['message']
raise ApplicationService::Error, resp_body['message']
elsif resp_body['status'] != 0
raise Error, "区块链接口请求失败."
raise ApplicationService::Error, "区块链接口请求失败."
end
end
@ -1145,9 +1145,9 @@ class ApplicationController < ActionController::Base
}.to_json
resp_body = Blockchain::InvokeBlockchainApi.call(params)
if resp_body['status'] == 9
raise Error, resp_body['message']
raise ApplicationService::Error, resp_body['message']
elsif resp_body['status'] != 0
raise Error, "区块链接口请求失败."
raise ApplicationService::Error, "区块链接口请求失败."
end
end
end