gitlab_hook: renaming module name (#51979)

* gitlab_hook: renaming module name

* gitlab_hook: rename module in documentation

* gitlab_hook: remove plural in docs and code

* gitlab_hook: fix unit test functions
This commit is contained in:
Guillaume Martinez 2019-02-11 00:30:36 +01:00 committed by Dag Wieers
commit 7b84c0ee80
3 changed files with 12 additions and 11 deletions

View file

@ -0,0 +1 @@
gitlab_hook.py

View file

@ -16,10 +16,10 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: gitlab_hooks module: gitlab_hook
short_description: Manages GitLab project hooks. short_description: Manages GitLab project hooks.
description: description:
- Adds, updates and removes project hooks - Adds, updates and removes project hook
version_added: "2.6" version_added: "2.6"
author: author:
- Marcus Watkins (@marwatk) - Marcus Watkins (@marwatk)
@ -111,7 +111,7 @@ options:
EXAMPLES = ''' EXAMPLES = '''
- name: "Adding a project hook" - name: "Adding a project hook"
gitlab_hooks: gitlab_hook:
api_url: https://gitlab.example.com/ api_url: https://gitlab.example.com/
api_token: "{{ access_token }}" api_token: "{{ access_token }}"
project: "my_group/my_project" project: "my_group/my_project"
@ -123,7 +123,7 @@ EXAMPLES = '''
token: "my-super-secret-token-that-my-ci-server-will-check" token: "my-super-secret-token-that-my-ci-server-will-check"
- name: "Delete the previous hook" - name: "Delete the previous hook"
gitlab_hooks: gitlab_hook:
api_url: https://gitlab.example.com/ api_url: https://gitlab.example.com/
api_token: "{{ access_token }}" api_token: "{{ access_token }}"
project: "my_group/my_project" project: "my_group/my_project"
@ -131,7 +131,7 @@ EXAMPLES = '''
state: absent state: absent
- name: "Delete a hook by numeric project id" - name: "Delete a hook by numeric project id"
gitlab_hooks: gitlab_hook:
api_url: https://gitlab.example.com/ api_url: https://gitlab.example.com/
api_token: "{{ access_token }}" api_token: "{{ access_token }}"
project: 10 project: 10
@ -279,7 +279,7 @@ class GitLabHook(object):
@param project Project object @param project Project object
@param hook_url Url to call on event @param hook_url Url to call on event
''' '''
def existsHooks(self, project, hook_url): def existsHook(self, project, hook_url):
# When project exists, object will be stored in self.projectObject. # When project exists, object will be stored in self.projectObject.
hook = self.findHook(project, hook_url) hook = self.findHook(project, hook_url)
if hook: if hook:
@ -376,7 +376,7 @@ def main():
if project is None: if project is None:
module.fail_json(msg="Failed to create hook: project %s doesn't exists" % project_identifier) module.fail_json(msg="Failed to create hook: project %s doesn't exists" % project_identifier)
hook_exists = gitlab_hook.existsHooks(project, hook_url) hook_exists = gitlab_hook.existsHook(project, hook_url)
if state == 'absent': if state == 'absent':
if hook_exists: if hook_exists:

View file

@ -5,7 +5,7 @@
from __future__ import absolute_import from __future__ import absolute_import
from ansible.modules.source_control.gitlab_hooks import GitLabHook from ansible.modules.source_control.gitlab_hook import GitLabHook
from .gitlab import (GitlabModuleTestCase, from .gitlab import (GitlabModuleTestCase,
python_version_match_requirement, python_version_match_requirement,
@ -31,11 +31,11 @@ class TestGitlabHook(GitlabModuleTestCase):
def test_hook_exist(self): def test_hook_exist(self):
project = self.gitlab_instance.projects.get(1) project = self.gitlab_instance.projects.get(1)
rvalue = self.moduleUtil.existsHooks(project, "http://example.com/hook") rvalue = self.moduleUtil.existsHook(project, "http://example.com/hook")
self.assertEqual(rvalue, True) self.assertEqual(rvalue, True)
rvalue = self.moduleUtil.existsHooks(project, "http://gitlab.com/hook") rvalue = self.moduleUtil.existsHook(project, "http://gitlab.com/hook")
self.assertEqual(rvalue, False) self.assertEqual(rvalue, False)
@ -72,7 +72,7 @@ class TestGitlabHook(GitlabModuleTestCase):
def test_delete_hook(self): def test_delete_hook(self):
project = self.gitlab_instance.projects.get(1) project = self.gitlab_instance.projects.get(1)
self.moduleUtil.existsHooks(project, "http://example.com/hook") self.moduleUtil.existsHook(project, "http://example.com/hook")
rvalue = self.moduleUtil.deleteHook() rvalue = self.moduleUtil.deleteHook()