From 39ae14bce72b8afb6ce488dad396890b34534593 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Feb 2023 14:18:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aentry=E6=96=B0?= =?UTF-8?q?=E5=A2=9Esubmodule=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 10 +++++++++- app/views/repositories/_simple_entry.json.jbuilder | 1 + app/views/repositories/entries.json.jbuilder | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d9ac3746f..d05d54611 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -197,5 +197,13 @@ module RepositoriesHelper def tmp_dir "repo" end - + + def repo_git_submodule_url(owner, repo, path) + unless (path.starts_with?('http://') || path.starts_with?('https://')) + path = File.expand_path(path, "#{base_url}/#{owner&.login}/#{repo&.identifier}") + path = path.split("#{Rails.root}/")[1] + end + + return path + end end diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 30ed9d22d..013b33a9d 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -7,6 +7,7 @@ if @project.forge? json.sha entry['sha'] json.path entry['path'] json.type entry['type'] + json.submodule_git_url repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] is_readme = is_readme?(entry['type'], entry['name']) if is_readme diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 6dea93b32..310918597 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -51,6 +51,7 @@ if @project.forge? json.path entry['path'] json.sha entry['sha'] json.type entry['type'] + json.submodule_git_url repo_git_submodule_url(@owner, @repository, entry['submodule_git_url']) json.size entry['size'] json.is_readme_file is_readme?(entry['type'], entry['name']) json.content decode64_content(entry, @owner, @repository, @ref, @path)