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

Add caching of Jira requests. Also can clear the cache. #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions jira-dependency-graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import textwrap

import requests
import requests_cache
from functools import reduce

GOOGLE_CHART_URL = 'https://chart.apis.google.com/chart'
MAX_SUMMARY_LENGTH = 30

cached_requests = requests_cache.CachedSession('jira_cache')

def log(*args):
print(*args, file=sys.stderr)
Expand All @@ -36,9 +38,9 @@ def get(self, uri, params={}):
url = self.url + uri

if isinstance(self.auth, str):
return requests.get(url, params=params, cookies={'JSESSIONID': self.auth}, headers=headers, verify=self.no_verify_ssl)
return cached_requests.get(url, params=params, cookies={'JSESSIONID': self.auth}, headers=headers, verify=self.no_verify_ssl)
else:
return requests.get(url, params=params, auth=self.auth, headers=headers, verify=(not self.no_verify_ssl))
return cached_requests.get(url, params=params, auth=self.auth, headers=headers, verify=(not self.no_verify_ssl))

def get_issue(self, key):
""" Given an issue key (i.e. JRA-9) return the JSON representation of it. This is the only place where we deal
Expand Down Expand Up @@ -251,6 +253,7 @@ def parse_args():
parser.add_argument('-t', '--ignore-subtasks', action='store_true', default=False, help='Don''t include sub-tasks issues')
parser.add_argument('-T', '--dont-traverse', dest='traverse', action='store_false', default=True, help='Do not traverse to other projects')
parser.add_argument('-w', '--word-wrap', dest='word_wrap', default=False, action='store_true', help='Word wrap issue summaries instead of truncating them')
parser.add_argument('-a', '--clear-cache', dest='clear_cache', default=False, action='store_true', help='Clear requests cache')
parser.add_argument('--no-verify-ssl', dest='no_verify_ssl', default=False, action='store_true', help='Don\'t verify SSL certs for requests')
parser.add_argument('issues', nargs='*', help='The issue key (e.g. JRADEV-1107, JRADEV-1391)')
return parser.parse_args()
Expand Down Expand Up @@ -281,6 +284,9 @@ def main():
else getpass.getpass('Password: ')
auth = (user, password)

if options.clear_cache is True:
cached_requests.cache.clear()

jira = JiraSearch(options.jira_url, auth, options.no_verify_ssl)

if options.jql_query is not None:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests ~= 2.22
requests-cache ~= 0.6