Update get repo entries dir api

This commit is contained in:
Jasder 2020-06-03 11:21:43 +08:00
parent 9f9cec34b6
commit 96ed75f6b0
3 changed files with 34 additions and 25 deletions

View File

@ -8,7 +8,7 @@ class RepositoriesController < ApplicationController
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
def show
@branches_count = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call&.size
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
@commits_count = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call[:total_count]
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
@ -25,8 +25,13 @@ class RepositoriesController < ApplicationController
def entries
@project.increment!(:visits)
@ref = params[:ref] || "master"
# TODO 获取最新commit信息
@latest_commit = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
sha: @ref, page: 1, limit: 1, token: current_user&.gitea_token).call
@latest_commit = @latest_commit.blank? ? nil : @latest_commit[:body][0]
@ref = params[:branch] || "master"
@entries = Gitea::Repository::Entries::ListService.new(@project.owner, @project.identifier, ref: @ref).call
@entries = @entries.sort_by{ |hash| hash['type'] }
end

View File

@ -0,0 +1,16 @@
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

View File

@ -1,23 +1,12 @@
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']
# json.content entry['content']
# json.target entry['target']
# json.commit entry['commit']
if entry['name'] == "README.md"
readme_md = Gitea::Repository::Entries::GetService.new(@project.owner, @project.identifier, entry['path'], ref:@ref).call
json.name readme_md['name']
json.path readme_md['path']
json.sha readme_md['sha']
json.type readme_md['type']
json.size readme_md['size']
json.content readme_md['content'].present? ? render_decode64_content(readme_md['content']).force_encoding('UTF-8') : ""
json.target readme_md['target']
json.last_commit do
if @latest_commit
json.partial! 'commit', commit: @latest_commit, project: @project
else
json.nil!
end
end
json.entries do
json.array! @entries do |entry|
json.name entry['name']
json.path entry['path']
json.sha entry['sha']
@ -25,9 +14,8 @@ json.array! @entries do |entry|
json.size entry['size']
json.content entry['content']
json.target entry['target']
end
if entry['latest_commit']
json.partial! 'last_commit', entry: entry
if entry['latest_commit']
json.partial! 'last_commit', entry: entry
end
end
end