diff --git a/Gemfile b/Gemfile index 660a7ff49..5a26ed6e0 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ unless RUBY_PLATFORM =~ /w32/ gem 'iconv' end +gem 'gitlab' gem 'rest-client' gem "mysql2", "= 0.3.18" gem 'redis-rails' diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 607c9b5db..e80fc4a9a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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? diff --git a/app/views/projects/_development_group.html.erb b/app/views/projects/_development_group.html.erb index d4bc7012a..20a9976e5 100644 --- a/app/views/projects/_development_group.html.erb +++ b/app/views/projects/_development_group.html.erb @@ -41,7 +41,7 @@ <%# --版本库被设置成私有、module中设置不显示、没有创建版本库 三种情况不显示-- %> <% if visible_repository?(@project) %> <% end %> diff --git a/config/initializers/gitlab_config.rb b/config/initializers/gitlab_config.rb new file mode 100644 index 000000000..ddd1efec8 --- /dev/null +++ b/config/initializers/gitlab_config.rb @@ -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 diff --git a/lib/tasks/gitlab.rake b/lib/tasks/gitlab.rake new file mode 100644 index 000000000..b0b64ff48 --- /dev/null +++ b/lib/tasks/gitlab.rake @@ -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