Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions atlassian/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# coding=utf-8
"""
Constants used throughout the project.
"""

# URI Relative Path
API_SPRINT = "/rest/agile/1.0/sprint"

# JIRA CSV URI Path
CSV_PATH_ALL_FIELDS = 'sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv'
CSV_PATH_CURRENT_FIELDS = 'sr/jira.issueviews:searchrequest-csv-current-fields/temp/SearchRequest.csv'
18 changes: 13 additions & 5 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

from requests import HTTPError

from .constants import (
CSV_PATH_ALL_FIELDS,
CSV_PATH_CURRENT_FIELDS
)
from .rest_client import AtlassianRestAPI
from .errors import (
ApiError,
Expand Down Expand Up @@ -2052,16 +2056,20 @@ def jql(self, jql, fields='*all', start=0, limit=None, expand=None):
params['expand'] = expand
return self.get('rest/api/2/search', params=params)

def csv(self, jql, limit=1000):
def csv(self, jql, limit=1000, all_fields=True):
"""
Get issues from jql search result with all related fields
Get issues from jql search result with ALL or CURRENT fields
default will be to return all fields
:param jql: JQL query
:param limit: max results in the output file
:param all_fields: To return all fields or current fields only
:return: CSV file
"""
params = {'tempMax': limit,
'jqlQuery': jql}
url = 'sr/jira.issueviews:searchrequest-csv-all-fields/temp/SearchRequest.csv'
params = {'jqlQuery': jql,
'tempMax': limit}
url = CSV_PATH_ALL_FIELDS
if not all_fields:
url = CSV_PATH_CURRENT_FIELDS
return self.get(url, params=params, not_json_response=True, headers={'Accept': 'application/csv'})

#######################################################################################################
Expand Down
3 changes: 3 additions & 0 deletions docs/jira.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ Manage issues
# Delete Issue Links
jira.delete_issue_remote_link_by_id(issue_key, link_id)

# Export Issues to csv
jira.csv(jql, all_fields=False)


Manage Boards
-------------
Expand Down
22 changes: 22 additions & 0 deletions examples/jira/jira-issues-csv-export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# coding=utf-8
"""
jira issues export to CSV - all or current.
default is ALL
below example uses the current fields
"""

from atlassian import Jira


def main():
jira = Jira("http://localhost:8080",
username="admin",
password="admin")
csv_issues = jira.csv(jql='project = "APA" and "Epic Link" = APA-3 ORDER BY created DESC',
all_fields=False)
with open('data.csv', 'wb') as file_obj:
file_obj.write(csv_issues)


if __name__ == '__main__':
main()