From fa0332babd387650b5885a094fef8a8bef8e5962 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Sun, 1 Nov 2015 22:25:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AA=E6=9C=89=E5=9C=A8=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=97=B6=E6=89=8D=E5=90=8C=E6=AD=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 16 ++--------- lib/trustie/gitlab/manage_user.rb | 4 +-- lib/trustie/gitlab/sync.rb | 33 +++++++++++++++++++++- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 4cec85833..8a1b3bbe0 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -125,20 +125,8 @@ update @repository.type = 'Repository::Gitlab' @repository.url = @repository.identifier if request.post? && @repository.save - g = ::Gitlab.client - gid = @project.owner.gid - gproject = g.create_project(@repository.identifier, - path: @repository.identifier, - description: @project.description, - wiki_enabled: false, - wall_enabled: false, - issues_enabled: false, - snippets_enabled: false, - public: false, - user_id: gid - ) - @project.gpid = gproject.id - @project.save! + s = Trustie::Gitlab::Sync.new + s.create_project(@project, @repository) redirect_to settings_project_url(@project, :tab => 'repositories') else redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages) diff --git a/lib/trustie/gitlab/manage_user.rb b/lib/trustie/gitlab/manage_user.rb index 15bd7ef78..a87984490 100644 --- a/lib/trustie/gitlab/manage_user.rb +++ b/lib/trustie/gitlab/manage_user.rb @@ -9,8 +9,8 @@ module Trustie def self.included(base) base.class_eval { - before_create :add_gitlab_user - before_destroy :delete_gitlab_user + #before_create :add_gitlab_user + #before_destroy :delete_gitlab_user before_save :change_gitlab_user } end diff --git a/lib/trustie/gitlab/sync.rb b/lib/trustie/gitlab/sync.rb index ae1cded6c..3a8e8380c 100644 --- a/lib/trustie/gitlab/sync.rb +++ b/lib/trustie/gitlab/sync.rb @@ -26,10 +26,37 @@ module Trustie user.mail_notification = "day" end user.save! + u + end + + + def create_project(project, repository) + gid = project.owner.gid + unless gid + gid = sync_user(project.owner).id + end + raise "unknow gid" unless gid + + gproject = g.create_project(repository.identifier, + path: repository.identifier, + description: project.description, + wiki_enabled: false, + wall_enabled: false, + issues_enabled: false, + snippets_enabled: false, + public: false, + user_id: gid + ) + project.gpid = gproject.id + project.save! end def sync_project(project, opt={}) gid = project.owner.gid + unless gid + gid = sync_user(project.owner).id + end + raise "unknow gid" unless gid path = opt[:path] raise "unknow path" unless path @@ -61,7 +88,11 @@ module Trustie project.members.each do |m| begin - self.g.add_team_member(gproject.id, m.user.gid, UserLevel::DEVELOPER) + gid = m.user.gid + unless gid + gid = sync_user(m.user).id + end + self.g.add_team_member(gproject.id, gid, UserLevel::DEVELOPER) rescue => e puts e end