Merge branch 'develop' of http://git.trustie.net/jasder/forgeplus into develop
This commit is contained in:
commit
3e89791255
|
@ -10,9 +10,9 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
scope = Projects::ListQuery.call(params.merge(is_admin: is_admin, user_id: current_user.try(:id)))
|
scope = Projects::ListQuery.call(params.merge(is_admin: is_admin, user_id: current_user.try(:id)))
|
||||||
|
|
||||||
@total_count = scope.size
|
scope_ids = scope.pluck(:id)
|
||||||
|
@total_count = scope_ids.size
|
||||||
@projects = paginate(scope)
|
@projects = paginate(Project.where(id: scope_ids))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -16,11 +16,12 @@ class Projects::ListQuery < ApplicationQuery
|
||||||
# else
|
# else
|
||||||
# projects = Project.visible
|
# projects = Project.visible
|
||||||
# end
|
# end
|
||||||
projects = Project.no_anomory_projects.visible
|
projects = Project.visible
|
||||||
scope = projects.includes(:project_category, :project_language, :repository, owner: :user_extension).like(params[:search])
|
scope = projects.includes(:project_category, :project_language, :repository, owner: :user_extension).like(params[:search])
|
||||||
.with_project_type(params[:project_type])
|
.with_project_type(params[:project_type])
|
||||||
.with_project_category(params[:category_id])
|
.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 = params[:sort_by] || "updated_on"
|
||||||
sort_direction = params[:sort_direction] || "desc"
|
sort_direction = params[:sort_direction] || "desc"
|
||||||
|
|
|
@ -24,7 +24,7 @@ class Gitea::Repository::Commits::ListService < Gitea::ClientService
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_result(response)
|
def render_result(response)
|
||||||
body = JSON.parse(response.body)
|
|
||||||
case response.status
|
case response.status
|
||||||
when 200
|
when 200
|
||||||
result = {}
|
result = {}
|
||||||
|
@ -33,7 +33,8 @@ class Gitea::Repository::Commits::ListService < Gitea::ClientService
|
||||||
total_count = headers["x-total"]
|
total_count = headers["x-total"]
|
||||||
result.merge(total_count: total_count.to_i, body: body)
|
result.merge(total_count: total_count.to_i, body: body)
|
||||||
else
|
else
|
||||||
{status: -1, message: "#{body['message']}"}
|
nil
|
||||||
|
# {status: -1, message: "#{body['message']}"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
json.total_count @total_count
|
json.total_count @total_count
|
||||||
json.projects do
|
json.projects do
|
||||||
json.array! @projects do |project|
|
json.array! @projects.to_a do |project|
|
||||||
json.partial! 'project', project: project
|
json.partial! 'project', project: project
|
||||||
json.author do
|
json.author do
|
||||||
json.name project&.owner&.login
|
json.name project.owner.try(:show_real_name)
|
||||||
json.login project&.owner&.login
|
json.login project.owner.login
|
||||||
json.image_url url_to_avatar(project&.owner)
|
json.image_url url_to_avatar(project.owner)
|
||||||
end
|
end
|
||||||
json.category do
|
json.category do
|
||||||
if project.project_category.blank?
|
if project.project_category.blank?
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
json.total_count @hash_commit[:total_count]
|
if @hash_commit.blank? #如果有状态值,则表示报错了
|
||||||
json.commits do
|
json.total_count 0
|
||||||
json.array! @hash_commit[:body] do |commit|
|
json.commits []
|
||||||
json.sha commit['sha']
|
else
|
||||||
json.message commit['commit']['message']
|
json.total_count @hash_commit[:total_count]
|
||||||
json.timestamp render_unix_time(commit['commit']['author']['date'])
|
json.commits do
|
||||||
json.time_from_now time_from_now(commit['commit']['author']['date'])
|
json.array! @hash_commit[:body] do |commit|
|
||||||
json.partial! 'author', user: @project.owner
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddVersionIdIndex < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
execute "ALTER TABLE versions ADD PRIMARY KEY (id);"
|
||||||
|
end
|
||||||
|
end
|
|
@ -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
|
Loading…
Reference in New Issue