Skip to content

Commit 0c2af64

Browse files
authored
Jira cache entries are strings, not lists (#400)
In-line _matching_jira_issue_query into _get_existing_jira_issue
1 parent bdf72ee commit 0c2af64

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

sync2jira/downstream_issue.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -234,26 +234,26 @@ def get_jira_client(issue, config):
234234
return client
235235

236236

237-
def _matching_jira_issue_query(client, issue, config):
237+
def _get_existing_jira_issue(client, issue, config):
238238
"""
239-
API calls that find matching JIRA tickets if any are present.
239+
Get a jira issue by the linked remote issue.
240240
241241
:param jira.client.JIRA client: JIRA client
242242
:param sync2jira.intermediary.Issue issue: Issue object
243243
:param Dict config: Config dict
244-
:returns: results: Returns a list of matching JIRA issues if any are found
245-
:rtype: List
244+
:returns: Returns a list of matching JIRA issues if any are found
245+
:rtype: str or None
246246
"""
247247

248248
# If there's an entry for the issue in our cache, fetch the issue key from it.
249249
if result := jira_cache.get(issue.url):
250-
issue_keys = [result]
250+
issue_keys = (result,)
251251
else:
252252
# Search for Jira issues with a "remote link" to the issue.url;
253-
# if we find none, return an empty list.
253+
# if we find none, return None.
254254
results = execute_snowflake_query(issue)
255255
if not results:
256-
return []
256+
return None
257257

258258
# From the results returned by Snowflake, make an iterable of the
259259
# issues' keys.
@@ -307,7 +307,7 @@ def _matching_jira_issue_query(client, issue, config):
307307

308308
# Cache the result for next time and return it.
309309
jira_cache[issue.url] = results[0].key
310-
return results
310+
return results[0]
311311

312312

313313
def find_username(_issue, config):
@@ -392,24 +392,6 @@ def _comment_matching(g_comments, j_comments):
392392
)
393393

394394

395-
def _get_existing_jira_issue(client, issue, config):
396-
"""
397-
Get a jira issue by the linked remote issue. \
398-
This is the new supported way of doing this.
399-
400-
:param jira.client.JIRA client: JIRA client
401-
:param sync2jira.intermediary.Issue issue: Issue object
402-
:param Dict config: Config dict
403-
:returns: Returns a list of matching JIRA issues if any are found
404-
:rtype: List
405-
"""
406-
results = _matching_jira_issue_query(client, issue, config)
407-
if results:
408-
return results[0]
409-
else:
410-
return None
411-
412-
413395
def _get_existing_jira_issue_legacy(client, issue):
414396
"""
415397
This is our old way of matching issues: use the special url field.
@@ -702,7 +684,7 @@ def _create_jira_issue(client, issue, config):
702684
return None
703685

704686
downstream = client.create_issue(**kwargs)
705-
jira_cache[issue.url] = [downstream.key]
687+
jira_cache[issue.url] = downstream.key
706688

707689
# Add values to the Epic link, QA, and EXD-Service fields if present
708690
if (

tests/test_downstream_issue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,12 +1420,12 @@ def test_matching_jira_issue_query(
14201420
d.jira_cache = d.UrlCache() # Clear the cache
14211421

14221422
# Call the function
1423-
response = d._matching_jira_issue_query(
1423+
response = d._get_existing_jira_issue(
14241424
client=mock_client, issue=self.mock_issue, config=self.mock_config
14251425
)
14261426

14271427
# Assert everything was called correctly
1428-
self.assertEqual(response, [mock_downstream_issue])
1428+
self.assertEqual(response, mock_downstream_issue)
14291429
mock_client.search_issues.assert_called_with("key in (SYNC2JIRA-123)")
14301430
mock_check_comments_for_duplicates.assert_called_with(
14311431
mock_client, mock_downstream_issue, "mock_username"

0 commit comments

Comments
 (0)