add: project trace tasks count

This commit is contained in:
2022-05-11 11:20:18 +08:00
parent 1f13bba52e
commit 7750cbe272
4 changed files with 20 additions and 21 deletions

View File

@@ -5,13 +5,13 @@ class Traces::ProjectsController < Traces::BaseController
def tasks
branch_name = params[:branch_name]
return render_error("无可用检测次数") if current_user.trace_user&.tasks_count >= 5
return render_error("无可用检测次数") if @project&.trace_tasks_count >= 5
return render_error("分支名不能为空!") if branch_name.blank?
@all_branches = Gitea::Repository::Branches::ListNameService.call(@project&.owner, @project.identifier)
return render_error("请输入正确的分支名!") unless @all_branches["branch_name"].include?(branch_name)
code, data, error = Trace::CheckService.call(current_user.trace_token, @project, "1", branch_name)
if code == 200
current_user.trace_user.increment!(:tasks_count, 1)
@project.increment!(:trace_tasks_count, 1)
render_ok
else
render_error("检测失败 Error:#{error}")
@@ -27,7 +27,7 @@ class Traces::ProjectsController < Traces::BaseController
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
code, data, error = Trace::CheckResultService.call(current_user.trace_token, @project, nil, page, limit)
if code == 200
current_user.trace_user.update_column(:tasks_count, data[0]["totalsize"]) if data.size > 0
@project.update_column(:trace_tasks_count, data[0]["totalsize"]) if data.size > 0
render :json => {data: data}
else
render_error("获取检测记录失败 Error:#{error}")