From 102858bc8cbadeac44fd4b49cf89a42379ffb345 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Dec 2021 11:06:49 +0800 Subject: [PATCH] fix: educoder entries file use hash --- app/controllers/repositories_controller.rb | 6 ++-- app/views/repositories/_commit.json.jbuilder | 30 ++++++++++--------- .../repositories/sub_entries.json.jbuilder | 4 +-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 94ee26a29..9012792c6 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -71,7 +71,7 @@ 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" }] @@ -82,13 +82,13 @@ class RepositoriesController < ApplicationController else begin @sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri}) - if @sub_entries.blank? + 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" => [{}] diff --git a/app/views/repositories/_commit.json.jbuilder b/app/views/repositories/_commit.json.jbuilder index a1ed80d60..892353ea7 100644 --- a/app/views/repositories/_commit.json.jbuilder +++ b/app/views/repositories/_commit.json.jbuilder @@ -7,20 +7,22 @@ if @project.educoder? json.timestamp 0 json.time_from_now commit[0]['time'] end - 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 + 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/sub_entries.json.jbuilder b/app/views/repositories/sub_entries.json.jbuilder index 3276ed0dd..4e6932210 100644 --- a/app/views/repositories/sub_entries.json.jbuilder +++ b/app/views/repositories/sub_entries.json.jbuilder @@ -24,8 +24,6 @@ if @project.educoder? end end json.entries do - json.array! @sub_entries['trees'] do |entry| - json.partial! 'repositories/simple_entry', locals: { entry: entry } - end + json.partial! 'repositories/simple_entry', locals: { entry: @sub_entries['trees']} end end