change versions_count and check mirrors
This commit is contained in:
commit
6357bf91cd
|
@ -145,9 +145,16 @@ class IssuesController < ApplicationController
|
|||
else
|
||||
normal_status(-1, "创建失败")
|
||||
end
|
||||
rescue => e
|
||||
Rails.looger.info("##################________exception_________________######################{e.message}")
|
||||
normal_status(-1, e.message)
|
||||
if params[:assigned_to_id].present?
|
||||
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
||||
container_id: @issue.id, container_type: 'Issue',
|
||||
parent_container_id: @project.id, parent_container_type: "Project",
|
||||
tiding_type: 'issue', status: 0)
|
||||
end
|
||||
|
||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
# normal_status(0, "创建成功",)
|
||||
render :json => { status: 0, message: "创建成功", id: @issue.id}
|
||||
else
|
||||
|
||||
end
|
||||
|
|
|
@ -88,6 +88,7 @@ class PullRequestsController < ApplicationController
|
|||
if params[:title].to_s.include?("WIP:")
|
||||
pull_issue.custom_journal_detail("WIP", "", "这个合并请求被标记为尚未完成的工作。完成后请从标题中移除WIP:前缀。", current_user&.id)
|
||||
end
|
||||
# render :json => { status: 0, message: "PullRequest创建成功", id: pull_issue.id}
|
||||
normal_status(0, "PullRequest创建成功")
|
||||
else
|
||||
normal_status(-1, "PullRequest创建失败")
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
# 运行示例: bundle exec rails runner "CheckMirrorJob.new.call()"
|
||||
|
||||
class CheckMirrorJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(project)
|
||||
SyncLog.sync_log("==========begin_check_project_id_job:#{project.id}============")
|
||||
begin
|
||||
response = Gitea::Repository::Branches::ListService.new(project.owner, project.identifier).call
|
||||
unless response.present?
|
||||
SyncLog.sync_log("==========check_project_error_id:#{project.id}============")
|
||||
ActiveRecord::Base.transaction do
|
||||
delete_gitea = Gitea::Repository::DeleteService.new(project.owner, project.identifier).call
|
||||
if delete_gitea.status == 204 || delete_gitea.status == 404 #删除成功或者仓库不存在,都重新创建
|
||||
repository_params= {
|
||||
name: project.identifier,
|
||||
auto_init: true,
|
||||
private: project.repository.hidden,
|
||||
}
|
||||
gitea_repository = Gitea::Repository::CreateService.new(project.owner.gitea_token, repository_params).call
|
||||
if gitea_repository
|
||||
project.update_columns(gpid: gitea_repository["id"],forked_count: gitea_repository["forks_count"])
|
||||
else
|
||||
SyncLog.sync_log("==========gitea_repository_created_failed:#{project.id}============")
|
||||
end
|
||||
else
|
||||
SyncLog.sync_log("==========delete_gitea_failed:#{project.id}============")
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
SyncLog.sync_log("==========failed_check_project_id:#{project.id}============errors:#{e}")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
class CheckMirrorRake
|
||||
# 运行示例: bundle exec rails runner "CheckMirrorRake.new.call()"
|
||||
|
||||
def call
|
||||
SyncLog.sync_log("=====begin to check mirror======")
|
||||
all_projects = Projects.select(:id,:identifier,:user_id, :gpid, :forked_count,:is_public).includes(:owner, :repository)
|
||||
all_projects.each do |project|
|
||||
SyncLog.sync_log("=====check_project_id:#{project.id}======")
|
||||
CheckMirrorJob.perform_later(project)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
class ChangeVersionsIssuesCount < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent)
|
||||
versions.each do |v|
|
||||
closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size
|
||||
unless v.closed_issues_count.to_i == closed_issues
|
||||
puts v.id
|
||||
percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i)
|
||||
v.closed_issues_count = closed_issues
|
||||
v.percent = percent
|
||||
v.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue