Skip to content

Commit 7303acc

Browse files
fixes
1 parent 44ff04a commit 7303acc

7 files changed

Lines changed: 56 additions & 49 deletions

File tree

sync2jira/downstream_issue.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ def update_jira_issue(existing, issue, client, config, updates_key="issue_update
10031003
log.info("Updating information for upstream %s: %s", updates_key, issue.url)
10041004

10051005
# Get a list of what the user wants to update for the upstream issue
1006-
updates = issue.downstream.get("issue_updates", [])
1006+
updates = issue.downstream.get(updates_key, [])
10071007

10081008
# Update relevant data if needed.
10091009
# If the user has specified nothing, just return.
@@ -1062,8 +1062,8 @@ def update_jira_issue(existing, issue, client, config, updates_key="issue_update
10621062
log.info("Looking for new transition(s)")
10631063
_update_transition(client, existing, issue, updates_key)
10641064

1065-
# Only execute 'on_close' events for listings that opt-in
1066-
# and when the issue is closed.
1065+
# Execute 'on_close' events when the issue is closed
1066+
# (opt-in is checked inside _update_on_close).
10671067
if issue.status == "Closed":
10681068
log.info("Attempting to update downstream issue on upstream closed event")
10691069
_update_on_close(existing, updates)
@@ -1417,7 +1417,7 @@ def _update_description(existing, issue, updates_key="issue_updates"):
14171417
Helper function to sync description between upstream issue and downstream JIRA issue.
14181418
14191419
:param jira.resource.Issue existing: Existing JIRA issue
1420-
:param issue: Upstream Issue or PR
1420+
:param sync2jira.intermediary.Issue or sync2jira.intermediary.PR issue: Upstream Issue or PR
14211421
:param str updates_key: Config key for the updates list
14221422
:returns: Nothing
14231423
"""

sync2jira/downstream_pr.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,9 @@ def _create_jira_issue_from_pr(client, pr, config):
280280
"""
281281

282282
pr_content = pr.content or f"PR: {pr.url}"
283-
if pr.downstream.get("issue_updates"):
284-
if (
285-
pr.source == "github"
286-
and pr_content
287-
and "github_markdown" in pr.downstream["issue_updates"]
288-
):
289-
pr_content = d_issue.convert_content(pr_content)
283+
pr_updates = pr.downstream.get(UPDATES_KEY, [])
284+
if pr.source == "github" and pr_content and "github_markdown" in pr_updates:
285+
pr_content = d_issue.convert_content(pr_content)
290286

291287
# Convert PR to Issue-like object for creation
292288
# PR and Issue share similar structure, but we need to adapt it
@@ -297,8 +293,8 @@ def _create_jira_issue_from_pr(client, pr, config):
297293
upstream=pr.upstream,
298294
comments=pr.comments,
299295
config=config,
300-
tags=[], # PRs don't have tags in the same way
301-
fixVersion=[],
296+
tags=pr.tags,
297+
fixVersion=pr.fixVersion,
302298
priority=pr.priority,
303299
content=pr_content,
304300
reporter=pr.reporter,

sync2jira/intermediary.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def __init__(
147147
upstream,
148148
config,
149149
comments,
150+
tags,
151+
fixVersion,
150152
priority,
151153
content,
152154
reporter,
@@ -163,8 +165,8 @@ def __init__(
163165
self.url = url
164166
self.upstream = upstream
165167
self.comments = comments
166-
# self.tags = tags
167-
# self.fixVersion = fixVersion
168+
self.tags = tags
169+
self.fixVersion = fixVersion
168170
self.priority = priority
169171

170172
# JIRA treats utf-8 characters in ways we don't totally understand, so scrub content down to
@@ -235,8 +237,8 @@ def from_github(cls, upstream, pr, suffix, config, action=None):
235237
upstream=upstream,
236238
config=config,
237239
comments=comments,
238-
# tags=issue['labels'],
239-
# fixVersion=[issue['milestone']],
240+
tags=pr.get("labels", []),
241+
fixVersion=[pr.get("milestone")],
240242
priority=None,
241243
content=pr.get("body"),
242244
reporter=pr["user"]["fullname"],

sync2jira/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,8 @@ def handle_msg(body, suffix, config):
321321
if not (pr := handler(body, config, is_pr=True)):
322322
log.info("Not handling PR issue update -- not configured")
323323
return
324-
# PRs require additional handling (Issues do not have suffix, and
325-
# reporter needs to be reformatted).
324+
# PRs require additional handling (Issues do not have suffix).
326325
pr.suffix = suffix
327-
pr.reporter = pr.reporter.get("fullname")
328326
setattr(pr, "match", matcher(pr.content, pr.comments))
329327
d_pr.sync_with_jira(pr, config)
330328
else:

tests/test_downstream_issue.py

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ def test_assign_user_remove_all(self, mock_client):
747747
mock_client.search_users.assert_not_called()
748748

749749
def common_test_create_jira_issue(
750-
self, mock_attach_link, mock_client, mockupdate_jira_issue
750+
self, mock_attach_link, mock_client, mock_update_jira_issue
751751
):
752752
"""Common code for testing _create_jira_issue"""
753753

@@ -782,7 +782,7 @@ def common_test_create_jira_issue(
782782
self.mock_downstream,
783783
{"url": "mock_url", "title": "Upstream issue"},
784784
)
785-
mockupdate_jira_issue.assert_called_with(
785+
mock_update_jira_issue.assert_called_with(
786786
self.mock_downstream, self.mock_issue, mock_client, self.mock_config
787787
)
788788
self.mock_downstream.update.assert_any_call({"customfield_1": "DUMMY-1234"})
@@ -798,13 +798,13 @@ def common_test_create_jira_issue(
798798
@mock.patch(PATH + "attach_link")
799799
@mock.patch("jira.client.JIRA")
800800
def test_create_jira_issue(
801-
self, mock_client, mock_attach_link, mockupdate_jira_issue
801+
self, mock_client, mock_attach_link, mock_update_jira_issue
802802
):
803803
"""
804804
Tests '_create_jira_issue' function normal success case
805805
"""
806806
self.common_test_create_jira_issue(
807-
mock_attach_link, mock_client, mockupdate_jira_issue
807+
mock_attach_link, mock_client, mock_update_jira_issue
808808
)
809809

810810
mock_client.add_comment.assert_not_called()
@@ -813,7 +813,7 @@ def test_create_jira_issue(
813813
@mock.patch(PATH + "attach_link")
814814
@mock.patch("jira.client.JIRA")
815815
def test_create_jira_issue_failed_epic_link(
816-
self, mock_client, mock_attach_link, mockupdate_jira_issue
816+
self, mock_client, mock_attach_link, mock_update_jira_issue
817817
):
818818
"""
819819
Tests '_create_jira_issue' function when we fail while updating the epic link
@@ -822,7 +822,7 @@ def test_create_jira_issue_failed_epic_link(
822822
self.mock_downstream.update.side_effect = [JIRAError, "success", "success"]
823823

824824
self.common_test_create_jira_issue(
825-
mock_attach_link, mock_client, mockupdate_jira_issue
825+
mock_attach_link, mock_client, mock_update_jira_issue
826826
)
827827

828828
mock_client.add_comment.assert_called_with(
@@ -833,7 +833,7 @@ def test_create_jira_issue_failed_epic_link(
833833
@mock.patch(PATH + "attach_link")
834834
@mock.patch("jira.client.JIRA")
835835
def test_create_jira_issue_failed_exd_service(
836-
self, mock_client, mock_attach_link, mockupdate_jira_issue
836+
self, mock_client, mock_attach_link, mock_update_jira_issue
837837
):
838838
"""
839839
Tests '_create_jira_issue' function when we fail while updating the
@@ -843,7 +843,7 @@ def test_create_jira_issue_failed_exd_service(
843843
self.mock_downstream.update.side_effect = ["success", "success", JIRAError]
844844

845845
self.common_test_create_jira_issue(
846-
mock_attach_link, mock_client, mockupdate_jira_issue
846+
mock_attach_link, mock_client, mock_update_jira_issue
847847
)
848848

849849
mock_client.add_comment.assert_called_with(
@@ -862,7 +862,7 @@ def test_create_jira_issue_multiple_types(
862862
mock_client,
863863
mock_get_preferred_issue_types,
864864
mock_attach_link,
865-
mockupdate_jira_issue,
865+
mock_update_jira_issue,
866866
):
867867
"""
868868
Tests '_create_jira_issue' function when multiple possible issue types are found
@@ -872,7 +872,7 @@ def test_create_jira_issue_multiple_types(
872872
mock_get_preferred_issue_types.return_value = issue_types
873873

874874
self.common_test_create_jira_issue(
875-
mock_attach_link, mock_client, mockupdate_jira_issue
875+
mock_attach_link, mock_client, mock_update_jira_issue
876876
)
877877

878878
mock_client.add_comment.assert_called_with(
@@ -884,7 +884,7 @@ def test_create_jira_issue_multiple_types(
884884
@mock.patch(PATH + "attach_link")
885885
@mock.patch("jira.client.JIRA")
886886
def test_create_jira_issue_no_updates(
887-
self, mock_client, mock_attach_link, mockupdate_jira_issue
887+
self, mock_client, mock_attach_link, mock_update_jira_issue
888888
):
889889
"""
890890
Tests '_create_jira_issue' function where we have
@@ -918,7 +918,7 @@ def test_create_jira_issue_no_updates(
918918
self.mock_downstream,
919919
{"url": "mock_url", "title": "Upstream issue"},
920920
)
921-
mockupdate_jira_issue.assert_called_with(
921+
mock_update_jira_issue.assert_called_with(
922922
self.mock_downstream, self.mock_issue, mock_client, self.mock_config
923923
)
924924
self.assertEqual(response, self.mock_downstream)
@@ -1014,7 +1014,7 @@ def test_sync_with_jira_matching(
10141014
mock_existing_jira_issue_legacy,
10151015
mock_client,
10161016
mock_create_jira_issue,
1017-
mockupdate_jira_issue,
1017+
mock_update_jira_issue,
10181018
mock_existing_jira_issue,
10191019
mock_get_jira_client,
10201020
):
@@ -1032,7 +1032,7 @@ def test_sync_with_jira_matching(
10321032

10331033
# Assert all calls were made correctly
10341034
mock_get_jira_client.assert_called_with(self.mock_issue, self.mock_config)
1035-
mockupdate_jira_issue.assert_called_with(
1035+
mock_update_jira_issue.assert_called_with(
10361036
self.mock_downstream, self.mock_issue, mock_client, self.mock_config
10371037
)
10381038
mock_create_jira_issue.assert_not_called()
@@ -1051,7 +1051,7 @@ def test_sync_with_jira_down(
10511051
mock_existing_jira_issue_legacy,
10521052
mock_client,
10531053
mock_create_jira_issue,
1054-
mockupdate_jira_issue,
1054+
mock_update_jira_issue,
10551055
mock_existing_jira_issue,
10561056
mock_get_jira_client,
10571057
):
@@ -1069,7 +1069,7 @@ def test_sync_with_jira_down(
10691069

10701070
# Assert all calls were made correctly
10711071
mock_get_jira_client.assert_called_with(self.mock_issue, self.mock_config)
1072-
mockupdate_jira_issue.assert_not_called()
1072+
mock_update_jira_issue.assert_not_called()
10731073
mock_create_jira_issue.assert_not_called()
10741074
mock_existing_jira_issue_legacy.assert_not_called()
10751075

@@ -1086,7 +1086,7 @@ def test_sync_with_jira_no_matching(
10861086
mock_existing_jira_issue_legacy,
10871087
mock_client,
10881088
mock_create_jira_issue,
1089-
mockupdate_jira_issue,
1089+
mock_update_jira_issue,
10901090
mock_existing_jira_issue,
10911091
mock_get_jira_client,
10921092
):
@@ -1104,7 +1104,7 @@ def test_sync_with_jira_no_matching(
11041104

11051105
# Assert all calls were made correctly
11061106
mock_get_jira_client.assert_called_with(self.mock_issue, self.mock_config)
1107-
mockupdate_jira_issue.assert_not_called()
1107+
mock_update_jira_issue.assert_not_called()
11081108
mock_create_jira_issue.assert_called_with(
11091109
mock_client, self.mock_issue, self.mock_config
11101110
)
@@ -1113,15 +1113,14 @@ def test_sync_with_jira_no_matching(
11131113
@mock.patch(PATH + "convert_content")
11141114
def test_maybe_convert_markdown(self, mock_convert):
11151115
"""maybe_convert_markdown: converts when opted-in, skips otherwise."""
1116-
mock_convert.return_value = "h1. Hello"
11171116

11181117
# Converts when source=github, content non-empty, github_markdown in updates
1118+
mock_convert.return_value = "h1. Hello"
11191119
issue = MagicMock()
11201120
issue.downstream = {"issue_updates": ["description", "github_markdown"]}
11211121
issue.source = "github"
11221122
issue.content = "# Hello"
11231123
d.maybe_convert_markdown(issue)
1124-
mock_convert.assert_called_once_with("# Hello")
11251124
self.assertEqual(issue.content, "h1. Hello")
11261125

11271126
# Works with pr_updates key
@@ -1130,23 +1129,28 @@ def test_maybe_convert_markdown(self, mock_convert):
11301129
issue.downstream = {"pr_updates": ["github_markdown", "description"]}
11311130
issue.content = "**bold**"
11321131
d.maybe_convert_markdown(issue, "pr_updates")
1133-
mock_convert.assert_called_once_with("**bold**")
11341132
self.assertEqual(issue.content, "*bold*")
11351133

11361134
# Skips when github_markdown not in updates
11371135
mock_convert.reset_mock()
11381136
issue.downstream = {"issue_updates": ["description"]}
11391137
issue.content = "# Hello"
11401138
d.maybe_convert_markdown(issue)
1141-
mock_convert.assert_not_called()
11421139
self.assertEqual(issue.content, "# Hello")
11431140

11441141
# Skips when content is empty
11451142
mock_convert.reset_mock()
11461143
issue.downstream = {"issue_updates": ["github_markdown"]}
11471144
issue.content = ""
11481145
d.maybe_convert_markdown(issue)
1149-
mock_convert.assert_not_called()
1146+
self.assertEqual(issue.content, "")
1147+
1148+
# Skips when source is not github
1149+
issue.source = "pagure"
1150+
issue.downstream = {"issue_updates": ["github_markdown"]}
1151+
issue.content = "# Hello"
1152+
d.maybe_convert_markdown(issue)
1153+
self.assertEqual(issue.content, "# Hello")
11501154

11511155
@mock.patch(PATH + "pypandoc")
11521156
def test_convert_content(self, mock_pypandoc):
@@ -1200,7 +1204,7 @@ def test_convert_content(self, mock_pypandoc):
12001204
@mock.patch(PATH + "_update_assignee")
12011205
@mock.patch(PATH + "_update_on_close")
12021206
@mock.patch("jira.client.JIRA")
1203-
def testupdate_jira_issue_closed(
1207+
def test_update_jira_issue_closed(
12041208
self,
12051209
mock_client,
12061210
mock_update_on_close,
@@ -1261,7 +1265,7 @@ def testupdate_jira_issue_closed(
12611265
@mock.patch(PATH + "_update_assignee")
12621266
@mock.patch(PATH + "_update_on_close")
12631267
@mock.patch("jira.client.JIRA")
1264-
def testupdate_jira_issue_open(
1268+
def test_update_jira_issue_open(
12651269
self,
12661270
mock_client,
12671271
mock_update_on_close,
@@ -2377,7 +2381,7 @@ def test_get_field_id_by_name_exception(self):
23772381
@mock.patch(PATH + "attach_link")
23782382
@mock.patch("jira.client.JIRA")
23792383
def test_create_jira_issue_epic_link_field_not_found(
2380-
self, mock_client, mock_attach_link, mockupdate_jira_issue
2384+
self, mock_client, mock_attach_link, mock_update_jira_issue
23812385
):
23822386
"""Test _create_jira_issue when Epic Link field cannot be resolved"""
23832387
# Set up return values
@@ -2439,7 +2443,7 @@ def test_update_github_project_fields_storypoints_resolution_failure(
24392443
@mock.patch(PATH + "change_status")
24402444
@mock.patch("jira.client.JIRA")
24412445
def test_create_jira_issue_with_component_and_labels(
2442-
self, mock_client, mock_change_status, mock_attach_link, mockupdate_jira_issue
2446+
self, mock_client, mock_change_status, mock_attach_link, mock_update_jira_issue
24432447
):
24442448
"""Test _create_jira_issue with component and labels"""
24452449
# Clear cache first
@@ -2474,7 +2478,7 @@ def test_create_jira_issue_with_component_and_labels(
24742478
@mock.patch(PATH + "change_status")
24752479
@mock.patch("jira.client.JIRA")
24762480
def test_create_jira_issue_with_default_status_and_upstream_id(
2477-
self, mock_client, mock_change_status, mock_attach_link, mockupdate_jira_issue
2481+
self, mock_client, mock_change_status, mock_attach_link, mock_update_jira_issue
24782482
):
24792483
"""Test _create_jira_issue with default_status and upstream_id comment"""
24802484
# Clear cache first
@@ -2668,7 +2672,7 @@ def test_UrlCache(self):
26682672
@mock.patch(PATH + "_update_assignee")
26692673
@mock.patch(PATH + "_update_on_close")
26702674
@mock.patch("jira.client.JIRA")
2671-
def testupdate_jira_issue_github_project_fields_early_exit(
2675+
def test_update_jira_issue_github_project_fields_early_exit(
26722676
self,
26732677
mock_client,
26742678
mock_update_on_close,

tests/test_downstream_pr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,8 @@ def _setup_pr_for_issue_creation(self, **overrides):
632632
self.mock_pr.url = "https://github.com/test/repo/pull/1"
633633
self.mock_pr.upstream = "test/repo"
634634
self.mock_pr.comments = []
635+
self.mock_pr.tags = ["bug", "enhancement"]
636+
self.mock_pr.fixVersion = ["v1.0"]
635637
self.mock_pr.priority = None
636638
self.mock_pr.content = "PR description"
637639
self.mock_pr.reporter = "testuser"
@@ -657,6 +659,8 @@ def _assert_issue_created_with_pr_fields(self, mock_issue_class, **field_overrid
657659
self.assertEqual(kwargs["title"], self.mock_pr._title)
658660
self.assertEqual(kwargs["url"], self.mock_pr.url)
659661
self.assertEqual(kwargs["upstream"], self.mock_pr.upstream)
662+
self.assertEqual(kwargs["tags"], self.mock_pr.tags)
663+
self.assertEqual(kwargs["fixVersion"], self.mock_pr.fixVersion)
660664
self.assertEqual(kwargs["status"], self.mock_pr.status)
661665
self.assertEqual(kwargs["id_"], self.mock_pr.id)
662666

tests/test_intermediary.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def test_from_github_pr_reopen(self, mock_matcher):
243243

244244
self.assertEqual(response.suffix, "reopened")
245245
self.assertEqual(response.status, None)
246+
self.assertEqual(response.tags, "mock_tags")
247+
self.assertEqual(response.fixVersion, ["mock_milestone"])
246248
self.assertEqual(response.downstream, {"mock_downstream": "mock_key"})
247249
self.assertEqual(response.jira_key, "JIRA-1234")
248250
self.mock_github_pr["comments"][0]["changed"] = None
@@ -278,6 +280,7 @@ def test_from_github_pr_flat_topic_normalizes_suffix(self, mock_matcher):
278280
base_kw["action"] = action
279281
response = i.PR.from_github(**base_kw)
280282
self.assertEqual(response.suffix, expected)
283+
self.assertEqual(response.status, None)
281284

282285
def test_matcher(self):
283286
"""This tests the matcher function"""

0 commit comments

Comments
 (0)