mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 12:33:59 -07:00
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.17) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.10) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.12) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.17+py3.7) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+alpine319+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+fedora39+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.17+ubuntu2004+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run
* Adjust all __future__ imports: for i in $(grep -REl "__future__.*absolute_import" plugins/ tests/); do sed -e 's/from __future__ import .*/from __future__ import annotations/g' -i $i; done * Remove all UTF-8 encoding specifications for Python source files: for i in $(grep -REl '[-][*]- coding: utf-8 -[*]-' plugins/ tests/); do sed -e '/^# -\*- coding: utf-8 -\*-/d' -i $i; done * Remove __metaclass__ = type: for i in $(grep -REl '__metaclass__ = type' plugins/ tests/); do sed -e '/^__metaclass__ = type/d' -i $i; done
122 lines
3 KiB
Python
122 lines
3 KiB
Python
#!/usr/bin/python
|
|
|
|
# Copyright (c) 2017-18, Abhijeet Kasurde <akasurde@redhat.com>
|
|
#
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
DOCUMENTATION = r"""
|
|
module: github_issue
|
|
short_description: View GitHub issue
|
|
description:
|
|
- View GitHub issue for a given repository and organization.
|
|
extends_documentation_fragment:
|
|
- community.general.attributes
|
|
attributes:
|
|
check_mode:
|
|
support: full
|
|
diff_mode:
|
|
support: none
|
|
options:
|
|
repo:
|
|
description:
|
|
- Name of repository from which issue needs to be retrieved.
|
|
required: true
|
|
type: str
|
|
organization:
|
|
description:
|
|
- Name of the GitHub organization in which the repository is hosted.
|
|
required: true
|
|
type: str
|
|
issue:
|
|
description:
|
|
- Issue number for which information is required.
|
|
required: true
|
|
type: int
|
|
action:
|
|
description:
|
|
- Get various details about issue depending upon action specified.
|
|
default: 'get_status'
|
|
choices:
|
|
- get_status
|
|
type: str
|
|
author:
|
|
- Abhijeet Kasurde (@Akasurde)
|
|
"""
|
|
|
|
RETURN = r"""
|
|
issue_status:
|
|
description: State of the GitHub issue.
|
|
type: str
|
|
returned: success
|
|
sample: open, closed
|
|
"""
|
|
|
|
EXAMPLES = r"""
|
|
- name: Check if GitHub issue is closed or not
|
|
community.general.github_issue:
|
|
organization: ansible
|
|
repo: ansible
|
|
issue: 23642
|
|
action: get_status
|
|
register: r
|
|
|
|
- name: Take action depending upon issue status
|
|
ansible.builtin.debug:
|
|
msg: Do something when issue 23642 is open
|
|
when: r.issue_status == 'open'
|
|
"""
|
|
|
|
import json
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
from ansible.module_utils.urls import fetch_url
|
|
|
|
|
|
def main():
|
|
module = AnsibleModule(
|
|
argument_spec=dict(
|
|
organization=dict(required=True),
|
|
repo=dict(required=True),
|
|
issue=dict(type='int', required=True),
|
|
action=dict(choices=['get_status'], default='get_status'),
|
|
),
|
|
supports_check_mode=True,
|
|
)
|
|
|
|
organization = module.params['organization']
|
|
repo = module.params['repo']
|
|
issue = module.params['issue']
|
|
action = module.params['action']
|
|
|
|
result = dict()
|
|
|
|
headers = {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/vnd.github.v3+json',
|
|
}
|
|
|
|
url = "https://api.github.com/repos/%s/%s/issues/%s" % (organization, repo, issue)
|
|
|
|
response, info = fetch_url(module, url, headers=headers)
|
|
if not (200 <= info['status'] < 400):
|
|
if info['status'] == 404:
|
|
module.fail_json(msg="Failed to find issue %s" % issue)
|
|
module.fail_json(msg="Failed to send request to %s: %s" % (url, info['msg']))
|
|
|
|
gh_obj = json.loads(response.read())
|
|
|
|
if action == 'get_status' or action is None:
|
|
if module.check_mode:
|
|
result.update(changed=True)
|
|
else:
|
|
result.update(changed=True, issue_status=gh_obj['state'])
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|