只有在同步项目时才同步用户
This commit is contained in:
parent
be25a57eaf
commit
fa0332babd
|
@ -125,20 +125,8 @@ update
|
||||||
@repository.type = 'Repository::Gitlab'
|
@repository.type = 'Repository::Gitlab'
|
||||||
@repository.url = @repository.identifier
|
@repository.url = @repository.identifier
|
||||||
if request.post? && @repository.save
|
if request.post? && @repository.save
|
||||||
g = ::Gitlab.client
|
s = Trustie::Gitlab::Sync.new
|
||||||
gid = @project.owner.gid
|
s.create_project(@project, @repository)
|
||||||
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!
|
|
||||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||||
else
|
else
|
||||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
|
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
|
||||||
|
|
|
@ -9,8 +9,8 @@ module Trustie
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.class_eval {
|
base.class_eval {
|
||||||
before_create :add_gitlab_user
|
#before_create :add_gitlab_user
|
||||||
before_destroy :delete_gitlab_user
|
#before_destroy :delete_gitlab_user
|
||||||
before_save :change_gitlab_user
|
before_save :change_gitlab_user
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,10 +26,37 @@ module Trustie
|
||||||
user.mail_notification = "day"
|
user.mail_notification = "day"
|
||||||
end
|
end
|
||||||
user.save!
|
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
|
end
|
||||||
|
|
||||||
def sync_project(project, opt={})
|
def sync_project(project, opt={})
|
||||||
gid = project.owner.gid
|
gid = project.owner.gid
|
||||||
|
unless gid
|
||||||
|
gid = sync_user(project.owner).id
|
||||||
|
end
|
||||||
|
|
||||||
raise "unknow gid" unless gid
|
raise "unknow gid" unless gid
|
||||||
path = opt[:path]
|
path = opt[:path]
|
||||||
raise "unknow path" unless path
|
raise "unknow path" unless path
|
||||||
|
@ -61,7 +88,11 @@ module Trustie
|
||||||
|
|
||||||
project.members.each do |m|
|
project.members.each do |m|
|
||||||
begin
|
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
|
rescue => e
|
||||||
puts e
|
puts e
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue