make it possible to configure the content type of a github webhook

This commit is contained in:
Ben Mather 2014-09-29 14:35:04 +01:00 committed by Matt Clay
parent 06559cad3c
commit eebde78ded

View file

@ -57,6 +57,12 @@ options:
required: false required: false
default: 'yes' default: 'yes'
choices: ['yes', 'no'] choices: ['yes', 'no']
content_type:
description:
- Content type to use for requests made to the webhook
required: false
default: 'json'
choices: ['json', 'form']
author: Phillip Gentry, CX Inc author: Phillip Gentry, CX Inc
''' '''
@ -105,14 +111,14 @@ def cleanall(module, hookurl, oauthkey, repo, user):
return 0, current_hooks return 0, current_hooks
def create(module, hookurl, oauthkey, repo, user): def create(module, hookurl, oauthkey, repo, user, content_type):
url = "%s/hooks" % repo url = "%s/hooks" % repo
values = { values = {
"active": True, "active": True,
"name": "web", "name": "web",
"config": { "config": {
"url": "%s" % hookurl, "url": "%s" % hookurl,
"content_type": "json" "content_type": "%s" % content_type
} }
} }
data = json.dumps(values) data = json.dumps(values)
@ -144,6 +150,7 @@ def main():
repo=dict(required=True), repo=dict(required=True),
user=dict(required=True), user=dict(required=True),
validate_certs=dict(default='yes', type='bool'), validate_certs=dict(default='yes', type='bool'),
content_type=dict(default='json', choices=['json', 'form']),
) )
) )
@ -152,6 +159,7 @@ def main():
oauthkey = module.params['oauthkey'] oauthkey = module.params['oauthkey']
repo = module.params['repo'] repo = module.params['repo']
user = module.params['user'] user = module.params['user']
content_type = module.params['content_type']
if action == "list": if action == "list":
(rc, out) = list_(module, hookurl, oauthkey, repo, user) (rc, out) = list_(module, hookurl, oauthkey, repo, user)
@ -163,7 +171,7 @@ def main():
(rc, out) = cleanall(module, hookurl, oauthkey, repo, user) (rc, out) = cleanall(module, hookurl, oauthkey, repo, user)
if action == "create": if action == "create":
(rc, out) = create(module, hookurl, oauthkey, repo, user) (rc, out) = create(module, hookurl, oauthkey, repo, user, content_type)
if rc != 0: if rc != 0:
module.fail_json(msg="failed", result=out) module.fail_json(msg="failed", result=out)