Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie
This commit is contained in:
commit
385abd53b7
|
@ -7,8 +7,9 @@ class RepositoriesController < ApplicationController
|
||||||
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
|
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
|
||||||
before_action :find_repository_by_id, only: %i[commit sync_mirror tags]
|
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 :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
||||||
before_action :get_ref, only: %i[entries sub_entries]
|
before_action :get_ref, only: %i[entries sub_entries top_counts]
|
||||||
before_action :get_statistics, only: %i[entries sub_entries]
|
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
|
||||||
|
before_action :get_statistics, only: %i[top_counts]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = current_user
|
@user = current_user
|
||||||
|
@ -32,6 +33,10 @@ class RepositoriesController < ApplicationController
|
||||||
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def top_counts
|
||||||
|
@result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
|
||||||
|
end
|
||||||
|
|
||||||
def sub_entries
|
def sub_entries
|
||||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: @ref)
|
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: @ref)
|
||||||
|
@ -122,7 +127,7 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO 获取最新commit信息
|
# TODO 获取最新commit信息
|
||||||
def get_latest_commit
|
def project_commits
|
||||||
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||||
end
|
end
|
||||||
|
@ -130,16 +135,18 @@ class RepositoriesController < ApplicationController
|
||||||
def get_statistics
|
def get_statistics
|
||||||
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
@branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size
|
||||||
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
||||||
|
|
||||||
latest_commit = get_latest_commit
|
|
||||||
@latest_commit = latest_commit[:body][0] if latest_commit.present?
|
|
||||||
@commits_count = latest_commit[:total_count] if latest_commit.present?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ref
|
def get_ref
|
||||||
@ref = params[:ref] || "master"
|
@ref = params[:ref] || "master"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_latest_commit
|
||||||
|
latest_commit = project_commits
|
||||||
|
@latest_commit = latest_commit[:body][0] if latest_commit.present?
|
||||||
|
@commits_count = latest_commit[:total_count] if latest_commit.present?
|
||||||
|
end
|
||||||
|
|
||||||
def content_params
|
def content_params
|
||||||
{
|
{
|
||||||
filepath: params[:filepath],
|
filepath: params[:filepath],
|
||||||
|
|
|
@ -38,6 +38,9 @@ class Project < ApplicationRecord
|
||||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||||
|
|
||||||
|
|
||||||
|
def self.search_project(search)
|
||||||
|
ransack(name_or_identifier_cont: search)
|
||||||
|
end
|
||||||
# 创建者
|
# 创建者
|
||||||
def creator
|
def creator
|
||||||
User.find(user_id).full_name
|
User.find(user_id).full_name
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Projects::ListQuery < ApplicationQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
q = Project.visible.ransack(name_or_identifier_cont: params[:search])
|
q = Project.visible.search_project(params[:search])
|
||||||
|
|
||||||
scope = q.result(distinct: true)
|
scope = q.result(distinct: true)
|
||||||
.includes(:project_category, :project_language, :repository, owner: :user_extension)
|
.includes(:project_category, :project_language, :repository, owner: :user_extension)
|
||||||
|
|
|
@ -5,9 +5,9 @@ json.last_commit do
|
||||||
json.nil!
|
json.nil!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
json.tags_count @tags_count
|
#json.tags_count @tags_count
|
||||||
json.branches_count @branches_count
|
#json.branches_count @branches_count
|
||||||
json.commits_count @commits_count
|
#json.commits_count @commits_count
|
||||||
json.zip_url render_zip_url(@project, @ref)
|
json.zip_url render_zip_url(@project, @ref)
|
||||||
json.tar_url render_tar_url(@project, @ref)
|
json.tar_url render_tar_url(@project, @ref)
|
||||||
json.entries do
|
json.entries do
|
||||||
|
|
|
@ -6,9 +6,9 @@ json.last_commit do
|
||||||
json.nil!
|
json.nil!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
json.tags_count @tags_count
|
#json.tags_count @tags_count
|
||||||
json.branches_count @branches_count
|
#json.branches_count @branches_count
|
||||||
json.commits_count @commits_count
|
#json.commits_count @commits_count
|
||||||
json.entries do
|
json.entries do
|
||||||
json.array! @sub_entries do |entry|
|
json.array! @sub_entries do |entry|
|
||||||
json.partial! 'repositories/simple_entry', locals: { entry: entry }
|
json.partial! 'repositories/simple_entry', locals: { entry: entry }
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
json.tags_count @tags_count
|
||||||
|
json.branches_count @branches_count
|
||||||
|
json.commits_count @commits_count
|
||||||
|
json.version_releasesed_count @project.releases_size(current_user.try(:id), "released") #已发行的版本
|
||||||
|
if @result
|
||||||
|
json.size replace_bytes_to_b(number_to_human_size(@result['size'].to_i*1024))
|
||||||
|
end
|
|
@ -214,6 +214,7 @@ Rails.application.routes.draw do
|
||||||
delete :delete_file
|
delete :delete_file
|
||||||
post :repo_hook
|
post :repo_hook
|
||||||
post :sync_mirror
|
post :sync_mirror
|
||||||
|
get :top_counts
|
||||||
get 'commits/:sha', to: 'repositories#commit', as: 'commit'
|
get 'commits/:sha', to: 'repositories#commit', as: 'commit'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue