同步登录

This commit is contained in:
guange 2015-06-30 22:12:34 +08:00
parent 38b97aa558
commit 797ed5081d
5 changed files with 28 additions and 1 deletions

View File

@ -6,6 +6,7 @@ unless RUBY_PLATFORM =~ /w32/
gem 'iconv'
end
gem 'gitlab'
gem 'rest-client'
gem "mysql2", "= 0.3.18"
gem 'redis-rails'

View File

@ -250,6 +250,14 @@ update
return -1
end
end
if params[:to] == 'gitlab'
g = Gitlab.client
g.post('/session', body: {email: User.current.mail, password: User.current.hashed_password})
redirect_to "http://192.168.41.130:3000/gitlab-org/gitlab-shell/tree/master"
return
end
#if( !User.current.member_of?(@project) || @project.hidden_repo)
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?

View File

@ -41,7 +41,7 @@
<%# --版本库被设置成私有、module中设置不显示、没有创建版本库 三种情况不显示-- %>
<% if visible_repository?(@project) %>
<div class="subNav">
<%= link_to l(:project_module_repository), {:controller => 'repositories', :action => 'show', :id => @project.id}, :class => "f14 c_blue02" %>
<%= link_to l(:project_module_repository), {:controller => 'repositories', :action => 'show', :id => @project.id, to: 'gitlab'}, :class => "f14 c_blue02" %>
<a class="subnav_num">(<%= @project.repositories.count %>)</a>
</div>
<% end %>

View File

@ -0,0 +1,7 @@
Gitlab.configure do |config|
config.endpoint = 'http://192.168.41.130:3000/api/v3' # API endpoint URL, default: ENV['GITLAB_API_ENDPOINT']
config.private_token = 'cK15gUDwvt8EEkzwQ_63' # user's private token, default: ENV['GITLAB_API_PRIVATE_TOKEN']
# Optional
# config.user_agent = 'Custom User Agent' # user agent, default: 'Gitlab Ruby Gem [version]'
# config.sudo = 'user' # username for sudo mode, default: nil
end

11
lib/tasks/gitlab.rake Normal file
View File

@ -0,0 +1,11 @@
namespace :gitlab do
desc "sync users to gitlab"
task :sync => :environment do
User.where(login: 'guange').find_each do |user|
g = Gitlab.client
unless g.get("/users?search=#{user.mail}")
g.create_user(user.mail, user.hashed_password, name: user.show_name, username: user.login)
end
end
end
end