From 48547f3e113f844cf610d407cf936b089a8cdb8c Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 6 Nov 2015 17:47:56 +0800 Subject: [PATCH] =?UTF-8?q?1/=E6=B7=BB=E5=8A=A0members=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=202=E3=80=81=E8=BF=87=E6=BB=A4=E6=8E=89=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=BA=93identifier=E9=87=8D=E5=A4=8D=E5=80=BC=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=203=E3=80=81=E6=B7=BB=E5=8A=A0puts?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/gitlab_to_git.rake | 11 +++++++++++ lib/tasks/sync_sigle_rep.rake | 26 +++++++++++++++++--------- lib/trustie/gitlab/sync.rb | 20 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/lib/tasks/gitlab_to_git.rake b/lib/tasks/gitlab_to_git.rake index 8b7f7279e..c7b97e00d 100644 --- a/lib/tasks/gitlab_to_git.rake +++ b/lib/tasks/gitlab_to_git.rake @@ -8,4 +8,15 @@ namespace :rep_fault do rep.save end + desc "forge and ossean's members" + task :sync_members => :environment do + projects = [] + projects << Project.where("id =? ",2) + projects << Project.where("id =? ",299) + puts projects + s = Trustie::Gitlab::Sync.new + projects.each do |project| + s.only_members(project.first) + end + end end \ No newline at end of file diff --git a/lib/tasks/sync_sigle_rep.rake b/lib/tasks/sync_sigle_rep.rake index b99221c83..591dcce84 100644 --- a/lib/tasks/sync_sigle_rep.rake +++ b/lib/tasks/sync_sigle_rep.rake @@ -3,19 +3,27 @@ namespace :sync_rep do desc "sync some projects which just have sigle repository" task :sigle => :environment do - projects = Project.all + projects = Project.where("user_id !=?",12) projects.each do |project| # 针对类型为Git并且只有一个版本库的项目 if project.repositories && project.repositories.count == 1 && project.repositories.first.type == "Repository::Git" rep = project.repositories.first - s = Trustie::Gitlab::Sync.new - s.sync_project(project, path: rep.identifier, import_url: rep.url) - rep.type = 'Repository::Gitlab' - rep.save - puts "*************************************" - puts project.id - puts rep.id - puts rep.identifier + count = Repository.find_by_sql("SELECT * FROM `repositories` where identifier = '#{rep.identifier}'").count + puts count + unless count > 1 + rep.identifier + puts "################################" + puts project.id + puts rep.id + s = Trustie::Gitlab::Sync.new + s.sync_project(project, path: rep.identifier, import_url: rep.url) + rep.type = 'Repository::Gitlab' + rep.save + puts "*************************************" + puts project.id + puts rep.id + puts rep.identifier + end end end end diff --git a/lib/trustie/gitlab/sync.rb b/lib/trustie/gitlab/sync.rb index 8c84984ee..a303b22fb 100644 --- a/lib/trustie/gitlab/sync.rb +++ b/lib/trustie/gitlab/sync.rb @@ -69,6 +69,11 @@ module Trustie # import url http://xianbo_trustie2:1234@repository.trustie.net/xianbo/trustie2.git # can use password + puts "@@@@@@@@@@@@@@@@@@@@@@@" + puts path + puts project.description + puts gid + puts import_url gproject = self.g.create_project(path, path: path, description: project.description, @@ -81,6 +86,7 @@ module Trustie user_id: gid, import_url: import_url ) + puts "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" project.gpid = gproject.id project.save! puts "Successfully created #{project.name}" @@ -100,6 +106,20 @@ module Trustie end end + def only_members(project) + project.members.each do |m| + begin + gid = m.user.gid + unless gid + gid = sync_user(m.user).id + end + self.g.add_team_member(project.gpid, gid, UserLevel::DEVELOPER) + rescue => e + puts e + end + end + end + def remove_project end end