New module: gitlab_issue.py (#7539)

* feat(gitlab_issue): adds module for gitlab issues management

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* fix(gitlab_issue): assignee_ids and labels as lists

* docs(gitlab_issue): fix missing element types

* Apply suggestions from code review

Co-authored-by: Léo GATELLIER <26511053+lgatellier@users.noreply.github.com>

* chore(gitlab_issue): remove unnecessary parameter checks

* chore(gitlab_issue): renaming milestone_id parameter to milestone_search

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Léo GATELLIER <26511053+lgatellier@users.noreply.github.com>
This commit is contained in:
Ondrej Zvara 2023-12-02 20:55:19 +01:00 committed by GitHub
parent 58cce27d45
commit f4a87fdbcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 590 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# 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
gitlab/ci
disabled

View file

@ -0,0 +1,15 @@
---
# Copyright (c) Ansible Project
# 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
gitlab_branch: ansible_test_branch
gitlab_project_name: ansible_test_project
gitlab_project_group: ansible_test_group
gitlab_host: ansible_test_host
gitlab_api_token: ansible_test_api_token
gitlab_labels: ansible_test_label
gitlab_milestone_search: ansible_test_milestone_search
gitlab_milestone_group_id: ansible_test_milestone_group_id
gitlab_assignee_ids: ansible_test_assignee_ids
gitlab_description_path: ansible_test_description_path

View file

@ -0,0 +1,9 @@
<!--
Copyright (c) Ansible Project
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
-->
### Description
Issue test description

View file

@ -0,0 +1,150 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# 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
- name: Install required libs
pip:
name: python-gitlab
state: present
- block:
- name: Create {{ gitlab_project_name }} project
gitlab_project:
api_url: "{{ gitlab_host }}"
validate_certs: true
api_token: "{{ gitlab_api_token }}"
name: "{{ gitlab_project_name }}"
group: "{{ gitlab_project_group }}"
default_branch: "{{ gitlab_branch }}"
initialize_with_readme: true
state: present
- name: Create Issue
gitlab_issue:
api_token: "{{ gitlab_api_token }}"
api_url: "{{ gitlab_host }}"
description: "Test description"
project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
state: present
title: "Ansible test issue"
register: gitlab_issue_create
- name: Test Issue Created
assert:
that:
- gitlab_issue_create is changed
- name: Create Issue ( Idempotency test )
gitlab_issue:
api_token: "{{ gitlab_api_token }}"
api_url: "{{ gitlab_host }}"
description: "Test description"
project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
state: present
title: "Ansible test issue"
register: gitlab_issue_create_idempotence
- name: Test Create Issue is Idempotent
assert:
that:
- gitlab_issue_create_idempotence is not changed
- name: Update Issue Test ( Additions )
gitlab_issue:
api_token: "{{ gitlab_api_token }}"
api_url: "{{ gitlab_host }}"
assignee_ids: "{{ gitlab_assignee_ids }}"
description_path: "{{ gitlab_description_path }}"
labels: "{{ gitlab_labels }}"
milestone_search: "{{ gitlab_milestone_search }}"
milestone_group_id: "{{ gitlab_milestone_group_id }}"
project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
state: present
title: "Ansible test issue"
register: gitlab_issue_update_additions
- name: Test Issue Updated ( Additions )
assert:
that:
- gitlab_issue_update_additions.issue.labels[0] == "{{ gitlab_labels[0] }}"
- gitlab_issue_update_additions.issue.assignees[0].username == "{{ gitlab_assignee_ids[0] }}"
- "'### Description\n\nIssue test description' in gitlab_issue_update_additions.issue.description"
- gitlab_issue_update_additions.issue.milestone.title == "{{ gitlab_milestone_search }}"
- name: Update Issue Test ( Persistence )
gitlab_issue:
api_token: "{{ gitlab_api_token }}"
api_url: "{{ gitlab_host }}"
description_path: "{{ gitlab_description_path }}"
milestone_search: "{{ gitlab_milestone_search }}"
milestone_group_id: "{{ gitlab_milestone_group_id }}"
project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
state: present
title: "Ansible test issue"
register: gitlab_issue_update_persistence
- name: Test issue Not Updated ( Persistence )
assert:
that:
- gitlab_issue_update_persistence.issue.labels[0] == "{{ gitlab_labels[0] }}"
- gitlab_issue_update_persistence.issue.assignees[0].username == "{{ gitlab_assignee_ids[0] }}"
- name: Update Issue Test ( Removals )
gitlab_issue:
api_token: "{{ gitlab_api_token }}"
api_url: "{{ gitlab_host }}"
assignee_ids: []
description_path: "{{ gitlab_description_path }}"
labels: []
milestone_search: ""
milestone_group_id: ""
project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
state: present
title: "Ansible test issue"
register: gitlab_issue_update_removal
- name: Test issue updated
assert:
that:
- gitlab_issue_update_removal.issue.labels == []
- gitlab_issue_update_removal.issue.assignees == []
- gitlab_issue_update_removal.issue.milestone == None
- name: Delete Issue
gitlab_issue:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_api_token }}"
project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
title: "Ansible test issue"
state: absent
register: gitlab_issue_delete
- name: Test issue is deleted
assert:
that:
- gitlab_issue_delete is changed
always:
- name: Delete Issue
gitlab_issue:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_api_token }}"
project: "{{ gitlab_project_group }}/{{ gitlab_project_name }}"
title: "Ansible test issue"
state_filter: "opened"
state: absent
register: gitlab_issue_delete
- name: Clean up {{ gitlab_project_name }}
gitlab_project:
api_url: "{{ gitlab_host }}"
validate_certs: false
api_token: "{{ gitlab_api_token }}"
name: "{{ gitlab_project_name }}"
group: "{{ gitlab_project_group }}"
state: absent