统计提交数
This commit is contained in:
parent
ec85b80a98
commit
bb59f0ead8
|
@ -0,0 +1,54 @@
|
|||
namespace :total_commit_count do
|
||||
desc "total_commit_count"
|
||||
task git_demo_raw: :environment do
|
||||
project_name = ENV['name'] || "mindspore"
|
||||
puts "project_id=================#{project_name}"
|
||||
projects = Project.where("name like ?", "%#{project_name}%")
|
||||
if ENV['count'].present?
|
||||
projects = projects.limit(ENV['count'].to_i)
|
||||
end
|
||||
|
||||
@date_count_hash = {}
|
||||
# projects = Project.where(:name => 'opensource0311')
|
||||
projects.each_with_index do |project, index|
|
||||
result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 5, token: project.owner.gitea_token)
|
||||
total_count = result[:total_count]
|
||||
puts "#{index} total_count==========#{total_count}"
|
||||
if total_count > 50
|
||||
total_page = (total_count / 50) + 1
|
||||
total_page.times do |i|
|
||||
add_commit_to_index(project, i + 1)
|
||||
end
|
||||
else
|
||||
add_commit_to_index(project, 1)
|
||||
end
|
||||
|
||||
end
|
||||
puts "@date_count_hash===========#{@date_count_hash.to_json}"
|
||||
|
||||
|
||||
|
||||
|
||||
# Time.now
|
||||
# Wed Mar 15 14:12:09 2023 +0800
|
||||
# Time.now.strftime("%a %b %d %H:%M:%S %Y")
|
||||
# Time.now.strftime("%a %b %d %H:%M:%S %Y +0800")
|
||||
Time.parse("2023-03-15 14:12:09").strftime("%a %b %d %H:%M:%S %Y +0800")
|
||||
|
||||
end
|
||||
|
||||
def add_commit_to_index(project, page)
|
||||
# Gitea::Repository::Commits::ListSliceService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 1000, token: "a9244ecac647dd33fee3b480c5898baab1d3fe7d")
|
||||
result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: page, limit: 50, token: project.owner.gitea_token)
|
||||
result[:body].each do |commit|
|
||||
commit_date = Time.parse(commit['commit']['author']['date'])
|
||||
commit_date_str = commit_date.strftime("%Y-%m")
|
||||
if @date_count_hash[commit_date_str].present?
|
||||
@date_count_hash[commit_date_str] = @date_count_hash[commit_date_str] + 1
|
||||
else
|
||||
@date_count_hash[commit_date_str] = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue