change versions and check repository

This commit is contained in:
sylor_huang@126.com 2020-07-17 11:18:12 +08:00
parent 5cd9fe9e34
commit 9372fcf6a4
5 changed files with 66 additions and 1 deletions

View File

@ -137,7 +137,8 @@ class IssuesController < ApplicationController
end
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
normal_status(0, "创建成功")
# normal_status(0, "创建成功",)
render :json => { status: 0, message: "创建成功", id: @issue.id}
else
normal_status(-1, "创建失败")
end

View File

@ -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创建失败")

View File

@ -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

View File

@ -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

View File

@ -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