Skip to content

Commit 19df894

Browse files
author
Gonchik Tsymzhitov
committed
Merge branch 'isaac-philip-issues_export_csv' into master
2 parents b396471 + a7689eb commit 19df894

File tree

4 files changed

+94
-67
lines changed

4 files changed

+94
-67
lines changed

atlassian/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0
1+
2.0.1

atlassian/jira.py

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111

1212

1313
class Jira(AtlassianRestAPI):
14-
1514
"""
1615
Provide permission information for the current user.
1716
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2
1817
"""
1918

2019
def get_permissions(
21-
self, project_id=None, project_key=None, issue_id=None, issue_key=None
20+
self, project_id=None, project_key=None, issue_id=None, issue_key=None
2221
):
2322
"""
2423
Returns all permissions in the system and whether the currently logged in user has them.
@@ -201,7 +200,7 @@ def get_attachment_expand_raw(self, attachment_id):
201200
"""
202201

203202
def get_audit_records(
204-
self, offset=None, limit=None, filter=None, from_date=None, to_date=None
203+
self, offset=None, limit=None, filter=None, from_date=None, to_date=None
205204
):
206205
"""
207206
Returns auditing records filtered using provided parameters
@@ -591,7 +590,7 @@ def remove_group(self, name, swap_group=None):
591590
return self.delete(url, params=params)
592591

593592
def get_all_users_from_group(
594-
self, group, include_inactive_users=False, start=0, limit=50
593+
self, group, include_inactive_users=False, start=0, limit=50
595594
):
596595
"""
597596
Just wrapping method user group members
@@ -648,7 +647,7 @@ def issue(self, key, fields="*all"):
648647
return self.get("rest/api/2/issue/{0}?fields={1}".format(key, fields))
649648

650649
def get_issue(
651-
self, issue_id_or_key, fields=None, properties=None, update_history=True
650+
self, issue_id_or_key, fields=None, properties=None, update_history=True
652651
):
653652
"""
654653
Returns a full representation of the issue for the given issue key
@@ -1014,7 +1013,7 @@ def get_issue_remote_links(self, issue_key, global_id=None, internal_id=None):
10141013
return self.get(url, params=params)
10151014

10161015
def create_or_update_issue_remote_links(
1017-
self, issue_key, link_url, title, global_id=None, relationship=None
1016+
self, issue_key, link_url, title, global_id=None, relationship=None
10181017
):
10191018
"""
10201019
Add Remote Link to Issue, update url if global_id is passed
@@ -1039,7 +1038,7 @@ def get_issue_remote_link_by_id(self, issue_key, link_id):
10391038
return self.get(url)
10401039

10411040
def update_issue_remote_link_by_id(
1042-
self, issue_key, link_id, url, title, global_id=None, relationship=None
1041+
self, issue_key, link_id, url, title, global_id=None, relationship=None
10431042
):
10441043
"""
10451044
Update existing Remote Link on Issue
@@ -1081,7 +1080,7 @@ def get_issue_transitions(self, issue_key):
10811080
"to": transition["to"]["name"],
10821081
}
10831082
for transition in (
1084-
self.get_issue_transitions_full(issue_key).json() or {}
1083+
self.get_issue_transitions_full(issue_key).json() or {}
10851084
).get("transitions")
10861085
]
10871086
else:
@@ -1092,7 +1091,7 @@ def get_issue_transitions(self, issue_key):
10921091
"to": transition["to"]["name"],
10931092
}
10941093
for transition in (
1095-
self.get_issue_transitions_full(issue_key) or {}
1094+
self.get_issue_transitions_full(issue_key) or {}
10961095
).get("transitions")
10971096
]
10981097

@@ -1264,7 +1263,7 @@ def user_update_email(self, username, email):
12641263
return self.user_update(username, data=data)
12651264

12661265
def user_create(
1267-
self, username, email, display_name, password=None, notification=None
1266+
self, username, email, display_name, password=None, notification=None
12681267
):
12691268
"""
12701269
Create a user in Jira
@@ -1361,10 +1360,10 @@ def user_disable(self, username):
13611360
return self.user_deactivate(username)
13621361

13631362
def user_disable_throw_rest_endpoint(
1364-
self,
1365-
username,
1366-
url="rest/scriptrunner/latest/custom/disableUser",
1367-
param="userName",
1363+
self,
1364+
username,
1365+
url="rest/scriptrunner/latest/custom/disableUser",
1366+
param="userName",
13681367
):
13691368
"""The disable method throw own rest enpoint"""
13701369
url = "{}?{}={}".format(url, param, username)
@@ -1386,8 +1385,8 @@ def user_get_websudo(self):
13861385
answer.split(
13871386
'<meta id="atlassian-token" name="atlassian-token" content="'
13881387
)[1]
1389-
.split("\n")[0]
1390-
.split('"')[0]
1388+
.split("\n")[0]
1389+
.split('"')[0]
13911390
)
13921391
if atl_token:
13931392
data["atl_token"] = atl_token
@@ -1401,12 +1400,12 @@ def invalidate_websudo(self):
14011400
return self.delete("rest/auth/1/websudo")
14021401

