Skip to content

Commit

Permalink
Updated web_hook_controller.rb to include gitlab@ urls
Browse files Browse the repository at this point in the history
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 25, 2018
1 parent 81b6da2 commit 9c4829e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
@@ -1,5 +1,5 @@
########################################################################## ##########################################################################
# Copyright 2017 ThoughtWorks, Inc. # Copyright 2018 ThoughtWorks, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,15 @@ class GitLabController < WebHookController


protected 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 def repo_branch
payload['ref'].gsub('refs/heads/', '') payload['ref'].gsub('refs/heads/', '')
end end
Expand Down
@@ -1,5 +1,5 @@
########################################################################## ##########################################################################
# Copyright 2017 ThoughtWorks, Inc. # Copyright 2018 ThoughtWorks, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,18 @@ module Api
module WebHooks module WebHooks
class WebHookController < ::Api::ApiController class WebHookController < ::Api::ApiController
def notify 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}/ https://#{repo_host_name}/#{repo_full_name}/
https://#{repo_host_name}/#{repo_full_name}.git https://#{repo_host_name}/#{repo_full_name}.git
Expand All @@ -36,17 +47,8 @@ def notify
git@#{repo_host_name}:#{repo_full_name}.git git@#{repo_host_name}:#{repo_full_name}.git
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 end


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

end end
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"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -73,7 +73,11 @@
git@gitlab.example.com:org/repo git@gitlab.example.com:org/repo
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/) 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) expect(@material_update_service)
.to receive(:updateGitMaterial) .to receive(:updateGitMaterial)
Expand Down

0 comments on commit 9c4829e

Please sign in to comment.