forked from Gitlink/forgeplus
remove all of chain related codes
This commit is contained in:
parent
d586f526c9
commit
058c962d05
|
@ -106,18 +106,7 @@ class IssuesController < ApplicationController
|
|||
normal_status(-1, "标题不能超过255个字符")
|
||||
elsif (params[:issue_type].to_s == "2")
|
||||
return normal_status(-1, "悬赏的奖金必须大于0") if params[:token].to_i == 0
|
||||
#查看当前用户的积分
|
||||
query_params = {
|
||||
type: "query",
|
||||
chain_params: {
|
||||
reponame: @project.try(:identifer),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
}
|
||||
|
||||
response = Gitea::Chain::ChainGetService.new(query_params).call
|
||||
return normal_status(-1, "获取token失败,请稍后重试") if response.status != 200
|
||||
return normal_status(-1, "您的token值不足") if response.body["balance"].to_i < params[:token].to_i
|
||||
else
|
||||
issue_params = issue_send_params(params)
|
||||
|
||||
|
@ -146,19 +135,6 @@ class IssuesController < ApplicationController
|
|||
tiding_type: 'issue', status: 0)
|
||||
end
|
||||
|
||||
#为悬赏任务时, 扣除当前用户的积分
|
||||
if params[:issue_type].to_s == "2"
|
||||
change_params = {
|
||||
type: "minus",
|
||||
chain_params: {
|
||||
amount: params[:token],
|
||||
reponame: @project.try(:identifer),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
}
|
||||
PostChainJob.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
|
||||
|
@ -221,25 +197,6 @@ class IssuesController < ApplicationController
|
|||
@issue.update_closed_issues_count_in_project!
|
||||
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 ? "add" : "minus"
|
||||
change_params = {
|
||||
type: change_type,
|
||||
chain_params: {
|
||||
amount: change_token.abs,
|
||||
reponame: @project.try(:identifer),
|
||||
username: current_user.try(:login)
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(change_params)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id)
|
||||
normal_status(0, "更新成功")
|
||||
else
|
||||
|
@ -323,8 +280,8 @@ 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?)
|
||||
# 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 = "关闭"
|
||||
|
@ -337,17 +294,6 @@ class IssuesController < ApplicationController
|
|||
if type == 5
|
||||
@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 = {
|
||||
type: "add",
|
||||
chain_params: {
|
||||
amount: tokens,
|
||||
reponame: @project.try(:identifer),
|
||||
username: @issue.get_assign_user.try(:login)
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(change_params)
|
||||
end
|
||||
if @issue.issue_classify.to_s == "pull_request"
|
||||
@issue&.pull_request&.update_attribute(:status, 2)
|
||||
|
|
|
@ -95,22 +95,7 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def repo_hook
|
||||
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: "upload",
|
||||
chain_params: uploadPushInfo
|
||||
}
|
||||
PostChainJob.perform_later(chain_params)
|
||||
@project.update_attribute(:token, @project.token + uploadPushInfo[:modificationLines].to_i)
|
||||
|
||||
end
|
||||
|
||||
def sync_mirror
|
||||
|
@ -159,24 +144,24 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
|
||||
def hook_params(hook_type, params)
|
||||
if hook_type == "push"
|
||||
# TODO hook返回的记录中,暂时没有文件代码数量的增减,暂时根据 commits数量来计算
|
||||
uploadPushInfo = {
|
||||
"sha": params["commits"].present? ? params["commits"].last : "",
|
||||
"branch": params["ref"].to_s.split("/").last,
|
||||
"modification_lines": params["commits"].length
|
||||
}
|
||||
elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作
|
||||
uploadPushInfo = {
|
||||
"branch": params["base"]["ref"].to_s.split("/").last,
|
||||
"sha": params["pull_request"]["merge_base"],
|
||||
"modification_lines": 1 #pull_request中没有commits数量
|
||||
}
|
||||
else
|
||||
uploadPushInfo = {}
|
||||
end
|
||||
# if hook_type == "push"
|
||||
# # TODO hook返回的记录中,暂时没有文件代码数量的增减,暂时根据 commits数量来计算
|
||||
# uploadPushInfo = {
|
||||
# "sha": params["commits"].present? ? params["commits"].last : "",
|
||||
# "branch": params["ref"].to_s.split("/").last,
|
||||
# "modification_lines": params["commits"].length
|
||||
# }
|
||||
# elsif hook_type == "pull_request" && params["action"].to_s == "closed" #合并请求合并后才会有上链操作
|
||||
# uploadPushInfo = {
|
||||
# "branch": params["base"]["ref"].to_s.split("/").last,
|
||||
# "sha": params["pull_request"]["merge_base"],
|
||||
# "modification_lines": 1 #pull_request中没有commits数量
|
||||
# }
|
||||
# else
|
||||
# uploadPushInfo = {}
|
||||
# end
|
||||
|
||||
uploadPushInfo
|
||||
# uploadPushInfo
|
||||
end
|
||||
|
||||
def create_new_pr(params)
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
class ChangeTokenJob < ApplicationJob
|
||||
# queue_as :default
|
||||
|
||||
# def perform(change_params)
|
||||
# status = 0
|
||||
# 5.times do |i|
|
||||
# if status == 200
|
||||
# Rails.logger.info("########_change_user_toke_success_user:__#{change_params[:username]}_try:_#{i+1}_")
|
||||
# break
|
||||
# else
|
||||
# Rails.logger.info("########_change_user_toke_try:_#{i+1}_")
|
||||
# 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
|
||||
# unless status == 200
|
||||
# Rails.logger.info("########_change_user_toke_failed__change_params:__#{change_params}_")
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
class PostChainJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
#注 pull_request的 api文档有问题,字段未明确,所以暂时关于pr的参数应该有问题。6-8,hs
|
||||
def perform(chain_params)
|
||||
status = false
|
||||
chain_type = chain_params[:type].to_s
|
||||
reponame = chain_params[:chain_params][:reponame]
|
||||
5.times do |i|
|
||||
if status
|
||||
break
|
||||
else
|
||||
response = Gitea::Chain::ChainPostService(chain_params)
|
||||
if response.status == 200
|
||||
reponse_body = response&.body
|
||||
messages = reponse_body.present? ? JSON.parse(reponse_body) : "success"
|
||||
status = true
|
||||
Rails.logger.info("################_repository__#{reponame}______create_chain_success_try:_#{i+1}_message__:#{messages}__")
|
||||
else
|
||||
Rails.logger.info("########_repository__#{reponame}______create_chain_failed__try:_#{i+1}_")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
class ProjectCreateChainJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
#可以去掉
|
||||
|
||||
# def perform(chain_params)
|
||||
# status = false
|
||||
# chain_type = chain_params[:type].to_s
|
||||
# reponame = chain_params[:reponame]
|
||||
|
||||
# 5.times do |i|
|
||||
# if status
|
||||
# Rails.logger.info("########_repository__#{reponame}______create_chain_success__try:_#{i+1}_")
|
||||
# break
|
||||
# else
|
||||
# Rails.logger.info("########_repository__#{reponame}______start_to_create_chain__try:_#{i+1}_")
|
||||
# if chain_type == "create"
|
||||
# chain_status = create_chain(chain_params)
|
||||
# elsif chain_type == "push"
|
||||
# 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 == 200
|
||||
# Rails.logger.info("########_repository__#{reponame}__create_chain:___#{chain_status}____failed_to_create_chain__")
|
||||
# end
|
||||
# end
|
||||
|
||||
# private
|
||||
|
||||
# #创建项目的上链操作
|
||||
# def create_chain(chain_params)
|
||||
# result = `chain trustieCreate #{chain_params[:ownername]} #{chain_params[:reponame]}`
|
||||
# return eval(result)
|
||||
# end
|
||||
|
||||
# # push项目的上链操作
|
||||
# def push_chain(chain_params)
|
||||
# result = `chain trustiePush #{chain_params[:ownername]} #{chain_params[:reponame]} #{chain_params[:username]} #{chain_params[:uploadPushInfo]}`
|
||||
# return eval(result)
|
||||
# end
|
||||
end
|
|
@ -1,29 +0,0 @@
|
|||
class Gitea::Chain::ChainGetService < Gitea::ChainService
|
||||
|
||||
attr_reader :params
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
get(url, request_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_params
|
||||
Hash.new.merge(data: params["chain_params"])
|
||||
end
|
||||
|
||||
def url
|
||||
chain_type = params["type"].to_s
|
||||
case chain_type
|
||||
when "query"
|
||||
"/repos/amount/query".freeze
|
||||
else
|
||||
"".freeze
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
class Gitea::Chain::ChainPostService < Gitea::ChainService
|
||||
|
||||
attr_reader :params
|
||||
|
||||
def initialize(params)
|
||||
@params = params
|
||||
end
|
||||
|
||||
def call
|
||||
post(url, request_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_params
|
||||
Hash.new.merge(data: params["chain_params"])
|
||||
end
|
||||
|
||||
def url
|
||||
chain_type = params["type"].to_s
|
||||
case chain_type
|
||||
when "create"
|
||||
"/repos/create".freeze
|
||||
when "upload"
|
||||
"/repos/commit/upload".freeze
|
||||
else #由于目前的api文档操作post请求,除了create/upload,都是在/repos/amount/*,所以以下简化了
|
||||
"/repos/amount/#{chain_type}".freeze
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,47 +0,0 @@
|
|||
class Gitea::ChainService < ApplicationService
|
||||
attr_reader :url, :params
|
||||
|
||||
def initialize(options={})
|
||||
@url = options[:url]
|
||||
@params = options[:params]
|
||||
end
|
||||
|
||||
def post(url, params={})
|
||||
Rails.logger.info("######_____api____request_url_______###############{request_url}")
|
||||
Rails.logger.info("######_____api____request_params_______###############{params}")
|
||||
|
||||
conn.post do |req|
|
||||
req.url "#{request_url}"
|
||||
req.body = params[:data].to_json
|
||||
end
|
||||
end
|
||||
|
||||
def get(url, params={})
|
||||
conn.get do |req|
|
||||
req.url = "#{request_url}"
|
||||
req.body = params[:data].to_json
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def conn(auth={})
|
||||
@client ||= begin
|
||||
Faraday.new(url: domain) do |req|
|
||||
req.request :url_encoded
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
req.response :logger # 显示日志
|
||||
req.adapter Faraday.default_adapter
|
||||
end
|
||||
end
|
||||
@client
|
||||
end
|
||||
|
||||
def domain
|
||||
Rails.application.config_for(:configuration)['chain_base']
|
||||
end
|
||||
|
||||
def request_url
|
||||
[domain, url].join('').freeze
|
||||
end
|
||||
|
||||
end
|
|
@ -14,18 +14,6 @@ class Repositories::CreateService < ApplicationService
|
|||
gitea_repository = Gitea::Repository::CreateService.new(user.gitea_token, gitea_repository_params).call
|
||||
sync_project(@repository, gitea_repository)
|
||||
sync_repository(@repository, gitea_repository)
|
||||
if project.project_type == "common"
|
||||
chain_params = {
|
||||
type: "create",
|
||||
chain_params:{
|
||||
username: user.try(:login),
|
||||
reponame: @repository.try(:identifier),
|
||||
token_name: @repository.try(:identifier),
|
||||
total_supply: 0
|
||||
}
|
||||
}
|
||||
PostChainJob.perform_later(chain_params) #创建上链操作
|
||||
end
|
||||
end
|
||||
@repository
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue