Skip to content

Commit

Permalink
Use only gitlab ReferenceTag instead of UserList (#27976)
Browse files Browse the repository at this point in the history
  • Loading branch information
CelianR authored Jul 29, 2024
1 parent 77bf04b commit bb91f82
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tasks/libs/ciproviders/gitlab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit bb91f82

Please sign in to comment.