diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1864c6964..3bb04e873 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -16,13 +16,13 @@ class ProjectsController < ApplicationController menu.append(menu_hash_by_name("home")) menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code") menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues") - menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") - menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") - menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") + menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") && @project.forge? + menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") && @project.forge? + menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") && @project.forge? menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions") - menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") + menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") && @project.forge? menu.append(menu_hash_by_name("activity")) - menu.append(menu_hash_by_name("settings")) if current_user.admin? || @project.manager?(current_user) + menu.append(menu_hash_by_name("settings")) if (current_user.admin? || @project.manager?(current_user)) && @project.forge? render json: menu end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 0292dc1d1..07c209730 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -71,16 +71,32 @@ class RepositoriesController < ApplicationController logger.info "######### sub_entries: #{@sub_entries}" return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1 - tmp_entries = [{ + tmp_entries = { "content" => @sub_entries['data']['content'], "type" => "blob" - }] + } @sub_entries = { "trees"=>tmp_entries, "commits" => [{}] } else - @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) + begin + @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) + if @sub_entries.blank? || @sub_entries['status'].to_i === -1 + @sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri) + return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1 + tmp_entries = { + "content" => @sub_entries['data']['content'], + "type" => "blob" + } + @sub_entries = { + "trees"=>tmp_entries, + "commits" => [{}] + } + end + rescue + return render_error('该文件暂未开放,敬请期待.') + end end else @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" @@ -117,8 +133,7 @@ class RepositoriesController < ApplicationController def commit @sha = params[:sha] if @project.educoder? - @commit = {} - @commit_diff ={} + return render_error('暂未开放,敬请期待.') else @commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token) @commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true}) diff --git a/app/helpers/tag_chosen_helper.rb b/app/helpers/tag_chosen_helper.rb index 593e412d9..4ded66e1a 100644 --- a/app/helpers/tag_chosen_helper.rb +++ b/app/helpers/tag_chosen_helper.rb @@ -26,8 +26,12 @@ module TagChosenHelper end def render_branches(project) - branches = Gitea::Repository::Branches::ListService.call(project&.owner, project.identifier) - branches.collect{|i| i["name"] if i.is_a?(Hash)} + if project.educoder? + return ['master'] + else + branches = Gitea::Repository::Branches::ListService.call(project&.owner, project.identifier) + branches.collect{|i| i["name"] if i.is_a?(Hash)} + end end def render_cache_trackers diff --git a/app/views/repositories/_commit.json.jbuilder b/app/views/repositories/_commit.json.jbuilder index 9c29116e9..892353ea7 100644 --- a/app/views/repositories/_commit.json.jbuilder +++ b/app/views/repositories/_commit.json.jbuilder @@ -7,11 +7,22 @@ if @project.educoder? json.timestamp 0 json.time_from_now commit[0]['time'] end - json.author do - {} - # json.partial! '/projects/author', user: render_commit_author(commit['author']) - end - json.committer {} + if commit[0]['author'].present? + json.author do + json.id nil + json.login commit[0]['author']['username'] + json.name commit[0]['author']['username'] + json.type nil + json.image_url commit[0]['author']['image_url'] + end + json.committer do + json.id nil + json.login commit[0]['author']['username'] + json.name commit[0]['author']['username'] + json.type nil + json.image_url commit[0]['author']['image_url'] + end + end end if @project.forge? diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index 6f33ac35e..80a54d477 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -32,6 +32,8 @@ end if @project.educoder? file_path = params[:filepath].present? ? [params[:filepath], entry['name']].join('/') : entry['name'] + file_type = File.extname(entry['name'].to_s)[1..-1] + image_type = image_type?(file_type) json.name entry['name'] json.sha nil @@ -42,7 +44,7 @@ if @project.educoder? json.target nil json.download_url nil json.direct_download false - json.image_type false + json.image_type image_type json.is_readme_file false json.commit do json.message entry['title'] diff --git a/app/views/repositories/commits.json.jbuilder b/app/views/repositories/commits.json.jbuilder index 11644f832..14b9f1b9e 100644 --- a/app/views/repositories/commits.json.jbuilder +++ b/app/views/repositories/commits.json.jbuilder @@ -12,7 +12,7 @@ if @hash_commit.blank? || @project.educoder? #如果有状态值,则表示 json.type nil json.image_url commit['author']['image_url'] end - json.commiter do + json.committer do json.id nil json.login commit['author']['username'] json.name commit['author']['username'] diff --git a/app/views/repositories/sub_entries.json.jbuilder b/app/views/repositories/sub_entries.json.jbuilder index 3276ed0dd..296e307f4 100644 --- a/app/views/repositories/sub_entries.json.jbuilder +++ b/app/views/repositories/sub_entries.json.jbuilder @@ -24,8 +24,12 @@ if @project.educoder? end end json.entries do - json.array! @sub_entries['trees'] do |entry| - json.partial! 'repositories/simple_entry', locals: { entry: entry } + if @sub_entries['trees'].is_a?(Array) + json.array! @sub_entries['trees'] do |entry| + json.partial! 'repositories/simple_entry', locals: { entry: entry } + end + elsif @sub_entries['trees'].is_a?(Hash) + json.partial! 'repositories/simple_entry', locals: { entry: @sub_entries['trees'] } end end end