fixed:educode项目

This commit is contained in:
xiaoxiaoqiong 2021-12-07 16:20:05 +08:00
parent 51356da7f3
commit 36286d9003
3 changed files with 34 additions and 18 deletions

View File

@ -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

View File

@ -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?

View File

@ -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']