forked from Gitlink/forgeplus
parent
d85075f951
commit
f06a1f63dd
|
@ -36,6 +36,7 @@ public/react/yarn.lock
|
||||||
/.idea/*
|
/.idea/*
|
||||||
|
|
||||||
# Ignore react node_modules
|
# Ignore react node_modules
|
||||||
|
public/react/*
|
||||||
/public/react/.cache
|
/public/react/.cache
|
||||||
/public/react/node_modules/
|
/public/react/node_modules/
|
||||||
/public/react/config/stats.json
|
/public/react/config/stats.json
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
class Gitea::Repository::TransferService < Gitea::ClientService
|
||||||
|
attr_reader :token, :owner, :repo, :new_owner
|
||||||
|
|
||||||
|
def initialize(token, owner, repo, new_owner)
|
||||||
|
@token = token
|
||||||
|
@owner = owner
|
||||||
|
@repo = repo
|
||||||
|
@new_owner = new_owner
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
response = post(url, request_params)
|
||||||
|
render_status(response)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def request_params
|
||||||
|
transfer_params = {
|
||||||
|
new_owner: new_owner
|
||||||
|
}
|
||||||
|
Hash.new.merge(token: token, data: transfer_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
def url
|
||||||
|
"/repos/#{owner}/#{repo}/transfer".freeze
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,45 @@
|
||||||
|
class Projects::TransferService < ApplicationService
|
||||||
|
attr_accessor :project, :owner, :new_owner
|
||||||
|
|
||||||
|
def initialize(project, new_owner)
|
||||||
|
@project = project
|
||||||
|
@owner = project.owner
|
||||||
|
@new_owner = new_owner
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
Rails.logger.info("###### Project transfer_service begin ######")
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
gitea_update_owner
|
||||||
|
update_owner
|
||||||
|
update_visit_teams
|
||||||
|
end
|
||||||
|
|
||||||
|
Rails.logger.info("##### Project transfer_service end ######")
|
||||||
|
|
||||||
|
@project.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def update_owner
|
||||||
|
project.update!(user_id: new_owner.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_visit_teams
|
||||||
|
if new_owner.is_a?(Organization)
|
||||||
|
new_owner.teams.where(includes_all_project: true).each do |team|
|
||||||
|
TeamProject.build(new_owner.id, team.id, project.id)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
project.team_projects.each(&:destroy!)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def gitea_update_owner
|
||||||
|
begin
|
||||||
|
Gitea::Repository::TransferService.call(owner&.gitea_token, owner&.login, project.identifier, new_owner&.login)
|
||||||
|
rescue Exception => e
|
||||||
|
Rails.logger.info("##### Project transfer_service, gitea transfer error #{e}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 6348a15cdb954862dc1b7b5f045a432bcfde7dc4
|
|
Loading…
Reference in New Issue