A very quick and easy to way to query a JIRA instance and cache the results for fast queries and searches. JIRA's API
can be very slow, especially in large hosted projects. This module attempts to solve for that by caching the results
of queries in redis.
The easy way to install is
pip install rejira
import config, fields
from rejira import ReJIRA
rj = ReJIRA(config, fields.field_map)
issue = rj.get("OM-1")
print(issue.key) # "OM-1"
print(issue.sprint.name) # "Sprint 66"Or you can use search() to run JQL and return the results as a list of objects
...
issues = rj.search('project = OM and fixVersion in ("1.1.1", "1.1.0")')
for issue in issues:
print(issue.project.name) # "Project Old Main" The structure of the issue objects is set by the field configuration. This is basically a large dictionary that lets
reJIRA know how to structure your issue objects. This is to make things highly customizable, but it does suffer from
perhaps creating a bit more complexity as well.
For now, this is required, so it is probably a lot easier to start with the example file than to
build the file from scratch. That file is heavily commented, so please start there.
ReJIRA uses environment variables for most of its configuration. But there are some to be found in the configuration file as well.
Defaults are (bold)
The host for Redis. (localhost)
The host for Redis. (6379)
Redis Database (0)
Use the Redis Cache. (True)
Number of seconds to expire a cached result. (3600)
Your JIRA Username.
Your JIRA Password
Your JIRA host URL. Make sure it is https and has a trailing slash. (e.g. https://jira.atlassian.net)
Logging Level (WARN)
The file to write logs to. Defaults to STDOUT. If this is not blank, it will write the logs to this file. (blank)
Verify SSL Host Certificate. (True)
HTTP Proxy. Can be domain or host. (None)(e.g. http://username:password@proxy.host.com:8888)
HTTPS Proxy. Can be domain or host. (None)(e.g. http://username:password@proxy.host.com:8888)
For an example of these, look in /example/config.py
Uses the same options as the jira library for python.
jira_options = {"async": False,
"rest_api_version": "2",
"rest_path": "api",
"client_cert": None,
"context_path": "/",
"headers": {
"X-Atlassian-Token": "no-check",
"Cache-Control": "no-cache",
"Content-Type": "application/json"
},
"resilient": True
}Not currently used
Not currently used
Not currently used
Not currently used
If you are behind a proxy server, put the strings for them here. Include basic auth in the proxy.
Example:
proxies = { 'https://user:password@proxy.somewhere.com:8888', \
'http://user:password@proxy.somewhere.com:8888' }For proxies, you can also use environment variables as well.
Instantiates the reJIRA class
- Parameters
Config: Configuration options.
Field Map: Field map dictionary - Return Values
None
import config, fields
from rejira import ReJIRA
rj = ReJIRA(config, fields.field_map)Fetches the given issue from Cache or JIRA and returns the issue as an object
- Parameters
Issue Key: Key of the issue you are looking for - Return Values
Issue Object
issue = rj.get("OM-1")
print(issue.key) # "OM-1"
print(issue.sprint.name) # "Sprint 66"Fetches the results of the JQL and returns it as a list of ojbects
- Parameters
JQL Query: Formatted JQL query - Return Values
List of issue objects
...
issues = rj.search('project = OM and fixVersion in ("1.1.1", "1.1.0")')
for issue in issues:
print(issue.project.name) # "Project Old Main" Expires a given cache entry or entries.
- Parameters
Scope: "all" (default) or the key of an issue. - Return Values
None
...
rj.expire()Xnuiem - Ryan C Meinzer - https://thescrum.ninja
Copyright 2018 XM Tek LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.