Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = W503, E203
max-line-length = 79
ignore = E501,W503,E302,E241,W293,E128,E124,E123,W504,E261,E111,E226,E126,E127,E203
# max-line-length = 79
# max-complexity = 18
select = B,C,E,F,W,T4,B9
27 changes: 19 additions & 8 deletions jira_agile_metrics/calculators/cycletime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ def jira(custom_fields):
changes=[
Change(
"2018-01-02 10:01:01",
[("Flagged", None, "Impediment")],
[("Flagged", None, "Impediment", "customfield_100")],
),
Change(
"2018-01-03 01:00:00", [("Flagged", "Impediment", "")]
"2018-01-03 01:00:00",
[("Flagged", "Impediment", "", "customfield_100")],
), # blocked 1 day in the backlog
# (doesn't count towards blocked days)
Change(
Expand All @@ -64,13 +65,16 @@ def jira(custom_fields):
],
),
Change(
"2018-01-04 10:01:01", [("Flagged", "", "Impediment")]
"2018-01-04 10:01:01",
[("Flagged", "", "Impediment", "customfield_100")],
),
Change(
"2018-01-05 08:01:01", [("Flagged", "Impediment", "")]
"2018-01-05 08:01:01",
[("Flagged", "Impediment", "", "customfield_100")],
), # was blocked 1 day
Change(
"2018-01-08 10:01:01", [("Flagged", "", "Impediment")]
"2018-01-08 10:01:01",
[("Flagged", "", "Impediment", "customfield_100")],
), # stays blocked until today
],
),
Expand Down Expand Up @@ -109,7 +113,7 @@ def jira(custom_fields):
),
Change(
"2018-01-04 10:01:01",
[("Flagged", None, "Impediment")],
[("Flagged", None, "Impediment", "customfield_100")],
), # should clear two days later when issue resolved
Change(
"2018-01-05 01:01:01",
Expand Down Expand Up @@ -178,11 +182,18 @@ def jira(custom_fields):
),
Change(
"2018-01-07 01:01:01",
[("Flagged", None, "Awaiting input")],
[
(
"Flagged",
None,
"Awaiting input",
"customfield_100",
)
],
),
Change(
"2018-01-10 10:01:01",
[("Flagged", "Awaiting input", "")],
[("Flagged", "Awaiting input", "", "customfield_100")],
), # blocked 3 days
],
),
Expand Down
44 changes: 36 additions & 8 deletions jira_agile_metrics/calculators/progressreport_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,18 @@ def simple_ql(i, jql):
changes=[
Change(
"2018-01-02 10:01:01",
[("Flagged", None, "Impediment")],
[
(
"Flagged",
None,
"Impediment",
"customfield_100",
)
],
),
Change(
"2018-01-03 01:00:00",
[("Flagged", "Impediment", "")],
[("Flagged", "Impediment", "", "customfield_100")],
), # blocked 1 day in the backlog
# (doesn't count towards blocked days)
Change(
Expand All @@ -299,15 +306,15 @@ def simple_ql(i, jql):
),
Change(
"2018-01-04 10:01:01",
[("Flagged", "", "Impediment")],
[("Flagged", "", "Impediment", "customfield_100")],
),
Change(
"2018-01-05 08:01:01",
[("Flagged", "Impediment", "")],
[("Flagged", "Impediment", "", "customfield_100")],
), # was blocked 1 day
Change(
"2018-01-08 10:01:01",
[("Flagged", "", "Impediment")],
[("Flagged", "", "Impediment", "customfield_100")],
), # stays blocked until today
],
),
Expand Down Expand Up @@ -343,7 +350,14 @@ def simple_ql(i, jql):
),
Change(
"2018-01-04 10:01:01",
[("Flagged", None, "Impediment")],
[
(
"Flagged",
None,
"Impediment",
"customfield_100",
)
],
), # should clear two days later when issue resolved
Change(
"2018-01-05 01:01:01",
Expand Down Expand Up @@ -409,11 +423,25 @@ def simple_ql(i, jql):
),
Change(
"2018-01-07 01:01:01",
[("Flagged", None, "Awaiting input")],
[
(
"Flagged",
None,
"Awaiting input",
"customfield_100",
)
],
),
Change(
"2018-01-10 10:01:01",
[("Flagged", "Awaiting input", "")],
[
(
"Flagged",
"Awaiting input",
"",
"customfield_100",
)
],
), # blocked 3 days
],
),
Expand Down
2 changes: 1 addition & 1 deletion jira_agile_metrics/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def config_to_options(data, cwd=None, extended=False):
) from None

logger.debug("Extending file %s" % extends_filename)
with open(extends_filename) as extends_file:
with open(extends_filename, "r") as extends_file:
options = config_to_options(
extends_file.read(),
cwd=os.path.dirname(extends_filename),
Expand Down
2 changes: 1 addition & 1 deletion jira_agile_metrics/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def test_config_to_options_extends():
"""
)

fp.seek(0)
fp.close()

# Extend the file

Expand Down
3 changes: 2 additions & 1 deletion jira_agile_metrics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def __init__(self, fields):
class FauxChangeItem(object):
"""An item in a changelog change"""

def __init__(self, field, fromString, toString):
def __init__(self, field, fromString, toString, fieldId=None):
self.field = field
self.fieldId = fieldId if fieldId is not None else field
self.from_ = self.fromString = fromString
self.to = self.toString = toString

Expand Down
28 changes: 22 additions & 6 deletions jira_agile_metrics/querymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
logger = logging.getLogger(__name__)


def _field_id_from_changelog_item(history_item):
if hasattr(history_item, "fieldId"):
return history_item.fieldId
else:
return history_item.field


class IssueSnapshot(object):
"""A snapshot of the key fields of an issue
at a point in its change history"""
Expand Down Expand Up @@ -174,14 +181,21 @@ def iter_changes(self, issue, fields):
`['status']`.
"""

# Since the changelog history lists field ids and not names, we
# need to pre-cache the field ids of the fields to watch in the
# changelog
field_ids_to_names = {}

for field in fields:
initial_value = self.resolve_field_value(
issue, self.field_name_to_id(field)
)

field_id = self.field_name_to_id(field)
field_ids_to_names[field_id] = field

initial_value = self.resolve_field_value(issue, field_id)
try:
initial_value = next(
filter(
lambda h: h.field == field,
lambda h: _field_id_from_changelog_item(h) == field_id,
itertools.chain.from_iterable(
[
c.items
Expand Down Expand Up @@ -213,9 +227,11 @@ def iter_changes(self, issue, fields):
change_date = dateutil.parser.parse(change.created, ignoretz=True)

for item in change.items:
if item.field in fields:
if _field_id_from_changelog_item(item) in field_ids_to_names:
yield IssueSnapshot(
change=item.field,
change=field_ids_to_names[
_field_id_from_changelog_item(item)
],
key=issue.key,
date=change_date,
from_string=item.fromString,
Expand Down
3 changes: 2 additions & 1 deletion jira_agile_metrics/querymanager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def jira(custom_fields):
"A-1",
summary="Issue A-1",
issuetype=Value("Story", "story"),
status=Value("Backlotg", "backlog"),
status=Value("Backlog", "backlog"),
resolution=None,
created="2018-01-01 01:01:01",
customfield_001="Team 1",
Expand Down Expand Up @@ -65,6 +65,7 @@ def jira(custom_fields):
"Team",
"Team 2",
"Team 1",
"customfield_001",
)
],
),
Expand Down