Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Jira v2] Added 3 new commands #27431

Merged
merged 49 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7fb8411
master
ennozdd May 25, 2023
e0ec928
Merge branch 'master' of https://github.com/demisto/content
ennozdd Jun 2, 2023
44a5c55
Merge branch 'master' of https://github.com/demisto/content
ennozdd Jun 14, 2023
9375a5d
jira command
ennozdd Jun 14, 2023
e64746f
reverting headers
ennozdd Jun 14, 2023
bb4a965
reverting union option
ennozdd Jun 14, 2023
920c1ca
reverted the latest message
ennozdd Jun 14, 2023
a3462c1
reverting debug message
ennozdd Jun 14, 2023
691a849
get_organization_name
ennozdd Jun 14, 2023
604c0c1
reverting update_issue_assignee_command
ennozdd Jun 14, 2023
e0fc6ff
moving up the update_issue_assignee_command
ennozdd Jun 14, 2023
ffa4417
git user
ennozdd Jun 14, 2023
7b07a69
issue assign
ennozdd Jun 14, 2023
d73f859
command
ennozdd Jun 14, 2023
72affd3
customfields removed
ennozdd Jun 14, 2023
e7466a7
jirav2copy
ennozdd Jun 14, 2023
4275fcc
rmed jirav2copy
ennozdd Jun 14, 2023
693670b
jira
ennozdd Jun 14, 2023
6c870d4
format
ennozdd Jun 14, 2023
c32f09d
jirav2
ennozdd Jun 14, 2023
d441e3a
reverted defaultmapperin
ennozdd Jun 14, 2023
483dfb2
reverted hidden marketplace
ennozdd Jun 14, 2023
2a1dcd1
jira
ennozdd Jun 14, 2023
ef1bfc6
moved down edit-issue
ennozdd Jun 14, 2023
3ce1fa4
wrong command
ennozdd Jun 14, 2023
3bf3b7f
jira
ennozdd Jun 14, 2023
e8331b7
replaced a line
ennozdd Jun 14, 2023
24243fc
Readme
ennozdd Jun 14, 2023
062bee3
watchers
ennozdd Jun 14, 2023
51e73ef
added release notes
ennozdd Jun 14, 2023
be68adc
revert CrowdStrike
ennozdd Jun 14, 2023
52c53b4
typo
ennozdd Jun 14, 2023
baa3a4f
test get_organizations
ennozdd Jun 14, 2023
694eee4
added a unit test
ennozdd Jun 14, 2023
a76b417
mocker error
ennozdd Jun 14, 2023
65db0bb
fixing unit test
ennozdd Jun 14, 2023
880d403
rmed 1_*
ennozdd Jun 14, 2023
05465ab
unit testing for organizations
ennozdd Jun 14, 2023
5f7def8
removed .gitignore
ennozdd Jun 14, 2023
5915435
Merge branch 'master' of https://github.com/demisto/content into jiraa
ennozdd Jun 15, 2023
4407e02
taking care of comments
ennozdd Jun 15, 2023
3773746
Merge branch 'master' of https://github.com/demisto/content into jiraa
ennozdd Jun 15, 2023
7b88121
rmed 1_* files
ennozdd Jun 15, 2023
90c9a5c
new commands into README
ennozdd Jun 15, 2023
2d2067c
Update Packs/Jira/Integrations/JiraV2/JiraV2.yml
ennozdd Jun 15, 2023
d3de9c0
Update Packs/Jira/Integrations/JiraV2/README.md
ennozdd Jun 15, 2023
3704504
Update Packs/Jira/ReleaseNotes/3_0_3.md
ennozdd Jun 15, 2023
6a98aa6
Update Packs/Jira/ReleaseNotes/3_0_3.md
ennozdd Jun 15, 2023
55d9629
Update Packs/Jira/ReleaseNotes/3_0_3.md
ennozdd Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions Packs/Jira/Integrations/JiraV2/JiraV2.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ def get_issue_fields(issue_creating=False, mirroring=False, **issue_args):
if not issue['fields'].get('issuetype') and issue_creating:
issue['fields']['issuetype'] = {}

if issue_args.get('watchers'):
watchers = issue_args.get('watchers')
if isinstance(watchers, list):
issue['watchers'] = watchers
elif isinstance(watchers, str):
issue['watchers'] = argToList(watchers)

if issue_args.get('summary'):
issue['fields']['summary'] = issue_args['summary']

