Skip to content
Merged
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
21 changes: 13 additions & 8 deletions sync2jira/downstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ def _update_assignee(client, existing, issue, overwrite):
"""

us_exists = bool(
issue.assignee and issue.assignee[0] and issue.assignee[0].get("fullname")
issue.assignee and issue.assignee[0] and issue.assignee[0].get("login")
)
Comment thread
webbnh marked this conversation as resolved.
assignee = existing.fields.assignee
ds_exists = bool(assignee) and _jira_user_display_label(assignee) is not None
Expand All @@ -1239,14 +1239,19 @@ def _update_assignee(client, existing, issue, overwrite):
# Let assign_user() figure out what to do.
update = True
elif us_exists:
# Overwrite the downstream assignment only if it is different from
# the upstream one.
un = issue.assignee[0]["fullname"]
dn = _jira_user_display_label(assignee)
update = un != dn and remove_diacritics(un) != dn
un = issue.assignee[0].get("fullname")
if un:
# Overwrite the downstream assignment only if it is different
# from the upstream one.
dn = _jira_user_display_label(assignee)
update = un != dn and remove_diacritics(un) != remove_diacritics(dn)
else:
# Upstream assignee has no fullname; let assign_user() resolve
# via LDAP/email lookup using the login.
update = True
else:
# Without an upstream owner, update only if the downstream is not
# assigned to the project owner.
# Without an upstream assignee, update only if the downstream is
# not assigned to the project owner.
update = issue.downstream.get("owner") != _jira_user_display_label(assignee)
else:
# We're not overwriting, so call assign_user() only if the downstream
Expand Down
3 changes: 2 additions & 1 deletion sync2jira/upstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def handle_github_message(body, config, is_pr=False):

headers, github_client = get_github_client(config)
reformat_github_issue(issue, upstream, github_client)
add_project_values(issue, upstream, headers, config)
updates_key = "pr_updates" if is_pr else "issue_updates"
add_project_values(issue, upstream, headers, config, updates_key)
return i.Issue.from_github(upstream, issue, config)


Expand Down
61 changes: 37 additions & 24 deletions tests/test_downstream_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,38 +1686,44 @@ def test_update_assignee_all(self, mock_client, mock_assign_user):
(12, None),
# - upstream assignee exists and assignments are different: called with remove_all=False
(13, False),
# - upstream assignee has a fullname of None: called with remove_all=True
(14, True),
# - upstream assignee has login but fullname is None: called with remove_all=False
(14, False),
# - upstream assignee has login but no fullname key: called with remove_all=False
(15, False),
# - upstream assignee does not exist: called with remove_all=True
(15, True),
# - upstream assignee is an empty list: called with remove_all=True
(16, True),
# - upstream assignee is an empty list: called with remove_all=True
(17, True),
# - downstream assignee is owner
# - upstream assignee exists and assignments are different: called with remove_all=False
(21, False),
# - upstream assignee exists and assignments are different: called with remove_all=False
(22, False),
# - upstream assignee exists and assignments are different: called with remove_all=False
(23, False),
# - upstream assignee has a fullname of None: not called (already assigned to owner)
(24, None),
# - upstream assignee has login but fullname is None: called with remove_all=False
(24, False),
# - upstream assignee has login but no fullname key: called with remove_all=False
(25, False),
# - upstream assignee does not exist: not called (already assigned to owner)
(25, None),
# - upstream assignee is an empty list: not called (already assigned to owner)
(26, None),
# - upstream assignee is an empty list: not called (already assigned to owner)
(27, None),
# - downstream assignee does not exist
# - upstream assignee exists: called with remove_all=False
(31, False),
# - upstream assignee exists: called with remove_all=False
(32, False),
# - upstream assignee exists: called with remove_all=False
(33, False),
# - upstream assignee has a fullname of None: called with remove_all=False
# - upstream assignee has login but fullname is None: called with remove_all=False
(34, False),
# - upstream assignee does not exist: called with remove_all=False
# - upstream assignee has login but no fullname key: called with remove_all=False
(35, False),
# - upstream assignee is an empty list: called with remove_all=False
# - upstream assignee does not exist: called with remove_all=False
(36, False),
# - upstream assignee is an empty list: called with remove_all=False
(37, False),
# - overwrite = False
# - downstream assignee is set:
# - upstream assignee exists and assignments are equal: not called
Expand All @@ -1726,38 +1732,44 @@ def test_update_assignee_all(self, mock_client, mock_assign_user):
(42, None),
# - upstream assignee exists and assignments are different: not called
(43, None),
# - upstream assignee has a fullname of None: not called
# - upstream assignee has login but fullname is None: not called
(44, None),
# - upstream assignee does not exist: not called
# - upstream assignee has login but no fullname key: not called
(45, None),
# - upstream assignee is an empty list: not called
# - upstream assignee does not exist: not called
(46, None),
# - upstream assignee is an empty list: not called
(47, None),
# - downstream assignee is owner
# - upstream assignee exists and assignments are different: not called
(51, None),
# - upstream assignee exists and assignments are different: not called
(52, None),
# - upstream assignee exists and assignments are different: not called
(53, None),
# - upstream assignee has a fullname of None: not called
# - upstream assignee has login but fullname is None: not called
(54, None),
# - upstream assignee does not exist: not called
# - upstream assignee has login but no fullname key: not called
(55, None),
# - upstream assignee is an empty list: not called
# - upstream assignee does not exist: not called
(56, None),
# - upstream assignee is an empty list: not called
(57, None),
# - downstream assignee does not exist
# - upstream assignee exists: called with remove_all=False
(61, False),
# - upstream assignee exists: called with remove_all=False
(62, False),
# - upstream assignee exists: called with remove_all=False
(63, False),
# - upstream assignee has a fullname of None: called with remove_all=False
# - upstream assignee has login but fullname is None: called with remove_all=False
(64, False),
# - upstream assignee does not exist: called with remove_all=False
# - upstream assignee has login but no fullname key: called with remove_all=False
(65, False),
# - upstream assignee is an empty list: called with remove_all=False
# - upstream assignee does not exist: called with remove_all=False
(66, False),
# - upstream assignee is an empty list: called with remove_all=False
(67, False),
)
)
match = "Erik"
Expand All @@ -1772,10 +1784,11 @@ def test_update_assignee_all(self, mock_client, mock_assign_user):
setattr(self.mock_downstream.fields.assignee, "name", ds)

for us in (
[{"fullname": match}],
[{"fullname": "Èŕìḱ"}],
[{"fullname": "Bob"}],
[{"fullname": None}],
[{"login": "erik", "fullname": match}],
[{"login": "erik", "fullname": "Èŕìḱ"}],
[{"login": "bob", "fullname": "Bob"}],
[{"login": "anon", "fullname": None}],
[{"login": "jdoe"}],
None,
[],
):
Expand Down
Loading