FIX 版本库兼容euducoder平台数据

This commit is contained in:
Jasder
2020-10-22 18:00:31 +08:00
parent 1feb238e80
commit 58f8d60646
12 changed files with 240 additions and 111 deletions

View File

@@ -1,6 +1,6 @@
json.id project.id
json.repo_id project&.repository&.id
json.identifier project.identifier
json.identifier render_identifier(project)
json.name project.name
json.description Nokogiri::HTML(project.description).text
json.visits project.visits
@@ -17,13 +17,13 @@ json.author do
if project.educoder?
project_educoder = project.project_educoder
json.name project_educoder&.owner
json.login project_educoder#.owner
json.image_url project_educoder.image_url
json.login project_educoder&.repo_name.split('/')[0]
json.image_url render_educoder_avatar_url(project.project_educoder)
else
user = project.owner
json.name user.try(:show_real_name)
json.login user.login
json.image_url url_to_avatar(project.owner)
json.image_url render_avatar_url(user)
end
end

View File

@@ -1,5 +1,11 @@
json.author do
json.login user.login
json.name user.real_name
json.image_url url_to_avatar(user)
if @project.forge?
json.login user.login
json.name user.real_name
json.image_url url_to_avatar(user)
else
json.login @project.project_educoder&.repo_name&.split('/')[0]
json.name @project.project_educoder&.owner
json.image_url @project.project_educoder&.image_url
end
end

View File

@@ -1,16 +1,34 @@
json.commit do
json.sha commit['sha']
# json.url EduSetting.get('host_name') + commit_repository_path(project.repository, commit['sha'])
json.message commit['commit']['message']
json.author commit['commit']['author']
json.committer commit['commit']['committer']
json.timestamp render_unix_time(commit['commit']['committer']['date'])
json.time_from_now time_from_now(commit['commit']['committer']['date'])
if @project.educoder?
json.commit do
json.sha commit[0]['id']
json.message commit[0]['title']
json.author {}
json.committer {}
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 {}
end
json.author do
json.partial! 'commit_author', user: render_commit_author(commit['author'])
end
json.committer do
json.partial! 'commit_author', user: render_commit_author(commit['committer'])
if @project.forge?
json.commit do
json.sha commit['sha']
# json.url EduSetting.get('host_name') + commit_repository_path(project.repository, commit['sha'])
json.message commit['commit']['message']
json.author commit['commit']['author']
json.committer commit['commit']['committer']
json.timestamp render_unix_time(commit['commit']['committer']['date'])
json.time_from_now time_from_now(commit['commit']['committer']['date'])
end
json.author do
json.partial! 'commit_author', user: render_commit_author(commit['author'])
end
json.committer do
json.partial! 'commit_author', user: render_commit_author(commit['committer'])
end
end

View File

@@ -1,18 +1,40 @@
file_name = entry['name']
file_type = file_name.to_s.split(".").last
direct_download = download_type(file_type)
image_type = image_type?(file_type)
json.name file_name
json.sha entry['sha']
json.path entry['path']
json.type entry['type']
json.size entry['size']
json.content entry['content'].present? && !direct_download ? render_decode64_content(entry['content']) : ""
json.target entry['target']
json.download_url entry['download_url']
json.direct_download direct_download
json.image_type image_type
json.is_readme_file is_readme_type?(file_name)
if entry['latest_commit']
json.partial! 'last_commit', entry: entry
if @project.forge?
file_name = entry['name']
file_type = file_name.to_s.split(".").last
direct_download = download_type(file_type)
image_type = image_type?(file_type)
json.name file_name
json.sha entry['sha']
json.path entry['path']
json.type entry['type']
json.size entry['size']
json.content entry['content'].present? && !direct_download ? render_decode64_content(entry['content']) : ""
json.target entry['target']
json.download_url entry['download_url']
json.direct_download direct_download
json.image_type image_type
json.is_readme_file is_readme_type?(file_name)
if entry['latest_commit']
json.partial! 'last_commit', entry: entry
end
end
if @project.educoder?
file_path = params[:filepath].present? ? [params[:filepath], entry['name']].join('/') : entry['name']
json.name entry['name']
json.sha nil
json.path file_path
json.type entry['type'] === 'blob'? 'file' : 'dir'
json.size 0
json.content nil
json.target nil
json.download_url nil
json.direct_download false
json.image_type false
json.is_readme_file false
if entry['latest_commit']
# json.partial! 'last_commit', entry: entry
json.partial! 'repositories/simple_entry', locals: { entry: entry }
end
end

