From 9fe3b5ae3ef0ee17ba4fe5bad98c9cea2a39d6ee Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 2 Feb 2023 18:10:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Acode=5Fstats?= =?UTF-8?q?=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/code_stats_controller.rb | 2 +- .../api/v1/projects/code_stats/list_service.rb | 8 ++++++-- .../v1/projects/code_stats/index.json.jbuilder | 15 ++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v1/projects/code_stats_controller.rb b/app/controllers/api/v1/projects/code_stats_controller.rb index 7ec671f3c..333cfe86a 100644 --- a/app/controllers/api/v1/projects/code_stats_controller.rb +++ b/app/controllers/api/v1/projects/code_stats_controller.rb @@ -2,7 +2,7 @@ class Api::V1::Projects::CodeStatsController < Api::V1::BaseController before_action :require_public_and_member_above, only: [:index] def index - @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token) + @result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {page: page, limit, limit, ref: params[:ref]}, current_user&.gitea_token) puts @result_object end end \ No newline at end of file diff --git a/app/services/api/v1/projects/code_stats/list_service.rb b/app/services/api/v1/projects/code_stats/list_service.rb index 84f4bac36..fa9d68bec 100644 --- a/app/services/api/v1/projects/code_stats/list_service.rb +++ b/app/services/api/v1/projects/code_stats/list_service.rb @@ -1,6 +1,6 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService - attr_reader :project, :ref, :owner, :repo, :token + attr_reader :project, :ref, :owner, :repo, :token, :page, :limit attr_accessor :gitea_data def initialize(project, params, token=nil) @@ -9,6 +9,8 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService @owner = project&.owner.login @repo = project&.identifier @token = token + @page = params[:page] + @limit = params[:limit] end def call @@ -20,7 +22,9 @@ class Api::V1::Projects::CodeStats::ListService < ApplicationService private def request_params param = { - access_token: token + access_token: token, + page: page, + limit: limit } param.merge!(ref: ref) if ref.present? diff --git a/app/views/api/v1/projects/code_stats/index.json.jbuilder b/app/views/api/v1/projects/code_stats/index.json.jbuilder index 0b64270f7..ecb4767e4 100644 --- a/app/views/api/v1/projects/code_stats/index.json.jbuilder +++ b/app/views/api/v1/projects/code_stats/index.json.jbuilder @@ -1,10 +1,11 @@ -json.author_count @result_object["author_count"] -json.commit_count @result_object["commit_count"] -json.change_files @result_object["change_files"] -json.additions @result_object["additions"] -json.deletions @result_object["deletions"] -json.commit_count_in_all_branches @result_object["commit_count_in_all_branches"] -json.authors @result_object["authors"].each do |author| +json.total_count @result_object[:total_data].to_i +json.author_count @result_object[:data]["author_count"] +json.commit_count @result_object[:data]["commit_count"] +json.change_files @result_object[:data]["change_files"] +json.additions @result_object[:data]["additions"] +json.deletions @result_object[:data]["deletions"] +json.commit_count_in_all_branches @result_object[:data]["commit_count_in_all_branches"] +json.authors @result_object[:data]["authors"].each do |author| json.author do json.partial! 'api/v1/users/commit_user_email', locals: { user: render_cache_commit_author(author), name: author['name'], email: author['email'] } end