Skip to content

Commit

Permalink
Use scriptrunner issueFunction to speed up things
Browse files Browse the repository at this point in the history
Original code needed per-project JIRA definition because JiraUpdated was
querying all JIRA issues in a project that changed over defined period
of time. This was wasteful and for JIRA instances with scriptrunner
installed we can do things faster and with a single configuration

With this change:
 * project configuration is optional - if omitted all projects are
   reported
 * added new "login" config item needed because when lastUpdated('by
   <login>') is triggered with non-existing login name it causes failure
   of the JIRA plugin.
 * JiraUpdated really only reports comments and does not report other
   changes such as state change (this removes duplicate when closing issues
   as a side-effect)

This will need further rework so that use of scriptrunner is
optional/configured properly (since it's not part of JIRA itself).
  • Loading branch information
Stanislav Ochotnicky committed Feb 17, 2020
1 parent ca5827e commit 55b45b7
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions did/plugins/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,13 @@ def fetch(self):
log.info("Searching for issues created in {0} by {1}".format(
self.parent.project, self.user))
query = (
"project = '{0}' AND creator = '{1}' AND "
"created >= {2} AND created <= {3}".format(
self.parent.project, self.user.email,
"creator = '{0}' AND "
"created >= {1} AND created <= {2}".format(
self.user.email,
self.options.since, self.options.until))
if self.parent.project:
query = query + " AND project = '{0}'".format(
self.parent.project)
self.stats = Issue.search(query, stats=self)


Expand All @@ -146,14 +149,13 @@ def fetch(self):
log.info("Searching for issues updated in {0} by {1}".format(
self.parent.project, self.user))
query = (
"project = '{0}' AND "
"updated >= {1} AND created <= {2}".format(
self.parent.project,
"issueFunction in commented"
"('by {0} after {1} before {2}')".format(
self.parent.login,
self.options.since, self.options.until))
# Filter only issues commented by given user
self.stats = [
issue for issue in Issue.search(query, stats=self)
if issue.updated(self.user, self.options)]
if self.parent.project:
query = query + " AND project = '{0}'".format(
self.parent.project)


class JiraResolved(Stats):
Expand All @@ -162,10 +164,13 @@ def fetch(self):
log.info("Searching for issues resolved in {0} by {1}".format(
self.parent.project, self.user))
query = (
"project = '{0}' AND assignee = '{1}' AND "
"resolved >= {2} AND resolved <= {3}".format(
self.parent.project, self.user.email,
"assignee = '{0}' AND "
"resolved >= {1} AND resolved <= {2}".format(
self.user.email,
self.options.since, self.options.until))
if self.parent.project:
query = query + " AND project = '{0}'".format(
self.parent.project)
self.stats = Issue.search(query, stats=self)


Expand Down Expand Up @@ -235,10 +240,8 @@ def __init__(self, option, name=None, parent=None, user=None):
self.ssl_verify = SSL_VERIFY

# Make sure we have project set
if "project" not in config:
raise ReportError(
"No project set in the [{0}] section".format(option))
self.project = config["project"]
self.project = config.get("project", None)
self.login = config.get("login", None)
# Check for custom prefix
self.prefix = config["prefix"] if "prefix" in config else None
# Create the list of stats
Expand Down

0 comments on commit 55b45b7

Please sign in to comment.