Merge branch 'develop' into standalone_develop
This commit is contained in:
commit
a01c98164a
2
Gemfile
2
Gemfile
|
@ -139,4 +139,4 @@ gem 'doorkeeper'
|
|||
|
||||
gem 'doorkeeper-jwt'
|
||||
|
||||
gem 'gitea-client', '~> 0.10.5'
|
||||
gem 'gitea-client', '~> 0.10.6'
|
|
@ -0,0 +1,8 @@
|
|||
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)
|
||||
puts @result_object
|
||||
end
|
||||
end
|
|
@ -0,0 +1,34 @@
|
|||
class Api::V1::Projects::CodeStats::ListService < ApplicationService
|
||||
|
||||
attr_reader :project, :ref, :owner, :repo, :token
|
||||
attr_accessor :gitea_data
|
||||
|
||||
def initialize(project, params, token=nil)
|
||||
@project = project
|
||||
@ref = params[:ref]
|
||||
@owner = project&.owner.login
|
||||
@repo = project&.identifier
|
||||
@token = token
|
||||
end
|
||||
|
||||
def call
|
||||
load_gitea_data
|
||||
|
||||
gitea_data
|
||||
end
|
||||
|
||||
private
|
||||
def request_params
|
||||
param = {
|
||||
access_token: token
|
||||
}
|
||||
param.merge!(ref: ref) if ref.present?
|
||||
|
||||
param
|
||||
end
|
||||
|
||||
def load_gitea_data
|
||||
@gitea_data = $gitea_client.get_repos_code_stats_by_owner_repo(owner, repo, {query: request_params}) rescue nil
|
||||
raise Error, '获取贡献者贡献度失败!' unless @gitea_data.is_a?(Hash)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
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.author do
|
||||
json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(author), name: author['name'] }
|
||||
end
|
||||
json.commits author["commits"]
|
||||
json.additions author["additions"]
|
||||
json.deletions author["deletions"]
|
||||
end
|
|
@ -54,6 +54,7 @@ defaults format: :json do
|
|||
end
|
||||
end
|
||||
resources :commits, only: [:index]
|
||||
resources :code_stats, only: [:index]
|
||||
get '/commits/:sha/diff', to: 'commits#diff'
|
||||
get '/git/blobs/:sha', to: 'git#blobs'
|
||||
get '/git/trees/:sha', to: 'git#trees'
|
||||
|
|
Loading…
Reference in New Issue