Skip to content

Commit

Permalink
EN-4286: Jira add comment lego (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar-salvi-unskript authored Mar 22, 2023
1 parent 2bff5f4 commit 2b5f959
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Jira/legos/jira_add_comment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[<img align="left" src="https://unskript.com/assets/favicon.png" width="100" height="100" style="padding-right: 5px">](https://unskript.com/assets/favicon.png)
<h2>Get Jira Add Comment</h2>

<br>

## Description
This Lego adds a comment to a Jira Issue.


## Lego Details

jira_add_comment(handle: JIRA, issue_id: str, comment: str, visibility: Dict[str, str] = None)

handle: Object of type unSkript jira Connector
issue_id: Issue ID.
comment: Comment to add in Jira Issue.
visibility: a dict containing two entries: "type" and "value".
"type" is 'role' (or 'group' if the Jira server has configured comment visibility for groups)
"value" is the name of the role (or group) to which viewing of this comment will be restricted.
is_internal: True marks the comment as 'Internal' in Jira Service Desk (Default: ``False``)

## Lego Input
This Lego take 4 input handle, issue_id, comment, visibility.

## Lego Output
Here is a sample output.
<img src="./1.png">

## See it in Action

You can see this Lego in action following this link [unSkript Live](https://us.app.unskript.io)
Empty file.
11 changes: 11 additions & 0 deletions Jira/legos/jira_add_comment/jira_add_comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"action_title": "Jira Add Comment",
"action_description": "Add a Jira Comment",
"action_type": "LEGO_TYPE_JIRA",
"action_entry_function": "jira_add_comment",
"action_needs_credential": true,
"action_output_type": "ACTION_OUTPUT_TYPE_INT",
"action_supports_poll": true,
"action_supports_iteration": true
}

72 changes: 72 additions & 0 deletions Jira/legos/jira_add_comment/jira_add_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
##
# Copyright (c) 2021 unSkript, Inc
# All rights reserved.
##

from jira.client import JIRA
from pydantic import BaseModel, Field
from typing import Dict, Optional
import pprint


class InputSchema(BaseModel):
issue_id: str = Field(
title='JIRA Issue ID',
description='Issue ID. Eg EN-1234'
)
comment: str = Field(
title='Comment',
description='Comment to add in Jira Issue'
)
visibility: Optional[Dict[str, str]] = Field(
None,
title='Visibility',
description='''a dict containing two entries: "type" and "value".
"type" is 'role' (or 'group' if the Jira server has configured comment visibility for groups)
"value" is the name of the role (or group) to which viewing of this comment will be restricted.'''
)
is_internal: Optional[bool] = Field(
False,
title='Internal',
description='True marks the comment as \'Internal\' in Jira Service Desk (Default: ``False``)'
)


def jira_add_comment_printer(output):
if output is None:
return
pprint.pprint(output)


def jira_add_comment(hdl: JIRA,
issue_id: str,
comment: str,
visibility: Dict[str, str] = None,
is_internal: bool = False) -> int:
"""jira_get_issue Get Jira Issue Info
:type hdl: JIRA
:param hdl: Jira handle.
:type issue_id: str
:param issue_id: Issue ID.
:type comment: str
:param comment: Comment to add in Jira Issue.
:type visibility: Dict[str, str]
:param visibility: a dict containing two entries: "type" and "value".
"type" is 'role' (or 'group' if the Jira server has configured comment visibility for groups)
"value" is the name of the role (or group) to which viewing of this comment will be restricted.
:type is_internal: bool
:param is_internal: True marks the comment as \'Internal\' in Jira Service Desk (Default: ``False``)
:rtype: Jira comment id (int)
"""
try:
issue = hdl.issue(issue_id)
comment = hdl.add_comment(issue, comment, visibility=visibility, is_internal=is_internal)
except Exception as e:
raise e
return int(comment.id)

0 comments on commit 2b5f959

Please sign in to comment.