Merge branch 'develop' of http://git.trustie.net/jasder/forgeplus into develop

This commit is contained in:
Jasder 2020-04-22 17:13:14 +08:00
commit 3e89791255
7 changed files with 63 additions and 19 deletions

View File

@ -10,9 +10,9 @@ class ProjectsController < ApplicationController
scope = Projects::ListQuery.call(params.merge(is_admin: is_admin, user_id: current_user.try(:id)))
@total_count = scope.size
@projects = paginate(scope)
scope_ids = scope.pluck(:id)
@total_count = scope_ids.size
@projects = paginate(Project.where(id: scope_ids))
end
def create

View File

@ -16,11 +16,12 @@ class Projects::ListQuery < ApplicationQuery
# else
# projects = Project.visible
# end
projects = Project.no_anomory_projects.visible
projects = Project.visible
scope = projects.includes(:project_category, :project_language, :repository, owner: :user_extension).like(params[:search])
.with_project_type(params[:project_type])
.with_project_category(params[:category_id])
.with_project_language(params[:language_id]).distinct
.with_project_language(params[:language_id])
scope = scope.no_anomory_projects.distinct
sort = params[:sort_by] || "updated_on"
sort_direction = params[:sort_direction] || "desc"

View File

@ -24,7 +24,7 @@ class Gitea::Repository::Commits::ListService < Gitea::ClientService
end
def render_result(response)
body = JSON.parse(response.body)
case response.status
when 200
result = {}
@ -33,7 +33,8 @@ class Gitea::Repository::Commits::ListService < Gitea::ClientService
total_count = headers["x-total"]
result.merge(total_count: total_count.to_i, body: body)
else
{status: -1, message: "#{body['message']}"}
nil
# {status: -1, message: "#{body['message']}"}
end
end
end

View File

@ -1,11 +1,11 @@
json.total_count @total_count
json.projects do
json.array! @projects do |project|
json.array! @projects.to_a do |project|
json.partial! 'project', project: project
json.author do
json.name project&.owner&.login
json.login project&.owner&.login
json.image_url url_to_avatar(project&.owner)
json.name project.owner.try(:show_real_name)
json.login project.owner.login
json.image_url url_to_avatar(project.owner)
end
json.category do
if project.project_category.blank?

View File

@ -1,10 +1,16 @@
json.total_count @hash_commit[:total_count]
json.commits do
json.array! @hash_commit[:body] do |commit|
json.sha commit['sha']
json.message commit['commit']['message']
json.timestamp render_unix_time(commit['commit']['author']['date'])
json.time_from_now time_from_now(commit['commit']['author']['date'])
json.partial! 'author', user: @project.owner
if @hash_commit.blank? #如果有状态值,则表示报错了
json.total_count 0
json.commits []
else
json.total_count @hash_commit[:total_count]
json.commits do
json.array! @hash_commit[:body] do |commit|
json.sha commit['sha']
json.message commit['commit']['message']
json.timestamp render_unix_time(commit['commit']['author']['date'])
json.time_from_now time_from_now(commit['commit']['author']['date'])
json.partial! 'author', user: @project.owner
end
end
end

View File

@ -0,0 +1,5 @@
class AddVersionIdIndex < ActiveRecord::Migration[5.2]
def change
execute "ALTER TABLE versions ADD PRIMARY KEY (id);"
end
end

View File

@ -0,0 +1,31 @@
# 执行示例 bundle exec rake sync_version_issues:update_issues
# 线上环境执行示例 RAILS_ENV=production bundle exec rake sync_version_issues:update_issues
namespace :sync_version_issues do
desc "update version issues_count"
task update_issues: :environment do
puts "____________sync start________________"
Version.all.each do |q|
issues = Issue.select(:id, :fixed_version_id,:status_id).where(fixed_version_id: q.id)
issues_count = issues.size
puts "____________issues_count____________#{issues_count}____"
closed_issues_count = issues.where(status_id: 5).size
percent = issues_count == 0 ? 0.0 : (closed_issues_count.to_f / issues_count)
q.issues_count = issues_count
q.closed_issues_count = closed_issues_count
q.percent = percent
begin
q.save!
rescue Exception => e
puts "#####_______save_error______######{e}"
end
# q.update_attributes(issues_count: issues_count, closed_issues_count: closed_issues_count, percent: percent)
puts "____________sync success________________"
end
puts "____________sync end________________"
end
end