fix: merge from develop
This commit is contained in:
commit
8f1aa3f4b1
|
@ -6,26 +6,48 @@ class CompareController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
load_compare_params
|
||||||
compare
|
compare
|
||||||
|
@merge_message = get_merge_message
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def get_merge_message
|
||||||
|
if @base.blank? || @head.blank?
|
||||||
|
return "请选择分支"
|
||||||
|
else
|
||||||
|
if @head.include?(":")
|
||||||
|
fork_project = @project.forked_projects.joins(:owner).where(users: {login: @head.to_s.split("/")[0]}).take
|
||||||
|
return "请选择正确的仓库" unless fork_project.present?
|
||||||
|
@exist_pullrequest = @project.pull_requests.where(is_original: true, head: @head.to_s.split(":")[1], base: @base, status: 0, fork_project_id: fork_project.id).take
|
||||||
|
else
|
||||||
|
@exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).take
|
||||||
|
end
|
||||||
|
if @exist_pullrequest.present?
|
||||||
|
return "在这些分支之间的合并请求已存在:<a href='/projects/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}/Messagecount'>#{@exist_pullrequest.try(:title)}</a>"
|
||||||
|
else
|
||||||
|
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
|
||||||
|
return "分支内容相同,无需创建合并请求"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "可以合并"
|
||||||
|
end
|
||||||
|
|
||||||
def compare
|
def compare
|
||||||
base, head = compare_params
|
|
||||||
|
|
||||||
# TODO: 处理fork的项目向源项目发送PR的base、head参数问题
|
# TODO: 处理fork的项目向源项目发送PR的base、head参数问题
|
||||||
@compare_result ||=
|
@compare_result ||=
|
||||||
head.include?(":") ? gitea_compare(base, head) : gitea_compare(head, base)
|
@head.include?(":") ? gitea_compare(@base, @head) : gitea_compare(@head, @base)
|
||||||
end
|
end
|
||||||
|
|
||||||
def compare_params
|
def load_compare_params
|
||||||
base = Addressable::URI.unescape(params[:base])
|
@base = Addressable::URI.unescape(params[:base])
|
||||||
head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head]
|
@head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head]
|
||||||
|
|
||||||
[base, head]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitea_compare(base, head)
|
def gitea_compare(base, head)
|
||||||
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, base, head)
|
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, @base, @head)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ module RepositoriesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_type?(str)
|
def image_type?(str)
|
||||||
default_type = %w(png jpg gif tif psd svg)
|
default_type = %w(png jpg gif tif psd svg gif bmp webp jpeg)
|
||||||
default_type.include?(str&.downcase)
|
default_type.include?(str&.downcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,4 +86,39 @@ module RepositoriesHelper
|
||||||
render_decode64_content(entry['content'])
|
render_decode64_content(entry['content'])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def base64_to_image(path, content)
|
||||||
|
# generate to https://git.trusite.net/pawm36ozq/-/raw/branch/master/entrn.png"
|
||||||
|
content = Base64.decode64(content)
|
||||||
|
File.open(path, 'wb') { |f| f.write(content) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_download_image_url(dir_path, file_path, content)
|
||||||
|
# 用户名/项目标识/文件路径
|
||||||
|
dir_path = generate_dir_path(dir_path)
|
||||||
|
|
||||||
|
file_path = [dir_path, file_path].join('/')
|
||||||
|
|
||||||
|
puts "##### render_download_image_url file_path: #{file_path}"
|
||||||
|
base64_to_image(file_path, content)
|
||||||
|
|
||||||
|
file_path = file_path.split('public')[1]
|
||||||
|
File.join(base_url, file_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_dir_path(dir_path)
|
||||||
|
# tmp_dir_path
|
||||||
|
# eg: jasder/forgeplus/raw/branch/ref
|
||||||
|
dir_path = ["public", tmp_dir, dir_path].join('/')
|
||||||
|
puts "#### dir_path: #{dir_path}"
|
||||||
|
unless Dir.exists?(dir_path)
|
||||||
|
FileUtils.mkdir_p(dir_path) ##不成功这里会抛异常
|
||||||
|
end
|
||||||
|
dir_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def tmp_dir
|
||||||
|
"repo"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
|
||||||
|
>>>>>>> develop
|
||||||
# == Schema Information
|
# == Schema Information
|
||||||
#
|
#
|
||||||
# Table name: projects
|
# Table name: projects
|
||||||
|
@ -75,6 +79,10 @@
|
||||||
# index_projects_on_updated_on (updated_on)
|
# index_projects_on_updated_on (updated_on)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
|
||||||
|
>>>>>>> develop
|
||||||
|
|
||||||
class Project < ApplicationRecord
|
class Project < ApplicationRecord
|
||||||
include Matchable
|
include Matchable
|
||||||
|
|
|
@ -83,3 +83,4 @@ json.diff do
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
json.message @merge_message
|
|
@ -2,6 +2,6 @@ json.total_count @owners.size
|
||||||
json.owners @owners.each do |owner|
|
json.owners @owners.each do |owner|
|
||||||
json.id owner.id
|
json.id owner.id
|
||||||
json.type owner.type
|
json.type owner.type
|
||||||
json.name owner.login
|
json.name owner&.show_real_name
|
||||||
json.avatar_url url_to_avatar(owner)
|
json.avatar_url url_to_avatar(owner)
|
||||||
end
|
end
|
|
@ -11,7 +11,16 @@ if @project.forge?
|
||||||
|
|
||||||
json.content decode64_content(entry, @owner, @repository, @ref)
|
json.content decode64_content(entry, @owner, @repository, @ref)
|
||||||
json.target entry['target']
|
json.target entry['target']
|
||||||
json.download_url entry['download_url']
|
|
||||||
|
download_url =
|
||||||
|
if image_type
|
||||||
|
dir_path = [@owner.login, @repository.identifier, "raw/branch", @ref].join('/')
|
||||||
|
render_download_image_url(dir_path, entry['path'], decode64_content(entry, @owner, @repository, @ref))
|
||||||
|
else
|
||||||
|
entry['download_url']
|
||||||
|
end
|
||||||
|
json.download_url download_url
|
||||||
|
|
||||||
json.direct_download direct_download
|
json.direct_download direct_download
|
||||||
json.image_type image_type
|
json.image_type image_type
|
||||||
json.is_readme_file is_readme?(entry['type'], entry['name'])
|
json.is_readme_file is_readme?(entry['type'], entry['name'])
|
||||||
|
|
Loading…
Reference in New Issue