Skip to content

Commit c1f0191

Browse files
Fix MRTarget equality to compare branch values (#3175)
Fix MRTarget equality to compare branch values As described in #3173 MRTarget.__eq__() compared self.branch with itself instead of comparing it with other.branch, causing targets with the same repository but different branches to compare as equal. Correct the comparison and add a regression test verifying that gitlab_mr_targets_handled membership respects the configured branch. This ensures GitLab MR target matching does not incorrectly treat different branch patterns as the same target. The MRTarget.__eq__() issue being corrected here has been present since the original implementation was introduced in 2021. It was noticed during a review of the code rather than as the result of a reported bug or observed production failure. This correction aligns MRTarget equality with the behavior described by the original commit message: both the repository and branch are part of the target definition. No specific production issue or crash has been attributed to this issue. Reviewed-by: Alžběta Kučerová
2 parents 72e0156 + 96c04fb commit c1f0191

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

packit_service/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __eq__(self, other: object) -> bool:
9090
if not isinstance(other, MRTarget):
9191
raise NotImplementedError()
9292

93-
return self.repo == other.repo and self.branch == self.branch
93+
return self.repo == other.repo and self.branch == other.branch
9494

9595

9696
class ServiceConfig(Config):

tests/unit/test_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ def test_parse_valid(service_config_valid):
8383
assert config.package_config_path_override is None
8484

8585

86+
def test_mr_target_membership_respects_branch(service_config_valid):
87+
config = ServiceConfig.get_from_dict(service_config_valid)
88+
assert MRTarget("redhat/centos-stream/src/.+", "c9s") in config.gitlab_mr_targets_handled
89+
assert (
90+
MRTarget("redhat/centos-stream/src/.+", "rawhide") not in config.gitlab_mr_targets_handled
91+
)
92+
93+
8694
def test_parse_optional_values(service_config_valid):
8795
"""When optional values are set, they are correctly parsed"""
8896
config = ServiceConfig.get_from_dict(

0 commit comments

Comments
 (0)