View File

@@ -1,36 +1,71 @@
json.last_commit do
if @latest_commit
json.partial! 'commit', commit: @latest_commit, project: @project
else
json.nil!
if @project.educoder?
json.last_commit do
if @entries['commits']
json.partial! 'commit', commit: @entries['commits'], project: @project
else
json.nil!
end
end
end
#json.tags_count @tags_count
#json.branches_count @branches_count
#json.commits_count @commits_count
json.zip_url render_zip_url(@project, @ref)
json.tar_url render_tar_url(@project, @ref)
json.entries do
json.array! @entries do |entry|
json.name entry['name']
json.path entry['path']
json.sha entry['sha']
json.type entry['type']
json.size entry['size']
content =
if is_readme_type?(entry['name'])
is_readme_file = true
content = Gitea::Repository::Entries::GetService.call(@project_owner, @project.identifier, entry['name'], ref: @ref)['content']
readme_render_decode64_content(content, @path)
else
is_readme_file = false
entry['content']
json.commits_count @entries['commit_count']
json.zip_url @entries['git_url']
json.tar_url ''
json.entries do
json.array! @entries['trees'] do |entry|
json.name entry['name']
json.path entry['name']
json.sha nil
json.type entry['type'] === 'blob'? 'file' : 'dir'
json.size 0
json.is_readme_file false
json.content nil
json.target nil
json.commit do
json.message entry['title']
json.time_from_now entry['time']
json.sha nil
json.created_at_unix nil
json.created_at nil
end
end
end
end
if @project.forge?
json.last_commit do
if @latest_commit
json.partial! 'commit', commit: @latest_commit, project: @project
else
json.nil!
end
end
#json.tags_count @tags_count
#json.branches_count @branches_count
#json.commits_count @commits_count
json.zip_url render_zip_url(@project, @ref)
json.tar_url render_tar_url(@project, @ref)
json.entries do
json.array! @entries do |entry|
json.name entry['name']
json.path entry['path']
json.sha entry['sha']
json.type entry['type']
json.size entry['size']
content =
if is_readme_type?(entry['name'])
is_readme_file = true
content = Gitea::Repository::Entries::GetService.call(@project_owner, @project.identifier, entry['name'], ref: @ref)['content']
readme_render_decode64_content(content, @path)
else
is_readme_file = false
entry['content']
end
json.is_readme_file is_readme_file
json.content content
json.target entry['target']
if entry['latest_commit']
json.partial! 'last_commit', entry: entry
end
json.is_readme_file is_readme_file
json.content content
json.target entry['target']
if entry['latest_commit']
json.partial! 'last_commit', entry: entry
end
end
end

View File

@@ -1,10 +1,10 @@
json.identifier @project.identifier
json.identifier render_identifier(@project)
json.name @project.name
json.project_id @project.id
json.repo_id @repo.id
json.issues_count @project.issues_count.to_i - @project.pull_requests_count.to_i
json.pull_requests_count @project.pull_requests_count
json.project_identifier @project.identifier
json.project_identifier render_identifier(@project)
json.praises_count @project.praises_count.to_i
json.forked_count @project.forked_count.to_i
json.watchers_count @project.watchers_count.to_i
@@ -47,4 +47,4 @@ if @result
json.private @result['private']
end
json.partial! 'author', locals: { user: @project.owner }
json.partial! 'author'

View File

@@ -1,16 +1,32 @@
if @project.forge?
json.last_commit do
if @latest_commit
json.partial! 'commit', commit: @latest_commit, project: @project
else
json.nil!
end
end
#json.tags_count @tags_count
#json.branches_count @branches_count
#json.commits_count @commits_count
json.entries do
json.array! @sub_entries do |entry|
json.partial! 'repositories/simple_entry', locals: { entry: entry }
end
end
end
json.last_commit do
if @latest_commit
json.partial! 'commit', commit: @latest_commit, project: @project
else
json.nil!
end
end
#json.tags_count @tags_count
#json.branches_count @branches_count
#json.commits_count @commits_count
json.entries do
json.array! @sub_entries do |entry|
json.partial! 'repositories/simple_entry', locals: { entry: entry }
if @project.educoder?
json.last_commit do
if @sub_entries['commits']
json.partial! 'commit', commit: @sub_entries['commits'], project: @project
else
json.nil!
end
end
json.entries do
json.array! @sub_entries['trees'] do |entry|
json.partial! 'repositories/simple_entry', locals: { entry: entry }
end
end
end