Skip to content

Commit

Permalink
community.general#6209 Add worklog functionality to jira
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoprudente committed Mar 20, 2023
1 parent bf8f295 commit ed79a1c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
66 changes: 62 additions & 4 deletions plugins/modules/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
# Copyright (c) 2020, Per Abildgaard Toft <[email protected]> Search and update function
# Copyright (c) 2021, Brandon McNama <[email protected]> Issue attachment functionality
# Copyright (c) 2022, Hugo Prudente <[email protected]> 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
Expand Down Expand Up @@ -40,7 +41,7 @@
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.
Expand Down Expand Up @@ -171,7 +172,6 @@
- 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:
Expand All @@ -197,7 +197,7 @@
validate_certs:
required: false
description:
- Require valid SSL certificates (set to C(false) if you'd like to use self-signed certificates)
- Require valid SSL certificates (set to `false` if you'd like to use self-signed certificates)
default: true
type: bool
Expand Down Expand Up @@ -287,6 +287,47 @@
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:
Expand Down Expand Up @@ -438,7 +479,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'),
Expand Down Expand Up @@ -481,6 +522,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']),
Expand Down Expand Up @@ -535,6 +577,22 @@ def operation_comment(self):
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 = {
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/targets/jira/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down

0 comments on commit ed79a1c

Please sign in to comment.