Merge branch 'develop' into standalone_develop
This commit is contained in:
commit
2ca5a908aa
2
Gemfile
2
Gemfile
|
@ -143,4 +143,4 @@ gem 'doorkeeper'
|
|||
|
||||
gem 'doorkeeper-jwt'
|
||||
|
||||
gem 'gitea-client', '~> 1.4.1'
|
||||
gem 'gitea-client', '~> 1.4.2'
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class Api::V1::Projects::ContributorsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index, :stat]
|
||||
|
||||
# todo
|
||||
def index
|
||||
end
|
||||
|
||||
def stat
|
||||
@result_object = Api::V1::Projects::Contributors::StatService.call(@project, {branch: params[:branch], pass_year: params[:pass_year], page: page, limit: limit}, current_user&.gitea_token)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,38 @@
|
|||
class Api::V1::Projects::Contributors::StatService < ApplicationService
|
||||
|
||||
attr_reader :project, :branch, :pass_year, :owner, :repo, :token, :page, :limit
|
||||
attr_accessor :gitea_data
|
||||
|
||||
def initialize(project, params, token=nil)
|
||||
@project = project
|
||||
@branch = params[:branch]
|
||||
@pass_year = params[:pass_year]
|
||||
@page = params[:page] || 1
|
||||
@limit = params[:limit] || 15
|
||||
@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!(branch: branch) if branch.present?
|
||||
param.merge!(pass_year: pass_year) if pass_year.present?
|
||||
|
||||
param
|
||||
end
|
||||
|
||||
def load_gitea_data
|
||||
@gitea_data = $gitea_hat_client.get_repos_contributors_stat_by_owner_repo(owner, repo, {query: request_params}) rescue nil
|
||||
raise Error, '获取贡献者(代码行)失败!' unless @gitea_data.is_a?(Hash)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
json.total_count @result_object[:total_data].to_i
|
||||
json.contributors @result_object[:data].each do |contributor|
|
||||
user = $redis_cache.hgetall("v2-owner-common:#{contributor["name"]}-#{contributor["email"]}")
|
||||
if user.blank?
|
||||
json.contributions contributor["commits"]
|
||||
json.additions contributor["additions"]
|
||||
json.deletions contributor["deletions"]
|
||||
# json.id contributor["id"]
|
||||
json.login contributor["name"]
|
||||
json.email contributor["email"]
|
||||
json.type nil
|
||||
json.name contributor["name"]
|
||||
json.image_url User::Avatar.get_letter_avatar_url(contributor["name"])
|
||||
else
|
||||
json.contributions contributor["commits"]
|
||||
json.additions contributor["additions"]
|
||||
json.deletions contributor["deletions"]
|
||||
json.id user["id"]
|
||||
json.login user["login"]
|
||||
json.email user["email"]
|
||||
json.name user["name"]
|
||||
json.type user["type"]
|
||||
json.name user["name"]
|
||||
json.image_url user["avatar_url"]
|
||||
end
|
||||
end
|
|
@ -82,6 +82,11 @@ defaults format: :json do
|
|||
|
||||
resources :commits, only: [:index]
|
||||
resources :code_stats, only: [:index]
|
||||
resources :contributors, only: [:index] do
|
||||
collection do
|
||||
get :stat
|
||||
end
|
||||
end
|
||||
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