From bb91f824334947fcd86e999a2625dcc54244d33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9lian=20Raimbault?= <161456554+CelianR@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:50:47 +0200 Subject: [PATCH] Use only gitlab ReferenceTag instead of UserList (#27976) --- tasks/libs/ciproviders/gitlab_api.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tasks/libs/ciproviders/gitlab_api.py b/tasks/libs/ciproviders/gitlab_api.py index 5b98e72369526..a10614efd0bb5 100644 --- a/tasks/libs/ciproviders/gitlab_api.py +++ b/tasks/libs/ciproviders/gitlab_api.py @@ -6,7 +6,6 @@ import re import subprocess import sys -from collections import UserList from copy import deepcopy from dataclasses import dataclass from difflib import Differ @@ -439,18 +438,24 @@ class ReferenceTag(yaml.YAMLObject): def __init__(self, references): self.references = references + def __iter__(self): + return iter(self.references) + + def __str__(self): + return f'{self.yaml_tag} {self.references}' + @classmethod def from_yaml(cls, loader, node): - return UserList(loader.construct_sequence(node)) + return ReferenceTag(loader.construct_sequence(node)) @classmethod - def to_yaml(cls, dumper, data): - return dumper.represent_sequence(cls.yaml_tag, data.data, flow_style=True) + def to_yaml(cls, dumper, data: ReferenceTag): + return dumper.represent_sequence(cls.yaml_tag, data.references, flow_style=True) # Update loader/dumper to handle !reference tag yaml.SafeLoader.add_constructor(ReferenceTag.yaml_tag, ReferenceTag.from_yaml) -yaml.SafeDumper.add_representer(UserList, ReferenceTag.to_yaml) +yaml.SafeDumper.add_representer(ReferenceTag, ReferenceTag.to_yaml) # HACK: The following line is a workaround to prevent yaml dumper from removing quote around comma separated numbers, otherwise Gitlab Lint API will remove the commas yaml.SafeDumper.add_implicit_resolver(