mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-17 18:25:56 +08:00
Merge branch 'develop' into standalone_develop
This commit is contained in:
38
app/services/api/v1/projects/contributors/stat_service.rb
Normal file
38
app/services/api/v1/projects/contributors/stat_service.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user