Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated web_hook_controller.rb to include gitlab@ urls #4211

Merged
merged 1 commit into from Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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.
Expand All @@ -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
Expand Down
@@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
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
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)
Expand Down