Skip to content

Commit

Permalink
jira: eliminate unnecessary 'extra' fields
Browse files Browse the repository at this point in the history
Also, don't override get_issue_for_record. Jira was the only service
doing this and the only advantage was a marginal convenience in testing.
  • Loading branch information
ryneeverett committed Dec 28, 2024
1 parent 1bef94c commit ce92e3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
20 changes: 7 additions & 13 deletions bugwarrior/services/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ def to_taskwarrior(self):
return {**fixed_fields, **extra_fields}

def get_extra_fields(self):
if self.extra['extra_fields'] is None:
if self.config.extra_fields is None:
return {}

return {extra_field.label: extra_field.extract_value(
self.record['fields']) for extra_field in self.extra['extra_fields']}
self.record['fields']) for extra_field in self.config.extra_fields}

def get_entry(self):
created_at = self.record['fields']['created']
Expand Down Expand Up @@ -307,12 +307,12 @@ def get_url(self):
return self.config.base_uri + '/browse/' + self.record['key']

def get_summary(self):
if self.extra.get('jira_version') == 4:
if self.config.version == 4:
return self.record['fields']['summary']['value']
return self.record['fields']['summary']

def get_estimate(self):
if self.extra.get('jira_version') == 4:
if self.config.version == 4:
return self.record['fields']['timeestimate']['value']
try:
return self.record['fields']['timeestimate'] / 60 / 60
Expand Down Expand Up @@ -430,21 +430,15 @@ def annotations(self, issue, issue_obj):
issue_obj.get_url()
)

def get_issue_for_record(self, record, extra=None):
if extra is None:
extra = {}
extra.setdefault('sprint_field_names', self.sprint_field_names)
return super().get_issue_for_record(record, extra=extra)

def issues(self):
cases = self.jira.search_issues(self.query, maxResults=None)

for case in cases:
issue = self.get_issue_for_record(case.raw)
issue = self.get_issue_for_record(
case.raw,
extra={'sprint_field_names': self.sprint_field_names})
extra = {
'jira_version': self.config.version,
'body': self.body(issue),
'extra_fields': self.config.extra_fields,
}
if self.config.version > 4:
extra.update({
Expand Down
10 changes: 4 additions & 6 deletions tests/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def test_body_length_limit(self):
service = JiraService(
conf['myjira'], conf['general'], _skip_server=True)
issue = mock.Mock()
issue = mock.Mock()
issue.record = dict(fields=dict(description=description))
self.assertEqual(description, service.body(issue))

Expand Down Expand Up @@ -123,10 +122,9 @@ def get_extra_fields(self):
def test_to_taskwarrior(self):
arbitrary_url = 'http://one'
arbitrary_extra = {
'jira_version': 5,
'annotations': ['an annotation'],
'body': 'issue body',
'extra_fields': self.get_extra_fields(),
'sprint_field_names': [],
}

issue = self.service.get_issue_for_record(
Expand Down Expand Up @@ -175,9 +173,8 @@ def test_to_taskwarrior_sprint_with_goal(self):
]
arbitrary_url = 'http://one'
arbitrary_extra = {
'jira_version': 5,
'annotations': ['an annotation'],
'extra_fields': self.get_extra_fields()
'sprint_field_names': self.service.sprint_field_names,
}

issue = self.service.get_issue_for_record(
Expand Down Expand Up @@ -245,7 +242,8 @@ def test_issues(self):

def test_get_due(self):
issue = self.service.get_issue_for_record(
self.arbitrary_record_with_due
self.arbitrary_record_with_due,
extra={'sprint_field_names': self.service.sprint_field_names},
)
self.assertEqual(issue.get_due(), datetime.datetime(
2016, 9, 23, 16, 8, tzinfo=tzutc()))

0 comments on commit ce92e3a

Please sign in to comment.