summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2017-05-04 16:46:32 +0530
committerJohn R Barker <john@johnrbarker.com>2017-05-04 12:16:32 +0100
commit86966c75fa3d291c2875ff0aa3352b456dd07b8e (patch)
treed097047cfe18e7897e8d1317ca79a9454b0bec35
parent08a3ea22210f17731ea94c077625cc9bb85dd45b (diff)
downloadansible-86966c75fa3d291c2875ff0aa3352b456dd07b8e.tar.gz
New module : github_issue (#23654)
Using github_issue module, user can retrive status of issue listed on Github repository and depending upon status takes various actions e.g., workarounds and downloading patches. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
-rw-r--r--lib/ansible/modules/source_control/github_issue.py129
1 files changed, 129 insertions, 0 deletions
diff --git a/lib/ansible/modules/source_control/github_issue.py b/lib/ansible/modules/source_control/github_issue.py
new file mode 100644
index 0000000000..73fb8e2156
--- /dev/null
+++ b/lib/ansible/modules/source_control/github_issue.py
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+# (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
+#
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+ANSIBLE_METADATA = {'metadata_version': '1.0',
+ 'status': ['preview'],
+ 'supported_by': 'community'}
+
+
+DOCUMENTATION = '''
+module: github_issue
+short_description: View GitHub issue.
+description:
+ - View GitHub issue for a given repository.
+version_added: "2.4"
+options:
+ repo:
+ description:
+ - Name of repository from which issue needs to be retrieved.
+ required: true
+ default: none
+ organization:
+ description:
+ - Name of the GitHub organization in which the repository is hosted.
+ required: true
+ default: none
+ issue:
+ description:
+ - Issue number for which information is required.
+ default: none
+ required: true
+ action:
+ description:
+ - Get various details about issue depending upon action specified.
+ default: 'get_status'
+ required: false
+ choices:
+ - ['get_status']
+
+author:
+ - Abhijeet Kasurde (@akasurde)
+requirements:
+ - "github3.py >= 1.0.0a4"
+'''
+
+RETURN = '''
+get_status:
+ description: State of the GitHub issue
+ type: string
+ returned: success
+ sample: open, closed
+'''
+
+EXAMPLES = '''
+- name: Check if GitHub issue is closed or not
+ github_issue:
+ organization: ansible
+ repo: ansible
+ issue: 23642
+ action: get_status
+ register: r
+
+- name: Take action depending upon issue status
+ debug:
+ msg: Do something when issue 23642 is open
+ when: r.issue_status == 'open'
+'''
+
+
+try:
+ import github3
+ HAS_GITHUB_PACKAGE = True
+except ImportError:
+ HAS_GITHUB_PACKAGE = False
+from ansible.module_utils.basic import AnsibleModule
+
+
+def main():
+ module = AnsibleModule(
+ argument_spec=dict(
+ organization=dict(required=True),
+ repo=dict(required=True),
+ issue=dict(required=True),
+ action=dict(required=False, choices=['get_status']),
+ ),
+ supports_check_mode=True,
+ )
+
+ if not HAS_GITHUB_PACKAGE:
+ module.fail_json(msg="Missing required github3 module. (check docs or "
+ "install with: pip install github3.py==1.0.0a4)")
+
+ organization = module.params['organization']
+ repo = module.params['repo']
+ issue = module.params['issue']
+ action = module.params['action']
+
+ result = dict()
+
+ gh_obj = github3.issue(organization, repo, issue)
+ if isinstance(gh_obj, github3.null.NullObject):
+ module.fail_json(msg="Failed to get details about issue specified. "
+ "Please check organization, repo and issue "
+ "details and try again.")
+
+ 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()