Expand Down Expand Up @@ -723,6 +730,24 @@ def get_issue(issue_id, headers=None, expand_links=False, is_update=False, get_a
return human_readable, outputs, contents


def get_project_role_command(project_key, role_name):
j_res = get_project_roles(project_key)
url = j_res.get(role_name)
if not url:
return_error(f"Role '{role_name}' not found")

role_id = url.split('/')[-1]
ennozdd marked this conversation as resolved.
Show resolved Hide resolved
url = f'rest/api/latest/project/{project_key}/role/{role_id}'
j_res = jira_req('GET', url, resp_type='json')
return j_res


def get_project_roles(project_key):
url = f'rest/api/latest/project/{project_key}/role'
j_res = jira_req('GET', url, resp_type='json')
return j_res


def issue_query_command(query, start_at='', max_results=None, headers='', extra_fields=None):
nofields: set = set()

Expand Down Expand Up @@ -753,6 +778,20 @@ def create_issue_command():
return_outputs(readable_output=human_readable, outputs=outputs, raw_response=contents)


def add_user_to_project_command(user_email, project_key, role_name):
result = get_account_id_from_attribute(user_email)

if isinstance(result, CommandResults) and isinstance(result.raw_response, dict):
user_id = result.raw_response.get('AccountID')
else:
return_error(f'{result}')

role_id = get_project_role_command(project_key, role_name).get('id')
url = f'rest/projectconfig/latest/roles/{project_key}/{role_id}'
json_data = {'users': [user_id], "groups": []}
return jira_req('POST', url, json.dumps(json_data)).text


def edit_issue_command(issue_id, mirroring=False, headers=None, status=None, transition=None, **kwargs):
issue = get_issue_fields(mirroring=mirroring, **kwargs)
if status and transition:
Expand Down Expand Up @@ -796,6 +835,13 @@ def _update_fields(issue_id, new_data):
jira_req('PUT', url, json.dumps({'fields': new_data}))


def get_organizations_command():
url = '/rest/servicedeskapi/organization'
res = jira_req('GET', url, resp_type='json').get('values')
[org.pop('_links') for org in res]
return CommandResults(outputs=res, outputs_prefix='Jira.Organizations')


def get_field_command(issue_id, field):
fields = argToList(field)
return get_issue(issue_id, extra_fields=fields, is_update=False)
Expand Down Expand Up @@ -1459,17 +1505,24 @@ def main():
incidents = fetch_incidents(fetch_query, id_offset, fetch_attachments, fetch_comments, incoming_mirror,
outgoing_mirror, comment_tag, attachment_tag, fetch_by_created)
demisto.incidents(incidents)

elif demisto.command() == 'jira-get-issue':
human_readable, outputs, raw_response = get_issue(**snakify(demisto.args()))
return_outputs(human_readable, outputs, raw_response)

elif demisto.command() == 'jira-get-project-role':
return_results(get_project_role_command(**demisto.args()))

elif demisto.command() == 'jira-issue-query':
human_readable, outputs, raw_response = issue_query_command(**snakify(demisto.args()))
return_outputs(human_readable, outputs, raw_response)

elif demisto.command() == 'jira-create-issue':
create_issue_command()

elif demisto.command() == 'jira-add-user-to-project':
return_results(add_user_to_project_command(**demisto.args()))

elif demisto.command() == 'jira-edit-issue':
human_readable, outputs, raw_response = edit_issue_command(**snakify(demisto.args()))
return_outputs(human_readable, outputs, raw_response)
Expand Down Expand Up @@ -1513,8 +1566,12 @@ def main():
elif demisto.command() == 'jira-get-id-by-attribute':
return_results(get_account_id_from_attribute(**demisto.args()))

elif demisto.command() == 'jira-get-organizations':
return_results(get_organizations_command())

elif demisto.command() == 'jira-list-transitions':
return_results(list_transitions_command(demisto.args()))

elif demisto.command() == 'get-modified-remote-data':
return_results(get_modified_remote_data_command(demisto.args()))

Expand Down
20 changes: 19 additions & 1 deletion Packs/Jira/Integrations/JiraV2/JiraV2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ script:
- description: The component names of the issue. For example components="component1,component2".
isArray: true
name: components
- description: A comma-separated list of account IDs for watching the issue. Use the jira-get-id-by-attribute command to get the user's account ID.
isArray: true
name: watchers
description: Creates a new issue in Jira.
name: jira-create-issue
outputs:
Expand Down Expand Up @@ -538,6 +541,21 @@ script:
- description: Available from Cortex XSOAR version 6.1.0. This command queries for incidents that were modified since the last update. This method is only used for debugging.
name: get-modified-remote-data
arguments: []
- arguments: []
description: Gets the information related to the role, including assigned users.
name: jira-get-project-role
- arguments:
- description: User's email address.
name: user_email
- description: Project key.
name: project_key
- description: Role name to assign the user.
name: role_name
description: Adds the user to a project.
name: jira-add-user-to-project
- arguments: []
description: Lists all the organizations.
name: jira-get-organizations
- arguments:
- description: The ID of the issue to edit.
name: issueId
Expand Down Expand Up @@ -569,7 +587,7 @@ script:
- contextPath: Ticket.Status
description: The ticket status.
type: String
dockerimage: demisto/oauthlib:1.0.0.58909
dockerimage: demisto/oauthlib:1.0.0.62974
isfetch: true
ismappable: true
isremotesyncin: true
Expand Down
38 changes: 38 additions & 0 deletions Packs/Jira/Integrations/JiraV2/JiraV2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,3 +1588,41 @@ def test_test_update_issue_assignee_command_no_assignees():

with pytest.raises(DemistoException):
update_issue_assignee_command(issue_id='19141', assignee=None, assignee_id=None)


def test_get_organizations(mocker):
from test_data.raw_response import ORGANIZATIONS
from JiraV2 import get_organizations_command
mocker.patch.object(demisto, "results")
organizations = [
{
"id": "23",
"name": "TEST"
},
{
"id": "4",
"name": "XSOAR"
}
]
mocker.patch("JiraV2.jira_req", return_value=ORGANIZATIONS)
result = get_organizations_command()
assert result.raw_response == organizations


def test_get_project_role(mocker):
from test_data.raw_response import PROJECT_ROLES, PROJECT_ROLE
from JiraV2 import get_project_role_command
mocker.patch("JiraV2.get_project_roles", return_value=PROJECT_ROLES)
mocker.patch("JiraV2.jira_req", return_value=PROJECT_ROLE)

role = get_project_role_command("demisto", "Agent")
assert role.get('id') == 11823


def test_get_project_roles(mocker):
from test_data.raw_response import PROJECT_ROLES
from JiraV2 import get_project_roles
mocker.patch("JiraV2.jira_req", return_value=PROJECT_ROLES)

roles = get_project_roles("demisto")
assert len(roles) == 2
54 changes: 54 additions & 0 deletions Packs/Jira/Integrations/JiraV2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1050,3 +1050,57 @@ Add a new custom field and add it to the incident type's layout:
6. Click on the 'V' option in the 'V/X' menu.
7. You can see the new status under 'Jira Status'.
8. Go to Jira, within approximately one minute you will be able to see the new status there as well.
### jira-add-user-to-project

***
Adds the user to a project.

#### Base Command

`jira-add-user-to-project`

#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |
| user_email | User's email address. | Optional |
| project_key | Project key. | Optional |
| role_name | Role name to assign the user. | Optional |

#### Context Output

There is no context output for this command.
### jira-get-project-role

***
Gets the information related to the role, including assigned users.

#### Base Command

`jira-get-project-role`

#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |

#### Context Output

There is no context output for this command.
### jira-get-organizations

***
Lists all the organizations.

#### Base Command

`jira-get-organizations`

#### Input

| **Argument Name** | **Description** | **Required** |
| --- | --- | --- |

#### Context Output

There is no context output for this command.
67 changes: 67 additions & 0 deletions Packs/Jira/Integrations/JiraV2/test_data/raw_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,70 @@
"content": "https://localhost/secure/attachment/18447/filename"
}
}


