Skip to content

Commit a0bfce1

Browse files
committed
[JIRA] Issues export to CSV +current fields option
To provide option to export CURRENT fields also in addition to existing ALL fields Default : ALL fields (existing and non-breaking change) - Functionality addition in `atlassian/jira` - Example added - Constants file added to have project related constants - Docs example added Closes #602
1 parent 965c93a commit a0bfce1

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

atlassian/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# coding=utf-8
2+
"""
3+
Constants used throughout the project.
4+
"""
5+
6+
# URI Relative Path
7+
API_SPRINT = "/rest/agile/1.0/sprint"
8+
9+
# JIRA CSV URI Path
10+
CSV_PATH_ALL_FIELDS = 'sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv'
11+
CSV_PATH_CURRENT_FIELDS = 'sr/jira.issueviews:searchrequest-csv-current-fields/temp/SearchRequest.csv'

atlassian/jira.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
from requests import HTTPError
66

7+
from .constants import (
8+
CSV_PATH_ALL_FIELDS,
9+
CSV_PATH_CURRENT_FIELDS
10+
)
711
from .rest_client import AtlassianRestAPI
812
from .errors import (
913
ApiError,
@@ -2052,16 +2056,20 @@ def jql(self, jql, fields='*all', start=0, limit=None, expand=None):
20522056
params['expand'] = expand
20532057
return self.get('rest/api/2/search', params=params)
20542058

2055-
def csv(self, jql, limit=1000):
2059+
def csv(self, jql, limit=1000, all_fields=True):
20562060
"""
2057-
Get issues from jql search result with all related fields
2061+
Get issues from jql search result with ALL or CURRENT fields
2062+
default will be to return all fields
20582063
:param jql: JQL query
20592064
:param limit: max results in the output file
2065+
:param all_fields: To return all fields or current fields only
20602066
:return: CSV file
20612067
"""
2062-
params = {'tempMax': limit,
2063-
'jqlQuery': jql}
2064-
url = 'sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv'
2068+
params = {'jqlQuery': jql,
2069+
'tempMax': limit}
2070+
url = CSV_PATH_ALL_FIELDS
2071+
if not all_fields:
2072+
url = CSV_PATH_CURRENT_FIELDS
20652073
return self.get(url, params=params, not_json_response=True, headers={'Accept': 'application/csv'})
20662074

20672075
#######################################################################################################

docs/jira.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ Manage issues
207207
# Delete Issue Links
208208
jira.delete_issue_remote_link_by_id(issue_key, link_id)
209209
210+
# Export Issues to csv
211+
jira.csv(jql, all_fields=False)
212+
210213
211214
Manage Boards
212215
-------------
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)