14031402
def user_find_by_user_string(
1404-
self,
1405-
username,
1406-
start=0,
1407-
limit=50,
1408-
include_inactive_users=False,
1409-
include_active_users=True,
1403+
self,
1404+
username,
1405+
start=0,
1406+
limit=50,
1407+
include_inactive_users=False,
1408+
include_active_users=True,
14101409
):
14111410
"""
14121411
Fuzzy search using username and display name
@@ -1542,14 +1541,14 @@ def get_project_versions(self, key, expand=None):
15421541
return self.get("rest/api/2/project/{}/versions".format(key), params=params)
15431542

15441543
def get_project_versions_paginated(
1545-
self,
1546-
key,
1547-
start=None,
1548-
limit=None,
1549-
order_by=None,
1550-
expand=None,
1551-
query=None,
1552-
status=None,
1544+
self,
1545+
key,
1546+
start=None,
1547+
limit=None,
1548+
order_by=None,
1549+
expand=None,
1550+
query=None,
1551+
status=None,
15531552
):
15541553
"""
15551554
Returns all versions for the specified project. Results are paginated.
@@ -1585,7 +1584,7 @@ def get_project_versions_paginated(
15851584
return self.get("rest/api/2/project/{}/version".format(key), params=params)
15861585

15871586
def add_version(
1588-
self, project_key, project_id, version, is_archived=False, is_released=False
1587+
self, project_key, project_id, version, is_archived=False, is_released=False
15891588
):
15901589
"""
15911590
Add missing version to project
@@ -1694,7 +1693,7 @@ def update_project(self, project_key, data, expand=None):
16941693
return self.put(url, data, params=params)
16951694

16961695
def update_project_category_for_project(
1697-
self, project_key, new_project_category_id, expand=None
1696+
self, project_key, new_project_category_id, expand=None
16981697
):
16991698
"""
17001699
Updates a project.
@@ -1724,7 +1723,7 @@ def get_notification_scheme_for_project(self, project_id_or_key):
17241723
return self.get(url)
17251724

17261725
def assign_project_notification_scheme(
1727-
self, project_key, new_notification_scheme=""
1726+
self, project_key, new_notification_scheme=""
17281727
):
17291728
"""
17301729
Updates a project.
@@ -1892,7 +1891,7 @@ def get_all_assignable_users_for_project(self, project_key, start=0, limit=50):
18921891
return self.get(url)
18931892

18941893
def get_assignable_users_for_issue(
1895-
self, issue_key, username=None, start=0, limit=50
1894+
self, issue_key, username=None, start=0, limit=50
18961895
):
18971896
"""
18981897
Provide assignable users for issue
@@ -2208,26 +2207,25 @@ def jql(self, jql, fields="*all", start=0, limit=None, expand=None):
22082207
params["expand"] = expand
22092208
return self.get("rest/api/2/search", params=params)
22102209

2211-
def csv(self, jql, limit=1000):
2210+
def csv(self, jql, limit=1000, all_fields=True):
22122211
"""
2213-
Get issues from jql search result with all related fields
2212+
Get issues from jql search result with ALL or CURRENT fields
2213+
default will be to return all fields
22142214
:param jql: JQL query
22152215
:param limit: max results in the output file
2216+
:param all_fields: To return all fields or current fields only
22162217
:return: CSV file
22172218
"""
2218-
params = {"tempMax": limit, "jqlQuery": jql}
2219-
url = "sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv"
2220-
return self.get(
2221-
url,
2222-
params=params,
2223-
not_json_response=True,
2224-
headers={"Accept": "application/csv"},
2225-
)
22262219

2227-
"""
2228-
Priority
2229-
Reference: https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/#api/2/priority
2230-
"""
2220+
params = {"tempMax": limit, "jqlQuery": jql}
2221+
if all_fields:
2222+
url = 'sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv'
2223+
else:
2224+
url = 'sr/jira.issueviews:searchrequest-csv-current-fields/temp/SearchRequest.csv'
2225+
return self.get(url,
2226+
params=params,
2227+
not_json_response=True,
2228+
headers={"Accept": "application/csv"}, )
22312229

22322230
def get_all_priorities(self):
22332231
"""
@@ -2260,7 +2258,7 @@ def get_all_workflows(self):
22602258
return self.get(url)
22612259

22622260
def get_workflows_paginated(
2263-
self, startAt=None, maxResults=None, workflowName=None, expand=None
2261+
self, startAt=None, maxResults=None, workflowName=None, expand=None
22642262
):
22652263
"""
22662264
Provide all workflows paginated (see https://developer.atlassian.com/cloud/jira/platform/rest/v2/\
@@ -2599,11 +2597,11 @@ def get_project_validated_key(self, key):
25992597
"""
26002598

26012599
def reindex(
2602-
self,
2603-
comments=True,
2604-
change_history=True,
2605-
worklogs=True,
2606-
indexing_type="BACKGROUND_PREFERRED",
2600+
self,
2601+
comments=True,
2602+
change_history=True,
2603+
worklogs=True,
2604+
indexing_type="BACKGROUND_PREFERRED",
26072605
):
26082606
"""
26092607
Reindex the Jira instance
@@ -2708,7 +2706,7 @@ def tempo_account_get_accounts_by_jira_project(self, project_id):
27082706
return self.get(url)
27092707

27102708
def tempo_account_associate_with_jira_project(
2711-
self, account_id, project_id, default_account=False, link_type="MANUAL"
2709+
self, account_id, project_id, default_account=False, link_type="MANUAL"
27122710
):
27132711
"""
27142712
The AccountLinkBean for associate Account with project
@@ -2959,7 +2957,7 @@ def tempo_timesheets_get_configuration(self):
29592957
return self.get(url)
29602958

29612959
def tempo_timesheets_get_team_utilization(
2962-
self, team_id, date_from, date_to=None, group_by=None
2960+
self, team_id, date_from, date_to=None, group_by=None
29632961
):
29642962
"""
29652963
GEt team utulization. Response in json
@@ -2977,13 +2975,13 @@ def tempo_timesheets_get_team_utilization(
29772975
return self.get(url, params=params)
29782976

29792977
def tempo_timesheets_get_worklogs(
2980-
self,
2981-
date_from=None,
2982-
date_to=None,
2983-
username=None,
2984-
project_key=None,
2985-
account_key=None,
2986-
team_id=None,
2978+
self,
2979+
date_from=None,
2980+
date_to=None,
2981+
username=None,
2982+
project_key=None,
2983+
account_key=None,
2984+
team_id=None,
29872985
):
29882986
"""
29892987
@@ -3051,7 +3049,7 @@ def tempo_timesheets_get_worklogs_by_issue(self, issue):
30513049
return self.get(url)
30523050

30533051
def tempo_timesheets_write_worklog(
3054-
self, worker, started, time_spend_in_seconds, issue_id, comment=None
3052+
self, worker, started, time_spend_in_seconds, issue_id, comment=None
30553053
):
30563054
"""
30573055
Log work for user
@@ -3205,7 +3203,7 @@ def tempo_teams_remove_member(self, team_id, member_id, membership_id):
32053203
return self.delete(url)
32063204

32073205
def tempo_teams_update_member_information(
3208-
self, team_id, member_id, membership_id, data
3206+
self, team_id, member_id, membership_id, data
32093207
):
32103208
"""
32113209
Update team membership attribute info
@@ -3234,7 +3232,7 @@ def tempo_teams_get_memberships_for_member(self, username):
32343232
# Resource: https://docs.atlassian.com/jira-software/REST/7.3.1/
32353233
#######################################################################
32363234
def get_all_agile_boards(
3237-
self, board_name=None, project_key=None, board_type=None, start=0, limit=50
3235+
self, board_name=None, project_key=None, board_type=None, start=0, limit=50
32383236
):
32393237
"""
32403238
Returns all boards. This only includes boards that the user has permission to view.

docs/jira.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ Manage issues
207207
# Delete Issue Links
208208
jira.delete_issue_remote_link_by_id(issue_key, link_id)
209209
210+
<<<<<<< HEAD
211+
=======
212+
# Export Issues to csv
213+
jira.csv(jql, all_fields=False)
214+
215+
216+
>>>>>>> a0bfce195ff799e9616a34b131bdaadbb096ee9d
210217
Manage Boards
211218
-------------
212219

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# coding=utf-8
2+
"""
3+
jira issues export to CSV - all or current.
4+
default is ALL
5+
below example uses the current fields
6+
"""
7+
8+
from atlassian import Jira
9+
10+
11+
def main():
12+
jira = Jira("http://localhost:8080",
13+
username="admin",
14+
password="admin")
15+
csv_issues = jira.csv(jql='project = "APA" and "Epic Link" = APA-3 ORDER BY created DESC',
16+
all_fields=False)
17+
with open('data.csv', 'wb') as file_obj:
18+
file_obj.write(csv_issues)
19+
20+
21+
if __name__ == '__main__':
22+
main()

0 commit comments

Comments
 (0)