Browse Source

add: project trace tasks count

pull/313/head
yystopf 4 years ago
parent
commit
7750cbe272
4 changed files with 20 additions and 21 deletions
  1. +3
    -3
      app/controllers/traces/projects_controller.rb
  2. +12
    -13
      app/models/trace_user.rb
  3. +0
    -5
      db/migrate/20220511022334_add_tasks_count_to_trace_users.rb
  4. +5
    -0
      db/migrate/20220511031711_add_trace_tasks_count_to_projects.rb

+ 3
- 3
app/controllers/traces/projects_controller.rb 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}")


+ 12
- 13
app/models/trace_user.rb View File

@@ -2,19 +2,18 @@
#
# Table name: trace_users
#
# id :integer not null, primary key
# user_id :integer
# username :string(255)
# password :string(255)
# unit :string(255)
# telnumber :string(255)
# email :string(255)
# name :string(255)
# token :text(65535)
# expired_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# tasks_count :integer default("0")
# id :integer not null, primary key
# user_id :integer
# username :string(255)
# password :string(255)
# unit :string(255)
# telnumber :string(255)
# email :string(255)
# name :string(255)
# token :text(65535)
# expired_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#


+ 0
- 5
db/migrate/20220511022334_add_tasks_count_to_trace_users.rb View File

@@ -1,5 +0,0 @@
class AddTasksCountToTraceUsers < ActiveRecord::Migration[5.2]
def change
add_column :trace_users, :tasks_count, :integer, default: 0
end
end

+ 5
- 0
db/migrate/20220511031711_add_trace_tasks_count_to_projects.rb View File

@@ -0,0 +1,5 @@
class AddTraceTasksCountToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :trace_tasks_count, :integer, default: 0
end
end

Loading…
Cancel
Save