ORGANIZATIONS = {
"_links": {
"base": "https://demistodev.atlassian.net",
"context": "",
"self": "https://demistodev.atlassian.net/rest/servicedeskapi/organization"
},
"isLastPage": True,
"limit": 50,
"size": 2,
"start": 0,
"values": [
{
"_links": {
"self": "https://demistodev.atlassian.net/rest/servicedeskapi/organization/23"
},
"id": "23",
"name": "TEST"
},
{
"_links": {
"self": "https://demistodev.atlassian.net/rest/servicedeskapi/organization/4"
},
"id": "4",
"name": "XSOAR"
}
]
}


PROJECT_ROLES = {
"Agent":"https://demistodev.atlassian.net/rest/api/2/project/10804/role/11824",
"Administrator":"https://demistodev.atlassian.net/rest/api/2/project/10804/role/11823",
}


PROJECT_ROLE = {
"self": "https://demistodev.atlassian.net/rest/api/2/project/10804/role/11823",
"name": "Administrator",
"id": 11823,
"description": "Admins can do most things, like update settings and add other admins.",
"actors": [
{
"id": 44432,
"displayName": "XSOAR",
"type": "atlassian-user-role-actor",
"actorUser": {
"accountId": "123456789"
}
},
{
"id": 44430,
"displayName": "Demisto",
"type": "atlassian-user-role-actor",
"actorUser": {
"accountId": "987654321"
}
}
],
"scope": {
"type": "PROJECT",
"project": {
"id": "10804"
}
}
}
10 changes: 10 additions & 0 deletions Packs/Jira/ReleaseNotes/3_0_3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#### Integrations

##### Atlassian Jira v2

- Added the following new commands:
* ***jira-get-organizations***
* ***jira-add-user-to-project***
* ***jira-get-project-role***
- Updated the Docker image to: *demisto/oauthlib:1.0.0.62974*.
2 changes: 1 addition & 1 deletion Packs/Jira/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Atlassian Jira",
"description": "Use the Jira integration to manage issues and create Cortex XSOAR incidents from Jira projects.",
"support": "xsoar",
"currentVersion": "3.0.2",
"currentVersion": "3.0.3",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down