mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-24 06:07:19 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -143,6 +143,7 @@ import traceback
|
|||
GITHUB_IMP_ERR = None
|
||||
try:
|
||||
import github
|
||||
|
||||
HAS_GITHUB = True
|
||||
except ImportError:
|
||||
GITHUB_IMP_ERR = traceback.format_exc()
|
||||
|
|
@ -155,7 +156,7 @@ def _create_hook_config(module):
|
|||
hook_config = {
|
||||
"url": module.params["url"],
|
||||
"content_type": module.params["content_type"],
|
||||
"insecure_ssl": "1" if module.params["insecure_ssl"] else "0"
|
||||
"insecure_ssl": "1" if module.params["insecure_ssl"] else "0",
|
||||
}
|
||||
|
||||
secret = module.params.get("secret")
|
||||
|
|
@ -169,10 +170,8 @@ def create_hook(repo, module):
|
|||
config = _create_hook_config(module)
|
||||
try:
|
||||
hook = repo.create_hook(
|
||||
name="web",
|
||||
config=config,
|
||||
events=module.params["events"],
|
||||
active=module.params["active"])
|
||||
name="web", config=config, events=module.params["events"], active=module.params["active"]
|
||||
)
|
||||
except github.GithubException as err:
|
||||
module.fail_json(msg=f"Unable to create hook for repository {repo.full_name}: {err}")
|
||||
|
||||
|
|
@ -184,11 +183,7 @@ def update_hook(repo, hook, module):
|
|||
config = _create_hook_config(module)
|
||||
try:
|
||||
hook.update()
|
||||
hook.edit(
|
||||
name="web",
|
||||
config=config,
|
||||
events=module.params["events"],
|
||||
active=module.params["active"])
|
||||
hook.edit(name="web", config=config, events=module.params["events"], active=module.params["active"])
|
||||
|
||||
changed = hook.update()
|
||||
except github.GithubException as err:
|
||||
|
|
@ -201,32 +196,36 @@ def update_hook(repo, hook, module):
|
|||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
repository=dict(type='str', required=True, aliases=['repo']),
|
||||
url=dict(type='str', required=True),
|
||||
content_type=dict(type='str', choices=('json', 'form'), default='form'),
|
||||
secret=dict(type='str', no_log=True),
|
||||
insecure_ssl=dict(type='bool', default=False),
|
||||
events=dict(type='list', elements='str', ),
|
||||
active=dict(type='bool', default=True),
|
||||
state=dict(type='str', choices=('absent', 'present'), default='present'),
|
||||
user=dict(type='str', required=True),
|
||||
password=dict(type='str', no_log=True),
|
||||
token=dict(type='str', no_log=True),
|
||||
github_url=dict(type='str', default="https://api.github.com")),
|
||||
mutually_exclusive=(('password', 'token'),),
|
||||
repository=dict(type="str", required=True, aliases=["repo"]),
|
||||
url=dict(type="str", required=True),
|
||||
content_type=dict(type="str", choices=("json", "form"), default="form"),
|
||||
secret=dict(type="str", no_log=True),
|
||||
insecure_ssl=dict(type="bool", default=False),
|
||||
events=dict(
|
||||
type="list",
|
||||
elements="str",
|
||||
),
|
||||
active=dict(type="bool", default=True),
|
||||
state=dict(type="str", choices=("absent", "present"), default="present"),
|
||||
user=dict(type="str", required=True),
|
||||
password=dict(type="str", no_log=True),
|
||||
token=dict(type="str", no_log=True),
|
||||
github_url=dict(type="str", default="https://api.github.com"),
|
||||
),
|
||||
mutually_exclusive=(("password", "token"),),
|
||||
required_one_of=(("password", "token"),),
|
||||
required_if=(("state", "present", ("events",)),),
|
||||
)
|
||||
|
||||
if not HAS_GITHUB:
|
||||
module.fail_json(msg=missing_required_lib('PyGithub'),
|
||||
exception=GITHUB_IMP_ERR)
|
||||
module.fail_json(msg=missing_required_lib("PyGithub"), exception=GITHUB_IMP_ERR)
|
||||
|
||||
try:
|
||||
github_conn = github.Github(
|
||||
module.params["user"],
|
||||
module.params.get("password") or module.params.get("token"),
|
||||
base_url=module.params["github_url"])
|
||||
base_url=module.params["github_url"],
|
||||
)
|
||||
except github.GithubException as err:
|
||||
module.fail_json(msg=f"Could not connect to GitHub at {module.params['github_url']}: {err}")
|
||||
|
||||
|
|
@ -236,11 +235,13 @@ def main():
|
|||
module.fail_json(msg=f"Could not authenticate to GitHub at {module.params['github_url']}: {err}")
|
||||
except github.UnknownObjectException as err:
|
||||
module.fail_json(
|
||||
msg=f"Could not find repository {module.params['repository']} in GitHub at {module.params['github_url']}: {err}")
|
||||
msg=f"Could not find repository {module.params['repository']} in GitHub at {module.params['github_url']}: {err}"
|
||||
)
|
||||
except Exception as err:
|
||||
module.fail_json(
|
||||
msg=f"Could not fetch repository {module.params['repository']} from GitHub at {module.params['github_url']}: {err}",
|
||||
exception=traceback.format_exc())
|
||||
exception=traceback.format_exc(),
|
||||
)
|
||||
|
||||
hook = None
|
||||
try:
|
||||
|
|
@ -260,8 +261,7 @@ def main():
|
|||
try:
|
||||
hook.delete()
|
||||
except github.GithubException as err:
|
||||
module.fail_json(
|
||||
msg=f"Unable to delete hook from repository {repo.full_name}: {err}")
|
||||
module.fail_json(msg=f"Unable to delete hook from repository {repo.full_name}: {err}")
|
||||
else:
|
||||
changed = True
|
||||
elif hook is not None and module.params["state"] == "present":
|
||||
|
|
@ -271,5 +271,5 @@ def main():
|
|||
module.exit_json(changed=changed, **data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue