mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-21 20:25:45 +08:00
增加chain的积分操作和上链操作
This commit is contained in:
@@ -104,8 +104,14 @@ class IssuesController < ApplicationController
|
||||
normal_status(-1, "标题不能为空")
|
||||
elsif params[:subject].to_s.size > 255
|
||||
normal_status(-1, "标题不能超过255个字符")
|
||||
elsif (params[:issue_type].to_s == "2") && params[:token].to_i == 0
|
||||
normal_status(-1, "悬赏的奖金必须大于0")
|
||||
elsif (params[:issue_type].to_s == "2")
|
||||
return normal_status(-1, "悬赏的奖金必须大于0")if params[:token].to_i == 0
|
||||
#查看当前用户的积分
|
||||
query_params = {
|
||||
type: "user"
|
||||
}.merge(tokens_params(@project))
|
||||
user_tokens = Gitea::Repository::Hooks::QueryService.new(query_params).call
|
||||
return normal_status(-1, "悬赏的奖金不足") if user_tokens[:value].to_i < params[:token].to_i
|
||||
else
|
||||
issue_params = issue_send_params(params)
|
||||
|
||||
@@ -133,6 +139,16 @@ class IssuesController < ApplicationController
|
||||
parent_container_id: @project.id, parent_container_type: "Project",
|
||||
tiding_type: 'issue', status: 0)
|
||||
end
|
||||
|
||||
#为悬赏任务时, 扣除当前用户的积分
|
||||
if params[:issue_type].to_s == "2"
|
||||
change_params = {
|
||||
change_type: "minusToken",
|
||||
tokens: params[:token]
|
||||
}.merge(tokens_params(@proeject))
|
||||
ChangeTokenJob.perform_later(change_params)
|
||||
end
|
||||
|
||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
normal_status(0, "创建成功")
|
||||
else
|
||||
@@ -150,6 +166,7 @@ class IssuesController < ApplicationController
|
||||
|
||||
def update
|
||||
issue_params = issue_send_params(params).except("issue_classify", "author_id", "project_id")
|
||||
return normal_status(-1, "您没有权限修改token") if @issue.will_save_change_to_token? && @issue.user_id !== current_user&.id
|
||||
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
|
||||
@issue&.issue_tags_relates&.destroy_all
|
||||
params[:issue_tag_ids].each do |tag|
|
||||
@@ -193,6 +210,21 @@ class IssuesController < ApplicationController
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
end
|
||||
|
||||
if @issue.issue_type.to_s == "2"
|
||||
#表示修改token值
|
||||
if @issue.saved_change_to_attribute("token")
|
||||
last_token = @issue.token_was
|
||||
change_token = last_token - @issue.token
|
||||
change_type = change_token > 0 ? "addToken" : "minusToken"
|
||||
change_params = {
|
||||
change_type: change_type,
|
||||
tokens: change_token.abs
|
||||
}.merge(tokens_params(@proeject))
|
||||
ChangeTokenJob.perform_later(change_params)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id)
|
||||
normal_status(0, "更新成功")
|
||||
else
|
||||
@@ -243,6 +275,9 @@ class IssuesController < ApplicationController
|
||||
|
||||
def close_issue
|
||||
type = params[:status_id].to_i || 5
|
||||
return normal_status(-1, "悬赏工单不允许再次打开") if @issue.issue_type.to_s == "2" && @issue.status_id.to_i == 5
|
||||
return normal_status(-1, "您没有权限操作") if @issue.issue_type.to_s == "2" && (@issue.user_id !== current_user&.id || !current_user&.admin?)
|
||||
|
||||
if type == 5
|
||||
message = "关闭"
|
||||
old_message = "重新开启"
|
||||
@@ -255,6 +290,17 @@ class IssuesController < ApplicationController
|
||||
@issue&.project_trends&.update_all(action_type: "close")
|
||||
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
if @issue.issue_type.to_s == "2"
|
||||
tokens = @issue.token
|
||||
change_params = {
|
||||
change_type: "addToken",
|
||||
tokens: tokens,
|
||||
ownername: project.owner.try(:login),
|
||||
reponame: project.try(:identifer),
|
||||
username: @issue.get_assign_user.try(:login) #指派人增加积分
|
||||
}
|
||||
ChangeTokenJob.perform_later(change_params)
|
||||
end
|
||||
else
|
||||
@issue&.project_trends&.update_all(action_type: "create")
|
||||
end
|
||||
@@ -264,7 +310,6 @@ class IssuesController < ApplicationController
|
||||
close_message = "close_pr"
|
||||
end
|
||||
@issue.custom_journal_detail(close_message,old_message, "#{message}", current_user&.id)
|
||||
|
||||
normal_status(0, message)
|
||||
else
|
||||
normal_status(-1, "操作失败")
|
||||
@@ -381,4 +426,13 @@ class IssuesController < ApplicationController
|
||||
project_id: @project.id
|
||||
}
|
||||
end
|
||||
|
||||
def tokens_params(project)
|
||||
{
|
||||
ownername: project.owner.try(:login),
|
||||
reponame: project.try(:identifer),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,7 +124,22 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def repo_hook
|
||||
Rails.logger.info("#####______222________########")
|
||||
hook_type = request.headers["X-Gitea-Event"].to_s # 获取推送的方式
|
||||
ownername = @project.owner.try(:login)
|
||||
reponame = @project.identifier
|
||||
username = current_user.try(:login)
|
||||
user_params = {
|
||||
"ownername": ownername,
|
||||
"username": username,
|
||||
"reponame": reponame
|
||||
}
|
||||
uploadPushInfo = hook_params(hook_type, params).merge(user_params)
|
||||
chain_params = {
|
||||
type: hook_type,
|
||||
uploadPushInfo: uploadPushInfo
|
||||
}.merge(user_params)
|
||||
ProjectCreateChainJob.perform_later(chain_params)
|
||||
@project.update_attribute(:token, @project.token + uploadPushInfo[:modificationLines].to_i)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -151,4 +166,28 @@ class RepositoriesController < ApplicationController
|
||||
}
|
||||
end
|
||||
|
||||
def hook_params(hook_type, params)
|
||||
if hook_type == "push"
|
||||
# TODO hook返回的记录中,暂时没有文件代码数量的增减,暂时根据 commits数量来计算
|
||||
uploadPushInfo = {
|
||||
"shas": params["commits"].map{|c| c["id"]} if params["commits"].present?,
|
||||
"branch": params["ref"].to_s.split("/").last,
|
||||
"modificationLines": params["commits"].length
|
||||
}
|
||||
elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作
|
||||
uploadPushInfo = {
|
||||
"source_branch": params["head"]["ref"].to_s.split("/").last,
|
||||
"target_branch": params["base"]["ref"].to_s.split("/").last,
|
||||
"source_project_id": params["head"]["repo_id"].to_i, #现在是为gitea上仓库的id
|
||||
"target_project_id": params["base"]["repo_id"].to_i,
|
||||
"shas": [params["pull_request"]["merge_commit_sha"], params["pull_request"]["merge_base"]],
|
||||
"modificationLines": 1 #pull_request中没有commits数量
|
||||
}
|
||||
else
|
||||
uploadPushInfo = {}
|
||||
end
|
||||
|
||||
return uploadPushInfo
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user