Skip to content

Commit

Permalink
Fix #856 (#861)
Browse files Browse the repository at this point in the history
Fix #856

Related to #856

TODO:

 Write new tests or update the old ones to cover new functionality.
 Update doc-strings where appropriate.
 Update or write new documentation in packit/packit.dev.
 ‹fill in›



Fixes #856
Related to
Merge before/after

RELEASE NOTES BEGIN
We have fixed an issue that caused inconsistencies with the expected behavior stated by the documentation when adding duplicit reactions to GitLab comments.
RELEASE NOTES END

Reviewed-by: Matej Focko
  • Loading branch information
2 parents c890cde + 9815990 commit 0042934
Show file tree
Hide file tree
Showing 3 changed files with 1,281 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ogr/services/gitlab/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,22 @@ def add_reaction(self, reaction: str) -> GitlabReaction:
if "404 Award Emoji Name has already been taken" not in str(ex):
raise GitlabAPIException() from ex

# Take project from the parent (PR's don't have project)
login = (
getattr(self._parent, "_target_project", None) or self._parent.project
).service.user.get_username()

# this happens only when the reaction was already added
logger.info(f"The emoji {reaction} has already been taken.")
(reaction_obj,) = filter(
(
# we want to return that already given reaction
lambda item: item.attributes["name"] == reaction
and item.attributes["user"]["name"]
== item.awardemojis.gitlab.user.name
reaction_obj = next(
filter(
(
# we want to return that already given reaction
lambda item: item.attributes["name"] == reaction
and item.attributes["user"]["username"] == login
),
self._raw_comment.awardemojis.list(),
),
self._raw_comment.awardemojis.list(),
)

return GitlabReaction(reaction_obj)
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/gitlab/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,24 @@ def test_get_reactions(self):
issue_comment.add_reaction("-1")
issue_comment.add_reaction("tractor")
assert len(pr_comment.get_reactions()) == 3

def test_duplicit_reactions(self):
pr = self.service.get_project(
repo="hello-world",
namespace="packit-service",
).get_pr(1149)
pr_comment = pr.get_comments()[-1]

pr_reaction_1 = pr_comment.add_reaction("tractor")
pr_reaction_2 = pr_comment.add_reaction("tractor")
assert pr_reaction_1._raw_reaction.id == pr_reaction_2._raw_reaction.id

issue = self.service.get_project(
repo="hello-world",
namespace="packit-service",
).get_issue(12)
issue_comment = issue.get_comments()[-1]

issue_reaction_1 = issue_comment.add_reaction("tractor")
issue_reaction_2 = issue_comment.add_reaction("tractor")
assert issue_reaction_1._raw_reaction.id == issue_reaction_2._raw_reaction.id
Loading

0 comments on commit 0042934

Please sign in to comment.