Browse Source

修改chain命令及返回内容

tags/v1
sylor_huang@126.com 6 years ago
parent
commit
e3d0904e2c
3 changed files with 19 additions and 12 deletions
  1. +2
    -1
      app/jobs/change_token_job.rb
  2. +13
    -7
      app/jobs/project_create_chain_job.rb
  3. +4
    -4
      app/services/gitea/repository/hooks/query_service.rb

+ 2
- 1
app/jobs/change_token_job.rb View File

@@ -9,7 +9,8 @@ class ChangeTokenJob < ApplicationJob
break
else
Rails.logger.info("########_change_user_toke_try:_#{i+1}_")
chain_status = system("chain #{change_params[:change_type]} #{change_params[:ownername]} #{change_params[:reponame]} #{change_params[:username]} #{change_params[:tokens].to_i}")
chain_status = `chain #{change_params[:change_type]} #{change_params[:ownername]} #{change_params[:reponame]} #{change_params[:username]} #{change_params[:tokens].to_i}`
chain_status = eval(chain_status)
status = chain_status[:status].to_i
end
end


+ 13
- 7
app/jobs/project_create_chain_job.rb View File

@@ -5,7 +5,6 @@ class ProjectCreateChainJob < ApplicationJob
status = false
chain_type = chain_params[:type].to_s
reponame = chain_params[:reponame]
Rails.logger.info("########_chain_params:________#{chain_params}")

5.times do |i|
if status
@@ -14,15 +13,20 @@ class ProjectCreateChainJob < ApplicationJob
else
Rails.logger.info("########_repository__#{reponame}______start_to_create_chain__try:_#{i+1}_")
if chain_type == "create"
status = create_chain(chain_params)
chain_status = create_chain(chain_params)
elsif chain_type == "push"
status = push_chain(chain_params)
chain_status = push_chain(chain_params)
else
chain_status = {status: 200}
end
Rails.logger.info("########_response__chain_status__#{chain_status}__")

status = chain_status[:status].to_i
end
end

unless status
Rails.logger.info("########_repository__#{reponame}__create_chain:___#{status}____failed_to_create_chain__")
unless status == 200
Rails.logger.info("########_repository__#{reponame}__create_chain:___#{chain_status}____failed_to_create_chain__")
end
end

@@ -30,11 +34,13 @@ class ProjectCreateChainJob < ApplicationJob

#创建项目的上链操作
def create_chain(chain_params)
return system("chain trustieCreate #{chain_params[:ownername]} #{chain_params[:reponame]}")
result = `chain trustieCreate #{chain_params[:ownername]} #{chain_params[:reponame]}`
return eval(result)
end

# push项目的上链操作
def push_chain(chain_params)
return system("chain trustiePush #{chain_params[:ownername]} #{chain_params[:reponame]} #{chain_params[:username]} #{chain_params[:uploadPushInfo]}")
result = `chain trustiePush #{chain_params[:ownername]} #{chain_params[:reponame]} #{chain_params[:username]} #{chain_params[:uploadPushInfo]}`
return eval(result)
end
end

+ 4
- 4
app/services/gitea/repository/hooks/query_service.rb View File

@@ -15,18 +15,18 @@ class Gitea::Repository::Hooks::QueryService < Gitea::ClientService
def call
query_type = query_params[:type] || "user"
if query_type == "user" #查询单个用户的积分
query_result = system("chain query #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}")
query_result = `chain query #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}`

#response {status:int, message:string, value:int}
elsif query_type == "members" #查询项目全部用户的积分
query_result = system("chain getAllInfo #{query_params[:ownername]} #{query_params[:reponame]} ")
query_result = `chain getAllInfo #{query_params[:ownername]} #{query_params[:reponame]}`
#response {status:int, message:string, value:jsonObject}
else #查询用户在项目的贡献大小
query_result = system("chain getContributionPercent #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}")
query_result = `chain getContributionPercent #{query_params[:ownername]} #{query_params[:reponame]} #{query_params[:username]}`

#response {status:int, message:string, percent:int, allTokenSum:int, personalTokens:int}
end
query_result
eval(query_result)
end

end

Loading…
Cancel
Save