From c4586fbb366abbab8709357bad8e43a39c57ec3a Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Dec 2021 14:11:37 +0800 Subject: [PATCH 1/4] fix: remove detail language and contributors --- app/services/repositories/detail_service.rb | 20 +------------------ .../repositories/contributors.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/app/services/repositories/detail_service.rb b/app/services/repositories/detail_service.rb index b2e7a69e6..b39b408ce 100644 --- a/app/services/repositories/detail_service.rb +++ b/app/services/repositories/detail_service.rb @@ -10,20 +10,12 @@ class Repositories::DetailService < ApplicationService def call return { repo: repo_suitable, - contributor: contributor_suitable, - language: language_suitable, branch_tag_total_count: branch_tag_total_count } rescue return { repo: {}, - release: [], - branch: [], - branch_type: [], - tag: [], - contributor: [], - language: {}, - readme: {} + branch_tag_total_count: {} } end @@ -35,14 +27,4 @@ class Repositories::DetailService < ApplicationService def repo_suitable Gitea::Repository::GetService.call(@owner, @repo.identifier) end - - def contributor_suitable - contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repo.identifier) - contributors.is_a?(Hash) && contributors.key?(:status) ? [] : contributors - end - - def language_suitable - result = Gitea::Repository::Languages::ListService.call(@owner.login, @repo.identifier, @user&.gitea_token) - result[:status] === :success ? hash_transform_precentagable(result[:body]) : nil - end end diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder index fa52475a5..2fb6abae8 100644 --- a/app/views/repositories/contributors.json.jbuilder +++ b/app/views/repositories/contributors.json.jbuilder @@ -1,5 +1,5 @@ total_count = @contributors.size -json.contributors @contributors.each do |contributor| +json.list @contributors.each do |contributor| json.partial! 'contributor', locals: { contributor: contributor } end json.total_count total_count From 0358229b959b9affdcb31b9c40c1cb8d794e6050 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Dec 2021 14:47:15 +0800 Subject: [PATCH 2/4] fix: educoder api delay --- app/controllers/repositories_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d0b4020c4..3f797a13a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -132,7 +132,7 @@ class RepositoriesController < ApplicationController end def contributors - if params[:filepath].present? + if params[:filepath].present? || @project.educoder? @contributors = [] else @contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) @@ -213,7 +213,11 @@ class RepositoriesController < ApplicationController end def languages - render json: languages_precentagable + if @project.educoder? + render json: {} + else + render json: languages_precentagable + end end def archive From 422549f9e798e0a360e094fe48e011deb09e2e39 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Dec 2021 15:01:33 +0800 Subject: [PATCH 3/4] fix --- app/views/repositories/detail.json.jbuilder | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index b741e01f9..14db8b092 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -53,13 +53,13 @@ end json.license_name @project.license_name json.branches_count @result[:branch_tag_total_count].present? ? (@result[:branch_tag_total_count]['branch_count'] || 0) : 0 json.tags_count @result[:branch_tag_total_count].present? ? (@result[:branch_tag_total_count]['tag_count'] || 0) : 0 -json.contributors do - total_count = @result[:contributor].size - json.list @result[:contributor].each do |contributor| - json.partial! 'contributor', locals: { contributor: contributor } - end - json.total_count total_count -end -json.languages @result[:language].blank? ? nil : @result[:language] +# json.contributors do +# total_count = @result[:contributor].size +# json.list @result[:contributor].each do |contributor| +# json.partial! 'contributor', locals: { contributor: contributor } +# end +# json.total_count total_count +# end +# json.languages @result[:language].blank? ? nil : @result[:language] json.partial! 'author', locals: { user: @project.owner } From e0c47c2abdd707a315b0c2842c2ce2fc19ede353 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Dec 2021 16:18:13 +0800 Subject: [PATCH 4/4] fix: educoder clone url --- app/controllers/repositories_controller.rb | 2 +- app/views/repositories/commits.json.jbuilder | 24 ++++++++++++++++++-- app/views/repositories/detail.json.jbuilder | 2 +- app/views/repositories/entries.json.jbuilder | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 3f797a13a..0292dc1d1 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -96,7 +96,7 @@ class RepositoriesController < ApplicationController def commits if @project.educoder? - @hash_commit = nil + @commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name) else if params[:filepath].present? file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) diff --git a/app/views/repositories/commits.json.jbuilder b/app/views/repositories/commits.json.jbuilder index 33406e6a5..11644f832 100644 --- a/app/views/repositories/commits.json.jbuilder +++ b/app/views/repositories/commits.json.jbuilder @@ -1,6 +1,26 @@ -if @hash_commit.blank? #如果有状态值,则表示报错了 +if @hash_commit.blank? || @project.educoder? #如果有状态值,则表示报错了 json.total_count 0 - json.commits [] + json.commits do + json.array! @commits do |commit| + json.sha commit['id'] + json.message commit['title'] + json.time_from_now commit['time'] + json.author do + json.id nil + json.login commit['author']['username'] + json.name commit['author']['username'] + json.type nil + json.image_url commit['author']['image_url'] + end + json.commiter do + json.id nil + json.login commit['author']['username'] + json.name commit['author']['username'] + json.type nil + json.image_url commit['author']['image_url'] + end + end + end else json.total_count @hash_commit[:total_count] json.commits do diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index 14db8b092..9381c4737 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -44,7 +44,7 @@ end if @result[:repo] json.size replace_bytes_to_b(number_to_human_size(@result[:repo]['size'].to_i*1024)) json.ssh_url @result[:repo]['ssh_url'] - json.clone_url @result[:repo]['clone_url'] + json.clone_url @project.educoder? ? "#{Rails.application.config_for(:configuration)['educoder']['git_site']}/#{@project&.project_educoder&.repo_name}.git" : @result[:repo]['clone_url'] json.default_branch @project.educoder? ? "master" : @result[:repo]['default_branch'] json.empty @result[:repo]['empty'] json.full_name @result[:repo]['full_name'] diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 8d1e67beb..6dea93b32 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -7,7 +7,7 @@ if @project.educoder? end end json.commits_count @entries['commit_count'] - json.zip_url @entries['git_url'] + json.zip_url '' json.tar_url '' json.entries do json.array! @entries['trees'] do |entry|