新增:删除fork仓库关闭对应合并请求

This commit is contained in:
2024-07-19 09:46:57 +08:00
parent c362315ea5
commit f9e7dafefd
2 changed files with 35 additions and 0 deletions

View File

@@ -258,6 +258,7 @@ class ProjectsController < ApplicationController
def destroy
if current_user.admin? || @project.manager?(current_user)
ActiveRecord::Base.transaction do
close_fork_pull_requests_by(@project)
Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call
@project.destroy!
@project.forked_projects.update_all(forked_from_project_id: nil)
@@ -408,4 +409,19 @@ class ProjectsController < ApplicationController
render_unauthorized('你还未登录.')
end
end
def close_fork_pull_requests_by(project)
open_pull_requests = PullRequest.where(fork_project_id: project.id)
if open_pull_requests.present?
open_pull_requests.each do |pull_request|
closed = PullRequests::CloseService.call(pull_request&.project.owner, pull_request&.project.repository, pull_request, current_user)
if closed === true
pull_request.project_trends.create!(user: current_user, project: pull_request&.project,action_type: ProjectTrend::CLOSE)
# 合并请求下issue处理为关闭
pull_request.issue&.update_attributes!({status_id:5})
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, pull_request.id) if Site.has_notice_menu?
end
end
end
end
end