Merge branch 'dev_trustie' into dev_chain
This commit is contained in:
commit
b7c86fd83c
|
@ -25,10 +25,8 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def migrate
|
||||
ActiveRecord::Base.transaction do
|
||||
Projects::MigrateForm.new(mirror_params).validate!
|
||||
@project = Projects::MigrateService.new(current_user, mirror_params).call
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
|
|
|
@ -32,6 +32,7 @@ class RepositoriesController < ApplicationController
|
|||
@project_owner = @project.owner
|
||||
@entries = Gitea::Repository::Entries::ListService.new(@project_owner, @project.identifier, ref: @ref).call
|
||||
@entries = @entries.sort_by{ |hash| hash['type'] }
|
||||
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||
end
|
||||
|
||||
def sub_entries
|
||||
|
|
|
@ -18,4 +18,36 @@ module RepositoriesHelper
|
|||
return nil if author_json.blank?
|
||||
find_user_by_login author_json['login']
|
||||
end
|
||||
|
||||
def readme_render_decode64_content(str, path)
|
||||
return nil if str.blank?
|
||||
content = Base64.decode64(str).force_encoding('UTF-8')
|
||||
|
||||
c_regex = /\!\[.*?\]\((.*?)\)/
|
||||
src_regex = /src=\"(.*?)\"/
|
||||
ss = content.to_s.scan(c_regex)
|
||||
ss_src = content.to_s.scan(src_regex)
|
||||
total_images = ss + ss_src
|
||||
if total_images.length > 0
|
||||
total_images.each do |s|
|
||||
image_title = /\"(.*?)\"/
|
||||
r_content = s[0]
|
||||
remove_title = r_content.to_s.scan(image_title)
|
||||
if remove_title.length > 0
|
||||
r_content = r_content.gsub(/#{remove_title[0]}/, "").strip
|
||||
end
|
||||
if r_content.include?("?")
|
||||
new_r_content = r_content + "&raw=true"
|
||||
else
|
||||
new_r_content = r_content + "?raw=true"
|
||||
end
|
||||
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
|
||||
new_r_content = "#{path}" + new_r_content
|
||||
end
|
||||
content = content.gsub(/#{r_content}/, new_r_content)
|
||||
end
|
||||
end
|
||||
|
||||
return content
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob
|
|||
|
||||
gitea_repository = Gitea::Repository::MigrateService.new(token, params).call
|
||||
if gitea_repository
|
||||
repo&.project&.update_columns(gpid: gitea_repository["id"], identifier: gitea_repository["name"])
|
||||
repo&.project&.update_columns(gpid: gitea_repository["id"])
|
||||
repo&.mirror&.update_columns(status: Mirror.statuses[:succeeded])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,13 +8,11 @@ class Projects::MigrateService < ApplicationService
|
|||
|
||||
def call
|
||||
@project = Project.new(project_params)
|
||||
ActiveRecord::Base.transaction do
|
||||
if @project.save!
|
||||
Repositories::MigrateService.new(user, @project, repository_params).call
|
||||
else
|
||||
#
|
||||
end
|
||||
end
|
||||
@project
|
||||
rescue => e
|
||||
puts "create mirror project service error: #{e.message}"
|
||||
|
@ -27,11 +25,12 @@ class Projects::MigrateService < ApplicationService
|
|||
{
|
||||
name: params[:name],
|
||||
user_id: params[:user_id],
|
||||
project_type: set_project_type,
|
||||
description: params[:description],
|
||||
identifier: params[:repository_name],
|
||||
is_public: project_secretion[:public],
|
||||
project_category_id: params[:project_category_id],
|
||||
project_language_id: params[:project_language_id],
|
||||
is_public: project_secretion[:public],
|
||||
project_type: set_project_type
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -9,13 +9,11 @@ class Repositories::MigrateService < ApplicationService
|
|||
|
||||
def call
|
||||
@repository = Repository.new(repository_params)
|
||||
ActiveRecord::Base.transaction do
|
||||
if @repository.save!
|
||||
@repository.set_mirror! if wrapper_mirror
|
||||
MigrateRemoteRepositoryJob.perform_later(@repository.id, user.gitea_token, gitea_repository_params)
|
||||
end
|
||||
@repository
|
||||
end
|
||||
rescue => e
|
||||
puts "create mirror repository service error: #{e.message}"
|
||||
raise Error, e.message
|
||||
|
@ -23,7 +21,7 @@ class Repositories::MigrateService < ApplicationService
|
|||
|
||||
private
|
||||
def repository_params
|
||||
params.merge(project_id: project.id)
|
||||
params.merge(project_id: project.id, identifier: params[:identifier])
|
||||
end
|
||||
|
||||
def gitea_repository_params
|
||||
|
|
|
@ -17,7 +17,7 @@ json.entries do
|
|||
content =
|
||||
if entry['name'] === 'README.md'
|
||||
content = Gitea::Repository::Entries::GetService.call(@project_owner, @project.identifier, entry['name'], ref: @ref)['content']
|
||||
render_decode64_content content
|
||||
readme_render_decode64_content(content, @path)
|
||||
else
|
||||
entry['content']
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue