change check_token
This commit is contained in:
commit
4b4bb0ab14
|
@ -80,3 +80,4 @@ docker/
|
|||
educoder.sql
|
||||
redis_data/
|
||||
Dockerfile
|
||||
dump.rdb
|
|
@ -319,8 +319,6 @@ 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 = "关闭"
|
||||
|
@ -481,7 +479,7 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
|
||||
def check_token_enough
|
||||
if params[:issue_type].to_s == "2"
|
||||
if params[:issue_type].to_s == "2" && (@issue.blank? || (@issue.present? && @issue.author_id == current_user.try(:id)))
|
||||
return normal_status(-1, "悬赏的奖金必须大于0") if params[:token].to_i == 0
|
||||
query_params = {
|
||||
type: "query",
|
||||
|
|
|
@ -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,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
|
Loading…
Reference in New Issue