From dae6e68623c5b56afcf1d607b9a0acca189816d2 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 18 Dec 2015 20:46:17 +0800 Subject: [PATCH] renwu --- db/schema.rb | 3 +- lib/tasks/update_project_commits.rake | 44 ++++++++++++++++----------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index eac8a81db..8e946c493 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151218022014) do +ActiveRecord::Schema.define(:version => 20151218110033) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1361,6 +1361,7 @@ ActiveRecord::Schema.define(:version => 20151218022014) do t.integer "gpid" t.integer "forked_from_project_id" t.integer "forked_count" + t.integer "commits_count", :default => 0 end add_index "projects", ["lft"], :name => "index_projects_on_lft" diff --git a/lib/tasks/update_project_commits.rake b/lib/tasks/update_project_commits.rake index 104406485..d8a916819 100644 --- a/lib/tasks/update_project_commits.rake +++ b/lib/tasks/update_project_commits.rake @@ -1,18 +1,26 @@ -# #coding=utf-8 -# -# namespace :projects do -# desc "sync some projects which just have sigle repository" -# task :commits_count => :environment do -# projects = Project.where("gpid is not null") -# puts projects.count -# projects.each do |project| -# unless project.gpid.nil? -# count = -# end -# -# end -# end -# -# task :delete_rep => :environment do -# end -# end \ No newline at end of file +#coding=utf-8 + +namespace :projects do + desc "sync some projects which just have sigle repository" + task :commits_count => :environment do + projects = Project.where("gpid is not null") + puts projects.count + projects.each do |project| + unless project.gpid.nil? + begin + url = "https://gittest.trustie.net/api/v3/projects/#{project.gpid}/repository/commits_total_count?private_token=kZUYYbAY12QSQ2Tx1zes&ref_name=master" + require 'net/http' + count = Net::HTTP.get(URI(url)) + puts "count is ===>#{count}" + ensure + puts "**************** #{project.id}" + end + project.update_attributes(:commits_count => count) + end + + end + end + + task :delete_rep => :environment do + end +end \ No newline at end of file