diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9b94f0d5d..dacdd809a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -95,13 +95,17 @@ class RepositoriesController < ApplicationController end def commits - if params[:filepath].present? - file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) - @hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri, - sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + if @project.educoder? + @hash_commit = nil else - @hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier, - sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + if params[:filepath].present? + file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) + @hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri, + sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + else + @hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier, + sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + end end end @@ -112,8 +116,13 @@ class RepositoriesController < ApplicationController def commit @sha = params[:sha] - @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}) + if @project.educoder? + @commit = {} + @commit_diff ={} + 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}) + end end def tags @@ -195,8 +204,9 @@ class RepositoriesController < ApplicationController else result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) end + @path = Gitea.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/" @readme = result[:status] === :success ? result[:body] : nil - @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref]) + @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path) render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha") rescue render json: nil diff --git a/app/models/project.rb b/app/models/project.rb index 32443e712..e671f0a6e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -366,6 +366,7 @@ class Project < ApplicationRecord logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} " user = Owner.find_by_login namespace_path + user = Owner.new(login: namespace_path) if user.nil? project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}") return nil if project.blank? diff --git a/app/views/repositories/commit.json.jbuilder b/app/views/repositories/commit.json.jbuilder index b15abef77..4c1074c8b 100644 --- a/app/views/repositories/commit.json.jbuilder +++ b/app/views/repositories/commit.json.jbuilder @@ -1,12 +1,17 @@ # json.key_format! camelize: :lower -json.files_count @commit_diff['NumFiles'] -json.total_addition @commit_diff['TotalAddition'] -json.total_deletion @commit_diff['TotalDeletion'] -json.files @commit_diff['Files'], partial: 'pull_requests/diff_file', as: :file, locals: {sha: @sha} +if @commit.blank? #如果有状态值,则表示报错了 + json.total_count 0 + json.commits [] +else + json.files_count @commit_diff['NumFiles'] + json.total_addition @commit_diff['TotalAddition'] + json.total_deletion @commit_diff['TotalDeletion'] + json.files @commit_diff['Files'], partial: 'pull_requests/diff_file', as: :file, locals: {sha: @sha} -json.partial! 'commit', commit: @commit, project: @project -json.parents @commit['parents'] do |parent| - json.sha parent['sha'] - # json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha']) + json.partial! 'commit', commit: @commit, project: @project + json.parents @commit['parents'] do |parent| + json.sha parent['sha'] + # json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha']) + end + json.branch @commit['branch'] end -json.branch @commit['branch']