Skip to content

Commit 9c4829e

Browse files
DavidWylieketan
authored andcommitted
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.
1 parent 81b6da2 commit 9c4829e

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

server/webapp/WEB-INF/rails.new/app/controllers/api/web_hooks/git_lab_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################
2-
# Copyright 2017 ThoughtWorks, Inc.
2+
# Copyright 2018 ThoughtWorks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -23,6 +23,15 @@ class GitLabController < WebHookController
2323

2424
protected
2525

26+
def possible_urls
27+
super + %W(
28+
gitlab@#{repo_host_name}:#{repo_full_name}
29+
gitlab@#{repo_host_name}:#{repo_full_name}/
30+
gitlab@#{repo_host_name}:#{repo_full_name}.git
31+
gitlab@#{repo_host_name}:#{repo_full_name}.git/
32+
)
33+
end
34+
2635
def repo_branch
2736
payload['ref'].gsub('refs/heads/', '')
2837
end

server/webapp/WEB-INF/rails.new/app/controllers/api/web_hooks/web_hook_controller.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################
2-
# Copyright 2017 ThoughtWorks, Inc.
2+
# Copyright 2018 ThoughtWorks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -18,7 +18,18 @@ module Api
1818
module WebHooks
1919
class WebHookController < ::Api::ApiController
2020
def notify
21-
possible_urls = %W(
21+
Rails.logger.info("[WebHook] Noticed a git push to #{repo_host_name}/#{repo_full_name} on branch #{repo_branch}")
22+
23+
if material_update_service.updateGitMaterial(repo_branch, possible_urls)
24+
render text: 'OK!', content_type: 'text/plain', status: :accepted, layout: nil
25+
else
26+
render text: 'No matching materials!', content_type: 'text/plain', status: :accepted, layout: nil
27+
end
28+
end
29+
30+
protected
31+
def possible_urls
32+
%W(
2233
https://#{repo_host_name}/#{repo_full_name}
2334
https://#{repo_host_name}/#{repo_full_name}/
2435
https://#{repo_host_name}/#{repo_full_name}.git
@@ -36,17 +47,8 @@ def notify
3647
git@#{repo_host_name}:#{repo_full_name}.git
3748
git@#{repo_host_name}:#{repo_full_name}.git/
3849
)
39-
40-
Rails.logger.info("[WebHook] Noticed a git push to #{repo_host_name}/#{repo_full_name} on branch #{repo_branch}")
41-
42-
if material_update_service.updateGitMaterial(repo_branch, possible_urls)
43-
render text: 'OK!', content_type: 'text/plain', status: :accepted, layout: nil
44-
else
45-
render text: 'No matching materials!', content_type: 'text/plain', status: :accepted, layout: nil
46-
end
4750
end
4851

49-
protected
5052
def repo_branch
5153
raise 'Subclass responsibility!'
5254
end
@@ -62,6 +64,7 @@ def repo_full_name
6264
def webhook_secret
6365
server_config_service.getWebhookSecret
6466
end
67+
6568
end
6669
end
6770
end

server/webapp/WEB-INF/rails.new/spec/controllers/api/web_hooks/git_lab_controller_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##########################################################################
2-
# Copyright 2017 ThoughtWorks, Inc.
2+
# Copyright 2018 ThoughtWorks, Inc.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -73,7 +73,11 @@
7373
git@gitlab.example.com:org/repo
7474
git@gitlab.example.com:org/repo/
7575
git@gitlab.example.com:org/repo.git
76-
git@gitlab.example.com:org/repo.git/)
76+
git@gitlab.example.com:org/repo.git/
77+
gitlab@gitlab.example.com:org/repo
78+
gitlab@gitlab.example.com:org/repo/
79+
gitlab@gitlab.example.com:org/repo.git
80+
gitlab@gitlab.example.com:org/repo.git/)
7781

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

0 commit comments

Comments
 (0)