From 281889ebae7f01f4be42e5809f8e975704b15051 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 3 Jul 2020 15:14:25 +0800 Subject: [PATCH 1/3] change counts --- app/controllers/repositories_controller.rb | 8 ++++++-- app/models/project.rb | 3 +++ app/queries/projects/list_query.rb | 2 +- app/views/repositories/entries.json.jbuilder | 6 +++--- app/views/repositories/sub_entries.json.jbuilder | 6 +++--- app/views/repositories/top_counts.json.jbuilder | 7 +++++++ config/routes.rb | 1 + 7 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 app/views/repositories/top_counts.json.jbuilder diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 65c2f404c..3b5952459 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -7,8 +7,8 @@ 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_ref, only: %i[entries sub_entries] - before_action :get_statistics, only: %i[entries sub_entries] + before_action :get_ref, only: %i[entries sub_entries top_counts] + before_action :get_statistics, only: %i[top_counts] def show @user = current_user @@ -32,6 +32,10 @@ class RepositoriesController < ApplicationController @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" end + def top_counts + @result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call + 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: @ref) diff --git a/app/models/project.rb b/app/models/project.rb index 1d6fd0327..e70c932bd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -38,6 +38,9 @@ class Project < ApplicationRecord 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 User.find(user_id).full_name diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index 6b145c81a..91a2a7627 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -10,7 +10,7 @@ class Projects::ListQuery < ApplicationQuery end def call - q = Project.visible.ransack(name_or_identifier_cont: params[:search]) + q = Project.visible.search_project(params[:search]) scope = q.result(distinct: true) .includes(:project_category, :project_language, :repository, owner: :user_extension) diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 7b2c7c6e6..636845efd 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -5,9 +5,9 @@ json.last_commit do json.nil! end end -json.tags_count @tags_count -json.branches_count @branches_count -json.commits_count @commits_count +#json.tags_count @tags_count +#json.branches_count @branches_count +#json.commits_count @commits_count json.zip_url render_zip_url(@project, @ref) json.tar_url render_tar_url(@project, @ref) json.entries do diff --git a/app/views/repositories/sub_entries.json.jbuilder b/app/views/repositories/sub_entries.json.jbuilder index 43dbf764e..2032df857 100644 --- a/app/views/repositories/sub_entries.json.jbuilder +++ b/app/views/repositories/sub_entries.json.jbuilder @@ -6,9 +6,9 @@ json.last_commit do json.nil! end end -json.tags_count @tags_count -json.branches_count @branches_count -json.commits_count @commits_count +#json.tags_count @tags_count +#json.branches_count @branches_count +#json.commits_count @commits_count json.entries do json.array! @sub_entries do |entry| json.partial! 'repositories/simple_entry', locals: { entry: entry } diff --git a/app/views/repositories/top_counts.json.jbuilder b/app/views/repositories/top_counts.json.jbuilder new file mode 100644 index 000000000..a5f5b9938 --- /dev/null +++ b/app/views/repositories/top_counts.json.jbuilder @@ -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 diff --git a/config/routes.rb b/config/routes.rb index ffda83821..ba9efd909 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,6 +214,7 @@ Rails.application.routes.draw do delete :delete_file post :repo_hook post :sync_mirror + get :top_counts get 'commits/:sha', to: 'repositories#commit', as: 'commit' end end From 7995a82d6a178ed44428f9b9faa66fe6a3bc6c99 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 3 Jul 2020 16:13:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9commits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 3b5952459..0f672b5ab 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -9,6 +9,7 @@ class RepositoriesController < ApplicationController 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_statistics, only: %i[top_counts] + before_action :get_latest_commit, %i[entries sub_entries top_counts] def show @user = current_user @@ -126,7 +127,7 @@ class RepositoriesController < ApplicationController end # TODO 获取最新commit信息 - def get_latest_commit + def project_commits Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call end @@ -134,16 +135,18 @@ class RepositoriesController < ApplicationController def get_statistics @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 - - 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 def get_ref @ref = params[:ref] || "master" 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 { filepath: params[:filepath], From 6d536aae62dcf6f5b1fb959771047da76a8df00b Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Fri, 3 Jul 2020 16:22:23 +0800 Subject: [PATCH 3/3] change errors --- app/controllers/repositories_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 0f672b5ab..840c8a1b0 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -8,8 +8,8 @@ class RepositoriesController < ApplicationController 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_ref, only: %i[entries sub_entries top_counts] + before_action :get_latest_commit, only: %i[entries sub_entries top_counts] before_action :get_statistics, only: %i[top_counts] - before_action :get_latest_commit, %i[entries sub_entries top_counts] def show @user = current_user