add: get project all files

This commit is contained in:
vilet.yy 2021-03-16 10:25:37 +08:00
parent b43926f69f
commit 34d95451b5
3 changed files with 35 additions and 2 deletions

View File

@ -7,10 +7,17 @@ class RepositoriesController < ApplicationController
before_action :load_repository
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
before_action :get_ref, only: %i[entries sub_entries top_counts]
before_action :get_ref, only: %i[entries sub_entries top_counts file]
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
before_action :get_statistics, only: %i[top_counts]
def files
result = @project.educoder? ? nil : Gitea::Repository::Files::GetService.call(@project.owner, @project.identifier, @ref)
render json: result
end
# 新版项目详情
def detail
@user = current_user

View File

@ -0,0 +1,25 @@
class Gitea::Repository::Files::GetService < Gitea::ClientService
attr_reader :owner, :repo_name, :ref, :q, :token
def initialize(owner, repo_name, ref, q=nil, token=nil)
@owner = owner
@repo_name = repo_name
@ref = ref
@q = q
@token = token
end
def call
response = get(url, params)
render_status(response)
end
private
def params
Hash.new.merge(token: token, ref: ref, q: q)
end
def url
"/repos/#{owner.login}/#{repo_name}/find"
end
end

View File

@ -378,8 +378,9 @@ Rails.application.routes.draw do
end
end
resource :repositories, path: '/', only: [:show, :create, :edit] do
resource :repositories, path: '/', only: [:show, :create, :edit] do
member do
get :files
get :detail
get :archive
get :top_counts