ADD repository show api

dev_forge
Jasder 5 years ago
parent 8ab4d9dc58
commit e169f9e361

@ -2,6 +2,9 @@ class RepositoriesController < ApplicationController
include ApplicationHelper
before_action :find_user, :find_repository, :authorizate!
def show
end
def entries
@entries = Gitea::Repository::Entries::ListService.new(@user, @repo.identifier, ref: params[:ref]).call
end
@ -23,6 +26,10 @@ class RepositoriesController < ApplicationController
@commit = Gitea::Repository::Commits::GetService.new(@user, @repo.identifier, params[:sha]).call
end
def tags
@tags = Gitea::Repository::Tags::ListService.new(@user, @repo.identifier).call
end
private
def authorizate!
if @repo.hidden? && @repo.user != current_user

@ -1,6 +1,7 @@
class Project < ApplicationRecord
include Matchable
include Publicable
include Watchable
enum project_type: { mirror: 1, common: 0 } # common:开源托管项目, mirror:开源镜像项目

@ -1,4 +1,4 @@
class Watcher < ApplicationRecord
belongs_to :user
belongs_to :watchable, polymorphic: true
belongs_to :watchable, polymorphic: true, counter_cache: :watchers_count
end

@ -0,0 +1,5 @@
json.identifier @repo.identifier
json.praises_count @repo.project.praises_count
json.forked_count @repo.project.forked_count
json.watchers_count @repo.project.watchers_count
json.partial! 'author', locals: { user: @repo.user }

@ -1,4 +1,5 @@
Rails.application.routes.draw do
require 'sidekiq/web'
require 'admin_constraint'
mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new
@ -59,12 +60,22 @@ Rails.application.routes.draw do
end
end
get '/:login/:repo_identifier', to: 'repositories#show'
resources :repositories, path: '/:login/:repo_identifier', only: [:index] do
collection do
get :entries
get :sub_entries
get :commits
get :single_commit
post :files
get :tags
end
end
resources :contents, path: '/:login/:repo_identifier/contents', only: [:create] do
collection do
put 'files/update', :action => 'update_file'
delete 'files/delete', :action => 'delete_file'
end
end

Loading…
Cancel
Save