mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #6210/be7f11bf backport][stable-6] Add worklog functionality to jira module (#6248)
Add worklog functionality to jira module (#6210)
community.general#6209 Add worklog functionality to jira
(cherry picked from commit be7f11bf39
)
Co-authored-by: Hugo Prudente <hugo.kenshin@gmail.com>
This commit is contained in:
parent
f6aad230c2
commit
1260a63241
3 changed files with 82 additions and 3 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- jira - add worklog functionality (https://github.com/ansible-collections/community.general/issues/6209, https://github.com/ansible-collections/community.general/pull/6210).
|
|
@ -6,6 +6,7 @@
|
|||
#
|
||||
# Copyright (c) 2020, Per Abildgaard Toft <per@minfejl.dk> Search and update function
|
||||
# Copyright (c) 2021, Brandon McNama <brandonmcnama@outlook.com> Issue attachment functionality
|
||||
# Copyright (c) 2022, Hugo Prudente <hugo.kenshin+oss@gmail.com> Worklog functionality
|
||||
#
|
||||
# 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
|
||||
|
@ -40,9 +41,10 @@ options:
|
|||
type: str
|
||||
required: true
|
||||
aliases: [ command ]
|
||||
choices: [ attach, comment, create, edit, fetch, link, search, transition, update ]
|
||||
choices: [ attach, comment, create, edit, fetch, link, search, transition, update, worklog ]
|
||||
description:
|
||||
- The operation to perform.
|
||||
- C(worklog) was added in community.genereal 6.5.0.
|
||||
|
||||
username:
|
||||
type: str
|
||||
|
@ -171,7 +173,6 @@ options:
|
|||
- When passed to comment, the data structure is merged at the first level since community.general 4.6.0. Useful to add JIRA properties for example.
|
||||
- Note that JIRA may not allow changing field values on specific transitions or states.
|
||||
default: {}
|
||||
|
||||
jql:
|
||||
required: false
|
||||
description:
|
||||
|
@ -287,6 +288,47 @@ EXAMPLES = r"""
|
|||
value:
|
||||
internal: true
|
||||
|
||||
# Add an workog to an existing issue
|
||||
- name: Worklog on issue
|
||||
community.general.jira:
|
||||
uri: '{{ server }}'
|
||||
username: '{{ user }}'
|
||||
password: '{{ pass }}'
|
||||
issue: '{{ issue.meta.key }}'
|
||||
operation: worklog
|
||||
comment: A worklog added by Ansible
|
||||
fields:
|
||||
timeSpentSeconds: 12000
|
||||
|
||||
- name: Workflow on issue with comment restricted visibility
|
||||
community.general.jira:
|
||||
uri: '{{ server }}'
|
||||
username: '{{ user }}'
|
||||
password: '{{ pass }}'
|
||||
issue: '{{ issue.meta.key }}'
|
||||
operation: worklog
|
||||
comment: A worklog added by Ansible
|
||||
comment_visibility:
|
||||
type: role
|
||||
value: Developers
|
||||
fields:
|
||||
timeSpentSeconds: 12000
|
||||
|
||||
- name: Workflow on issue with comment property to mark it internal
|
||||
community.general.jira:
|
||||
uri: '{{ server }}'
|
||||
username: '{{ user }}'
|
||||
password: '{{ pass }}'
|
||||
issue: '{{ issue.meta.key }}'
|
||||
operation: worklog
|
||||
comment: A worklog added by Ansible
|
||||
fields:
|
||||
properties:
|
||||
- key: 'sd.public.comment'
|
||||
value:
|
||||
internal: true
|
||||
timeSpentSeconds: 12000
|
||||
|
||||
# Assign an existing issue using edit
|
||||
- name: Assign an issue using free-form fields
|
||||
community.general.jira:
|
||||
|
@ -438,7 +480,7 @@ class JIRA(StateModuleHelper):
|
|||
uri=dict(type='str', required=True),
|
||||
operation=dict(
|
||||
type='str',
|
||||
choices=['attach', 'create', 'comment', 'edit', 'update', 'fetch', 'transition', 'link', 'search'],
|
||||
choices=['attach', 'create', 'comment', 'edit', 'update', 'fetch', 'transition', 'link', 'search', 'worklog'],
|
||||
aliases=['command'], required=True
|
||||
),
|
||||
username=dict(type='str'),
|
||||
|
@ -481,6 +523,7 @@ class JIRA(StateModuleHelper):
|
|||
('operation', 'attach', ['issue', 'attachment']),
|
||||
('operation', 'create', ['project', 'issuetype', 'summary']),
|
||||
('operation', 'comment', ['issue', 'comment']),
|
||||
('operation', 'workflow', ['issue', 'comment']),
|
||||
('operation', 'fetch', ['issue']),
|
||||
('operation', 'transition', ['issue', 'status']),
|
||||
('operation', 'link', ['linktype', 'inwardissue', 'outwardissue']),
|
||||
|
@ -535,6 +578,22 @@ class JIRA(StateModuleHelper):
|
|||
url = self.vars.restbase + '/issue/' + self.vars.issue + '/comment'
|
||||
self.vars.meta = self.post(url, data)
|
||||
|
||||
@cause_changes(on_success=True)
|
||||
def operation_worklog(self):
|
||||
data = {
|
||||
'comment': self.vars.comment
|
||||
}
|
||||
# if comment_visibility is specified restrict visibility
|
||||
if self.vars.comment_visibility is not None:
|
||||
data['visibility'] = self.vars.comment_visibility
|
||||
|
||||
# Use 'fields' to merge in any additional data
|
||||
if self.vars.fields:
|
||||
data.update(self.vars.fields)
|
||||
|
||||
url = self.vars.restbase + '/issue/' + self.vars.issue + '/worklog'
|
||||
self.vars.meta = self.post(url, data)
|
||||
|
||||
@cause_changes(on_success=True)
|
||||
def operation_edit(self):
|
||||
data = {
|
||||
|
|
|
@ -67,6 +67,24 @@
|
|||
that:
|
||||
- assign is changed
|
||||
|
||||
- name: Worklog on issue
|
||||
community.general.jira:
|
||||
uri: '{{ server }}'
|
||||
username: '{{ user }}'
|
||||
password: '{{ pass }}'
|
||||
issue: '{{ issue.meta.key }}'
|
||||
operation: worklog
|
||||
comment: Worklog
|
||||
fields:
|
||||
timeSpentSeconds: 1200
|
||||
register: worklog
|
||||
- name: assert worklog -> with comment
|
||||
assert:
|
||||
that:
|
||||
- worklog is changed
|
||||
- worklog.meta.comment == 'Worklog'
|
||||
- worklog.meta.timeSpentSeconds == 1200
|
||||
|
||||
- name: transition -> Resolved with comment
|
||||
community.general.jira:
|
||||
uri: "{{ uri }}"
|
||||
|
|
Loading…
Reference in a new issue