Browse Source

add: get project all files

tags/v3.0.1
vilet.yy 5 years ago
parent
commit
34d95451b5
3 changed files with 35 additions and 2 deletions
  1. +8
    -1
      app/controllers/repositories_controller.rb
  2. +25
    -0
      app/services/gitea/repository/files/get_service.rb
  3. +2
    -1
      config/routes.rb

+ 8
- 1
app/controllers/repositories_controller.rb 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


+ 25
- 0
app/services/gitea/repository/files/get_service.rb 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

+ 2
- 1
config/routes.rb 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


Loading…
Cancel
Save