Skip to content
Permalink
Browse files

Updated web_hook_controller.rb to include gitlab@ urls

Many Gitlab installations use gitlab@ as a git user.  this was once a default user for gitlab installs.
Due to this the urls for ssh connections from gitlab can include this user.  Changing the user is a non trivial event.
  • Loading branch information...
DavidWylie authored and ketan committed Jan 22, 2018
1 parent 81b6da2 commit 9c4829e87ec47fd835579d0dc2779233c7b00330
@@ -1,5 +1,5 @@
##########################################################################
# Copyright 2017 ThoughtWorks, Inc.
# Copyright 2018 ThoughtWorks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -23,6 +23,15 @@ class GitLabController < WebHookController

protected

def possible_urls
super + %W(
gitlab@#{repo_host_name}:#{repo_full_name}
gitlab@#{repo_host_name}:#{repo_full_name}/
gitlab@#{repo_host_name}:#{repo_full_name}.git
gitlab@#{repo_host_name}:#{repo_full_name}.git/
)
end

def repo_branch
payload['ref'].gsub('refs/heads/', '')
end
@@ -1,5 +1,5 @@
##########################################################################
# Copyright 2017 ThoughtWorks, Inc.
# Copyright 2018 ThoughtWorks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -18,7 +18,18 @@ module Api
module WebHooks
class WebHookController < ::Api::ApiController
def notify
possible_urls = %W(
Rails.logger.info("[WebHook] Noticed a git push to #{repo_host_name}/#{repo_full_name} on branch #{repo_branch}")

if material_update_service.updateGitMaterial(repo_branch, possible_urls)
render text: 'OK!', content_type: 'text/plain', status: :accepted, layout: nil
else
render text: 'No matching materials!', content_type: 'text/plain', status: :accepted, layout: nil
end
end

protected
def possible_urls
%W(
https://#{repo_host_name}/#{repo_full_name}
https://#{repo_host_name}/#{repo_full_name}/
https://#{repo_host_name}/#{repo_full_name}.git
@@ -36,17 +47,8 @@ def notify
git@#{repo_host_name}:#{repo_full_name}.git
git@#{repo_host_name}:#{repo_full_name}.git/
)

Rails.logger.info("[WebHook] Noticed a git push to #{repo_host_name}/#{repo_full_name} on branch #{repo_branch}")

if material_update_service.updateGitMaterial(repo_branch, possible_urls)
render text: 'OK!', content_type: 'text/plain', status: :accepted, layout: nil
else
render text: 'No matching materials!', content_type: 'text/plain', status: :accepted, layout: nil
end
end

protected
def repo_branch
raise 'Subclass responsibility!'
end
@@ -62,6 +64,7 @@ def repo_full_name
def webhook_secret
server_config_service.getWebhookSecret
end

end
end
end
@@ -1,5 +1,5 @@
##########################################################################
# Copyright 2017 ThoughtWorks, Inc.
# Copyright 2018 ThoughtWorks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -73,7 +73,11 @@
git@gitlab.example.com:org/repo
git@gitlab.example.com:org/repo/
git@gitlab.example.com:org/repo.git
git@gitlab.example.com:org/repo.git/)
git@gitlab.example.com:org/repo.git/
gitlab@gitlab.example.com:org/repo
gitlab@gitlab.example.com:org/repo/
gitlab@gitlab.example.com:org/repo.git
gitlab@gitlab.example.com:org/repo.git/)

expect(@material_update_service)
.to receive(:updateGitMaterial)

0 comments on commit 9c4829e

Please sign in to comment.
You can’t perform that action at this time.