Update reposotiry's sub entries api
This commit is contained in:
parent
96ed75f6b0
commit
acc0bfb7aa
|
@ -6,6 +6,7 @@ class RepositoriesController < ApplicationController
|
|||
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
|
||||
before_action :find_repository_by_id, only: %i[commit sync_mirror tags]
|
||||
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
||||
before_action :get_latest_commit, only: %i[entries sub_entries]
|
||||
|
||||
def show
|
||||
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
||||
|
@ -25,20 +26,14 @@ 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]
|
||||
|
||||
@entries = Gitea::Repository::Entries::ListService.new(@project.owner, @project.identifier, ref: @ref).call
|
||||
@entries = Gitea::Repository::Entries::ListService.new(@project.owner, @project.identifier, ref: get_ref).call
|
||||
@entries = @entries.sort_by{ |hash| hash['type'] }
|
||||
end
|
||||
|
||||
def sub_entries
|
||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: params[:ref])
|
||||
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: get_ref)
|
||||
if interactor.success?
|
||||
@sub_entries = interactor.result
|
||||
@sub_entries = [] << @sub_entries unless @sub_entries.is_a? Array
|
||||
|
@ -134,6 +129,17 @@ class RepositoriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# TODO 获取最新commit信息
|
||||
def get_latest_commit
|
||||
@latest_commit = Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||
@latest_commit = @latest_commit.blank? ? nil : @latest_commit[:body][0]
|
||||
end
|
||||
|
||||
def get_ref
|
||||
params[:ref] || "master"
|
||||
end
|
||||
|
||||
def content_params
|
||||
{
|
||||
filepath: params[:filepath],
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
|
||||
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! @sub_entries do |entry|
|
||||
json.partial! 'repositories/simple_entry', locals: { entry: entry }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue