Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
commit
d8f951449b
|
@ -0,0 +1,5 @@
|
|||
class UpdateCommitLogMessage < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
execute("ALTER TABLE `commit_logs` MODIFY `message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,78 @@
|
|||
namespace :commit_log_to_db do
|
||||
desc "commit_log_to_db"
|
||||
task done: :environment do
|
||||
puts "project_id=================#{ENV['project_id']}"
|
||||
return if ENV['project_id'].blank?
|
||||
projects = Project.where(id: ENV['project_id'])
|
||||
projects.each_with_index do |project, index|
|
||||
result = Gitea::Repository::Commits::ListService.call(project.owner.login,project.identifier,sha: "", page: 1, limit: 200, token: project.owner.gitea_token)
|
||||
next if result.blank? || result[:total_count].blank?
|
||||
total_count = result[:total_count]
|
||||
# next if total_count > 2000
|
||||
puts "#{index} total_count==========#{total_count}"
|
||||
if total_count > 200
|
||||
total_page = (total_count / 200) + 1
|
||||
total_page.times do |i|
|
||||
add_commit_by_page(project, i + 1)
|
||||
end
|
||||
else
|
||||
# add_commit_to_index(project, 1)
|
||||
data = ""
|
||||
result[:body].each do |commit|
|
||||
# puts "commit==========#{commit}"
|
||||
commiter = commit['commit']['committer']
|
||||
# "luoyuan <luoyuan7@huawei.com>"
|
||||
commit_author = "#{commiter['name']} <#{commiter['email']}>"
|
||||
commit_sha = commit['sha']
|
||||
ref = "master"
|
||||
commit_message = commit['commit']['message'].to_s.gsub("\"","")
|
||||
user = User.find_by(mail: commiter['email'])
|
||||
user_id = user&.id || project.user_id
|
||||
commit_date = Time.parse(commit['commit']['author']['date'])
|
||||
commit_date_str = commit_date.strftime("%a %b %d %H:%M:%S")
|
||||
|
||||
data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}'),"
|
||||
end
|
||||
data = data[0,data.length-1]
|
||||
sql_connection = ActiveRecord::Base.connection
|
||||
sql_connection.begin_db_transaction
|
||||
sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}"
|
||||
sql_connection.execute(sql)
|
||||
end
|
||||
end
|
||||
|
||||
# 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_by_page(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: 200, token: project.owner.gitea_token)
|
||||
data = ""
|
||||
result[:body].each do |commit|
|
||||
# puts "commit==========#{commit}"
|
||||
commiter = commit['commit']['committer']
|
||||
# "luoyuan <luoyuan7@huawei.com>"
|
||||
commit_author = "#{commiter['name']} <#{commiter['email']}>"
|
||||
commit_sha = commit['sha']
|
||||
ref = "master"
|
||||
commit_message = commit['commit']['message'].to_s.gsub("/n","").gsub("\"","")
|
||||
user = User.find_by(mail: commiter['email'])
|
||||
user_id = user&.id || project.user_id
|
||||
commit_date = Time.parse(commit['commit']['author']['date'])
|
||||
commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
data += "(#{user_id},#{project.id},#{project.repository&.id},'#{project.identifier}','#{project.owner.name}/#{project.identifier}','#{commit_sha}','#{ref}',\"#{commit_message}\",'#{commit_date_str}','#{commit_date_str}'),"
|
||||
end
|
||||
data = data[0,data.length-1]
|
||||
sql_connection = ActiveRecord::Base.connection
|
||||
sql_connection.begin_db_transaction
|
||||
sql = "INSERT INTO commit_logs (`user_id`, `project_id`, `repository_id`, `name`, `full_name`, `commit_id`, `ref`, `message`, `created_at`, `updated_at`) VALUES #{data}"
|
||||
sql_connection.execute(sql)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,65 @@
|
|||
namespace :total_commit_to_db do
|
||||
desc "total_commit_to_db"
|
||||
task done: :environment do
|
||||
project_name = ENV['name'] || "mindspore"
|
||||
puts "project_id=================#{project_name}"
|
||||
projects = Project.where(identifier: ['MindSpore-first-experience', ' MindSpore-install', 'MindSpore-Application-practice', 'MindSpore-Model-Development', 'MindSpore-Data-preprocessing', 'Mindspore-Data-storage-use', 'MindSpore-Data-storage-kunpeng', 'MindSpore-LeNet-jzx3', 'MindSpore-competition'] )
|
||||
|
||||
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)
|
||||
next if result.blank? || result[:total_count].blank?
|
||||
total_count = result[:total_count]
|
||||
# next if total_count > 2000
|
||||
puts "#{index} total_count==========#{total_count}"
|
||||
if total_count > 200
|
||||
total_page = (total_count / 200) + 1
|
||||
total_page.times do |i|
|
||||
add_commit_to_index(project, i + 1)
|
||||
end
|
||||
else
|
||||
# add_commit_to_index(project, 1)
|
||||
data = ""
|
||||
result[:body].each do |commit|
|
||||
commit_date = Time.parse(commit['commit']['author']['date'])
|
||||
commit_date_str = commit_date.strftime("%Y-%m-%d")
|
||||
data += "(\"#{commit_date_str}\",1),"
|
||||
end
|
||||
data = data[0,data.length-1]
|
||||
sql_connection = ActiveRecord::Base.connection
|
||||
sql_connection.begin_db_transaction
|
||||
sql = "insert into mindspore_commit(week_date,num) values #{data}"
|
||||
sql_connection.execute(sql)
|
||||
end
|
||||
puts "#{index} date_count_hash===========#{@date_count_hash.to_json}"
|
||||
|
||||
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: 200, token: project.owner.gitea_token)
|
||||
data = ""
|
||||
result[:body].each do |commit|
|
||||
commit_date = Time.parse(commit['commit']['author']['date'])
|
||||
commit_date_str = commit_date.strftime("%Y-%m-%d")
|
||||
data += "(\"#{commit_date_str}\",1),"
|
||||
end
|
||||
data = data[0,data.length-1]
|
||||
sql_connection = ActiveRecord::Base.connection
|
||||
sql_connection.begin_db_transaction
|
||||
sql = "insert into mindspore_commit(week_date,num) values #{data}"
|
||||
sql_connection.execute(sql)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue