Skip to content

Commit

Permalink
Fix the edge-case in GitLab award emojis
Browse files Browse the repository at this point in the history
Fixes #856
  • Loading branch information
kapr200 committed Sep 27, 2024
1 parent 92b7055 commit 7eafa52
Showing 1 changed file with 13 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

0 comments on commit 7eafa52

Please sign in to comment.