Merge branch 'dev_trustie_server' into trustie_server
This commit is contained in:
commit
4520055de2
|
@ -6,23 +6,45 @@ class CompareController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
load_compare_params
|
||||||
compare
|
compare
|
||||||
|
@merge_status, @merge_message = get_merge_message
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def get_merge_message
|
||||||
|
if @base.blank? || @head.blank?
|
||||||
|
return -2, "请选择分支"
|
||||||
|
else
|
||||||
|
if @head.include?(":")
|
||||||
|
fork_project = @project.forked_projects.joins(:owner).where(users: {login: @head.to_s.split("/")[0]}).take
|
||||||
|
return -2, "请选择正确的仓库" 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 -2, "在这些分支之间的合并请求已存在:<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 -2, "分支内容相同,无需创建合并请求"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 0, "可以合并"
|
||||||
|
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)
|
||||||
|
|
|
@ -150,9 +150,16 @@ class PullRequestsController < ApplicationController
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
result = PullRequests::MergeService.call(@owner, @repository, @pull_request, current_user, params)
|
@gitea_pull = Gitea::PullRequest::GetService.call(@owner.login, @repository.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||||
|
|
||||||
if result.status == 200 && @pull_request.merge!
|
if @gitea_pull["merged_by"].present?
|
||||||
|
success_condition = true
|
||||||
|
else
|
||||||
|
result = PullRequests::MergeService.call(@owner, @repository, @pull_request, current_user, params)
|
||||||
|
success_condition = result.status == 200
|
||||||
|
end
|
||||||
|
|
||||||
|
if success_condition && @pull_request.merge!
|
||||||
@pull_request.project_trend_status!
|
@pull_request.project_trend_status!
|
||||||
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
||||||
normal_status(1, "合并成功")
|
normal_status(1, "合并成功")
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -76,8 +76,6 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Project < ApplicationRecord
|
class Project < ApplicationRecord
|
||||||
include Matchable
|
include Matchable
|
||||||
include Publicable
|
include Publicable
|
||||||
|
|
|
@ -83,3 +83,5 @@ json.diff do
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
json.status @merge_status
|
||||||
|
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