forked from Trustie/forgeplus
fixed add rake
This commit is contained in:
parent
4c4b48c10e
commit
e61a174ae3
|
|
@ -0,0 +1,54 @@
|
|||
namespace :github_api do
|
||||
desc "github_api"
|
||||
task org: :environment do
|
||||
file = ENV['file'] || "orgs.xlsx"
|
||||
user_type = ENV['type'] || "User"
|
||||
doc = SimpleXlsxReader.open("#{Rails.root}/public/#{file}")
|
||||
data = doc.sheets.first.rowsm
|
||||
data.each_with_index do |row, index|
|
||||
next if index==0
|
||||
org = row[3].to_s.gsub("https://github.com/","")
|
||||
url = URI("https://api.github.com/orgs/#{org}")
|
||||
https = Net::HTTP.new(url.host, url.port)
|
||||
https.use_ssl = true
|
||||
|
||||
request = Net::HTTP::Get.new(url)
|
||||
request["Authorization"] = "Bearer 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"
|
||||
request["Accept"] = "application/vnd.github+json"
|
||||
request["X-GitHub-Api-Version"] = "2022-11-28"
|
||||
|
||||
response = https.request(request)
|
||||
data= JSON.parse(response.read_body)
|
||||
if data.present?
|
||||
puts "#{org},#{data["public_repos"]}"
|
||||
end
|
||||
|
||||
end
|
||||
# data.each_with_index do |row, index|
|
||||
# next if index == 0
|
||||
# begin
|
||||
# user = (user_type == "User" ? User.find_by(login: row[1]) : Owner.find_by(login: row[1]))
|
||||
# project = user.projects.find_by(identifier: row[4])
|
||||
# unless project.present?
|
||||
# p_category = ProjectCategory.find_or_create_by(name: row[6])
|
||||
# p_language = ProjectLanguage.find_or_create_by(name: row[7].to_s.split("/")[0]) if row[7]
|
||||
# p_license = License.find_by(name: row[8])
|
||||
#
|
||||
# mirror_params = {
|
||||
# user_id: user.id,
|
||||
# name: row[5],
|
||||
# description: row[9],
|
||||
# repository_name: row[4],
|
||||
# project_category_id: p_category.id,
|
||||
# project_language_id: p_language&.id,
|
||||
# clone_addr: row[10]
|
||||
# }
|
||||
# Projects::MigrateService.call(user, mirror_params)
|
||||
# end
|
||||
# puts "sync outer repository to gitlink Success repo: #{row[5]} username: #{row[0]}"
|
||||
# rescue Exception => e
|
||||
# puts "sync outer repository to gitlink Error repo: #{row[5]} username: #{row[0]}, error:#{e}"
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
Binary file not shown.
Loading…
Reference in New Issue