Skip to content

Commit 309978a

Browse files
fixes
1 parent f207f08 commit 309978a

2 files changed

Lines changed: 26 additions & 16 deletions

File tree

sync2jira/downstream_issue.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def get_existing_jira_issue(client, issue, config):
316316
:rtype: JIssue or None
317317
"""
318318

319-
issue_keys = _get_existing_jira_issue_query(issue)
319+
issue_keys = _get_existing_jira_issue_keys(issue)
320320
if not issue_keys:
321321
return None
322322
jql = f"key in ({','.join(issue_keys)})"
@@ -370,22 +370,23 @@ def get_existing_jira_issue(client, issue, config):
370370
return results[0]
371371

372372

373-
def _get_existing_jira_issue_query(issue: Issue) -> tuple[str, ...]:
373+
def _get_existing_jira_issue_keys(issue: Issue) -> tuple[str, ...]:
374374
"""
375-
Generate a JQL query to find downstream issues corresponding to a given
376-
upstream issue. Return empty tuple if no matches were found in either our local
377-
cache or in the Dataverse.
375+
Retrieve downstream Jira issue keys corresponding to a given upstream issue.
376+
377+
The function first checks the local cache; if no cached result is found,
378+
it queries Snowflake. Returns empty tuple if no matches are found.
378379
379380
:param sync2jira.intermediary.Issue issue: Issue object
380-
:returns: A string containing the JQL query or None if no matches
381-
:rtype: Tuple[tuple[str, ...]
381+
:returns: A tuple of Jira issue keys, or None if no matches are found
382+
:rtype: Optional[Tuple[str, ...]]
382383
"""
383384
if result := jira_cache.get(issue.url):
384385
issue_keys = (result,)
385386
else:
386387
results = execute_snowflake_query(issue)
387388
if not results:
388-
return None
389+
return ()
389390
issue_keys = tuple(row[0] for row in results)
390391

391392
return issue_keys
@@ -448,7 +449,7 @@ def _jira_user_display_label(user) -> Optional[str]:
448449
"""Best-effort display string for a Jira User (Cloud: displayName, else name)."""
449450
if not user:
450451
return None
451-
return getattr(user, "displayName", getattr(user, "name", None))
452+
return getattr(user, "displayName", None) or getattr(user, "name", None)
452453

453454

454455
def check_comments_for_duplicate(client, result, username):

tests/test_downstream_issue.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ class MockIssue(object):
269269
)
270270

271271
@mock.patch(PATH + "_filter_downstream_issues")
272-
@mock.patch(PATH + "_get_existing_jira_issue_query")
272+
@mock.patch(PATH + "_get_existing_jira_issue_keys")
273273
@mock.patch("jira.client.JIRA")
274-
def test_get_existing_newstyle(self, mock_client, mock_get_query, mock_filter):
274+
def test_get_existing_newstyle(self, mock_client, mock_get_keys, mock_filter):
275275
"""
276276
This tests 'get_existing_jira_issue' function.
277277
"""
@@ -290,7 +290,7 @@ def test_get_existing_newstyle(self, mock_client, mock_get_query, mock_filter):
290290

291291
scenarios = (
292292
{
293-
"scenario": "_get_existing_jira_issue_query returns no keys",
293+
"scenario": "_get_existing_jira_issue_keys returns no keys",
294294
"query_return": (),
295295
"search_issues": None,
296296
"filter_results": None,
@@ -347,7 +347,7 @@ def test_get_existing_newstyle(self, mock_client, mock_get_query, mock_filter):
347347

348348
for x in scenarios:
349349
d.jira_cache = d.UrlCache() # Clear the cache
350-
mock_get_query.return_value = x["query_return"]
350+
mock_get_keys.return_value = x["query_return"]
351351
mock_client.search_issues.return_value = x["search_issues"]
352352
mock_filter.return_value = x["filter_results"]
353353
mock_client.issue.side_effect = x["issue_side_effect"]
@@ -361,7 +361,7 @@ def test_get_existing_newstyle(self, mock_client, mock_get_query, mock_filter):
361361
self.assertEqual(d.jira_cache[self.mock_issue.url], x["expected"].key)
362362

363363
@mock.patch(PATH + "execute_snowflake_query")
364-
def test_get_existing_jira_issue_query(self, mock_snowflake):
364+
def test_get_existing_jira_issue_keys(self, mock_snowflake):
365365
scenarios = (
366366
{
367367
"jira_cache": {self.mock_issue.url: "issue_key"},
@@ -371,7 +371,7 @@ def test_get_existing_jira_issue_query(self, mock_snowflake):
371371
{
372372
"jira_cache": {},
373373
"snowflake": (),
374-
"expected": None,
374+
"expected": (),
375375
},
376376
{
377377
"jira_cache": {},
@@ -392,7 +392,7 @@ def test_get_existing_jira_issue_query(self, mock_snowflake):
392392
for x in scenarios:
393393
d.jira_cache = x["jira_cache"]
394394
mock_snowflake.return_value = x["snowflake"]
395-
result = d._get_existing_jira_issue_query(self.mock_issue)
395+
result = d._get_existing_jira_issue_keys(self.mock_issue)
396396
self.assertEqual(result, x["expected"])
397397

398398
@mock.patch(PATH + "find_username")
@@ -1720,6 +1720,15 @@ def test_jira_user_display_label(self):
17201720
d._jira_user_display_label(types.SimpleNamespace(name="bob_only")),
17211721
"bob_only",
17221722
)
1723+
self.assertEqual(
1724+
d._jira_user_display_label(
1725+
types.SimpleNamespace(displayName="Alice", name="bob")
1726+
),
1727+
"Alice",
1728+
)
1729+
self.assertIsNone(
1730+
d._jira_user_display_label(types.SimpleNamespace()),
1731+
)
17231732

17241733
@mock.patch("jira.client.JIRA")
17251734
def test_check_comments_for_duplicates(self, mock_client):

0 commit comments

Comments
 (0)