From e76d475fefb3c74bf216763c5447b3474adb6bcd Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 6 Jul 2021 11:04:00 +0800 Subject: [PATCH 1/3] FIX show realname for create project --- app/views/owners/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/owners/index.json.jbuilder b/app/views/owners/index.json.jbuilder index 677aff71..6b7e5222 100644 --- a/app/views/owners/index.json.jbuilder +++ b/app/views/owners/index.json.jbuilder @@ -2,6 +2,6 @@ json.total_count @owners.size json.owners @owners.each do |owner| json.id owner.id json.type owner.type - json.name owner.login + json.name owner&.show_real_name json.avatar_url url_to_avatar(owner) end \ No newline at end of file From 3614f3e15b700d16c0b4ae5910d296975d437d41 Mon Sep 17 00:00:00 2001 From: jasder Date: Fri, 9 Jul 2021 16:57:11 +0800 Subject: [PATCH 2/3] =?UTF-8?q?FIX=20=E8=A7=A3=E5=86=B3=E7=A7=81=E6=9C=89?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E5=BA=93=E4=B8=8D=E8=83=BD=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E3=80=81=E4=B8=8B=E8=BD=BD=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 37 ++++++++++++++++++- .../repositories/_simple_entry.json.jbuilder | 11 +++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index e704acb8..95c669b7 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -15,7 +15,7 @@ module RepositoriesHelper end 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) end @@ -86,4 +86,39 @@ module RepositoriesHelper render_decode64_content(entry['content']) 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 diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index ec2a045b..7d41bbd2 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -11,7 +11,16 @@ if @project.forge? json.content decode64_content(entry, @owner, @repository, @ref) 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.image_type image_type json.is_readme_file is_readme?(entry['type'], entry['name']) From d271a684fa053bd891866435437b5f63de08216b Mon Sep 17 00:00:00 2001 From: viletyy Date: Mon, 12 Jul 2021 17:24:23 +0800 Subject: [PATCH 3/3] add: compare code return can merge message --- app/controllers/compare_controller.rb | 36 +++++++++++++++++++++------ app/views/compare/show.json.jbuilder | 1 + 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb index 63ca58aa..4b686015 100644 --- a/app/controllers/compare_controller.rb +++ b/app/controllers/compare_controller.rb @@ -6,26 +6,48 @@ class CompareController < ApplicationController end def show + load_compare_params compare + @merge_message = get_merge_message end 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 "在这些分支之间的合并请求已存在:#{@exist_pullrequest.try(:title)}" + else + if @compare_result["Commits"].blank? && @compare_result["Diff"].blank? + return "分支内容相同,无需创建合并请求" + end + end + end + return "可以合并" + end + def compare - base, head = compare_params # TODO: 处理fork的项目向源项目发送PR的base、head参数问题 @compare_result ||= - head.include?(":") ? gitea_compare(base, head) : gitea_compare(head, base) + @head.include?(":") ? gitea_compare(@base, @head) : gitea_compare(@head, @base) end - def compare_params - base = Addressable::URI.unescape(params[:base]) - head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head] + def load_compare_params + @base = Addressable::URI.unescape(params[:base]) + @head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head] - [base, head] end 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 diff --git a/app/views/compare/show.json.jbuilder b/app/views/compare/show.json.jbuilder index 8b75fa3d..91260e56 100644 --- a/app/views/compare/show.json.jbuilder +++ b/app/views/compare/show.json.jbuilder @@ -83,3 +83,4 @@ json.diff do end end +json.message @merge_message \ No newline at end of file