Skip to content

Commit c6dbfda

Browse files
committed
Combine runs_on/permissions normalization in single validator
1 parent 39568ba commit c6dbfda

1 file changed

Lines changed: 7 additions & 23 deletions

File tree

src/openhound_github/models/workflow_job.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class WorkflowJob(BaseAsset):
153153
repository_name: str
154154
repository_node_id: str
155155
org_login: str
156-
runs_on: str | list[str] | dict[str, str] | None = None
156+
runs_on: list[str] | None = None
157157
is_self_hosted: bool = False
158158
container: str | None = None
159159
environment: str | None = None
@@ -163,41 +163,25 @@ class WorkflowJob(BaseAsset):
163163
secret_references: list[WorkflowReference] = Field(default_factory=list)
164164
variable_references: list[WorkflowReference] = Field(default_factory=list)
165165

166-
@property
167-
def normalize_runs_on(self) -> list[str] | None:
168-
if self.runs_on is None:
169-
return None
170-
171-
if isinstance(self.runs_on, str):
172-
return [self.runs_on]
173-
174-
if isinstance(self.runs_on, list):
175-
return self.runs_on
176-
177-
if isinstance(self.runs_on, dict):
178-
return [f"{key}:{value}" for key, value in self.runs_on.items()]
179-
180-
return [str(self.runs_on)]
181-
182166
@property
183167
def org_node_id(self) -> str | None:
184168
return self._lookup.org_id_for_login(self.org_login)
185169

186-
@field_validator("permissions", mode="before")
170+
@field_validator("runs_on", "permissions", mode="before")
187171
@classmethod
188-
def normalize_permissions(cls, value: Any) -> list[str] | None:
172+
def normalize_mapping(cls, value: Any) -> list[str] | None:
189173
if value is None:
190174
return None
191175

192-
if isinstance(value, dict):
193-
return [f"{key}:{permission}" for key, permission in value.items()]
194-
195176
if isinstance(value, str):
196177
return [value]
197178

198179
if isinstance(value, list):
199180
return [str(item) for item in value]
200181

182+
if isinstance(value, dict):
183+
return [f"{str(key)}:{str(value)}" for key, value in value.items()]
184+
201185
return [str(value)]
202186

203187
@property
@@ -209,7 +193,7 @@ def as_node(self) -> GHNode:
209193
displayname=self.job_key,
210194
node_id=self.node_id,
211195
job_key=self.job_key,
212-
runs_on=self.normalize_runs_on,
196+
runs_on=self.runs_on,
213197
is_self_hosted=self.is_self_hosted,
214198
container=self.container,
215199
environment=self.environment,

0 commit comments

Comments
 (0)