diff --git a/atlassian/constants.py b/atlassian/constants.py new file mode 100644 index 000000000..30894642e --- /dev/null +++ b/atlassian/constants.py @@ -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' diff --git a/atlassian/jira.py b/atlassian/jira.py index 347e88f85..2ed04da50 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -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, @@ -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'}) ####################################################################################################### diff --git a/docs/jira.rst b/docs/jira.rst index f9c9c4412..efc1458ee 100644 --- a/docs/jira.rst +++ b/docs/jira.rst @@ -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 ------------- diff --git a/examples/jira/jira-issues-csv-export.py b/examples/jira/jira-issues-csv-export.py new file mode 100644 index 000000000..e75f8d277 --- /dev/null +++ b/examples/jira/jira-issues-csv-export.py @@ -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()