Skip to content

Commit 5bcc84c

Browse files
committed
Also normalize the secrets map when loading the model
1 parent 83acaca commit 5bcc84c

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/openhound_github/models/workflow.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,30 @@ class WorkflowJobDefinition(BaseModel):
101101
uses: str | None = None
102102
container: str | Container | None = None
103103
env: dict[str, str] = Field(default_factory=dict)
104-
secrets: dict[str, str] | str | None = None
104+
secrets: dict[str, str] = Field(default_factory=dict)
105105
steps: list[WorkflowStepDefinition] = Field(default_factory=list)
106106

107+
# This may seem strange, but the GitHub yaml format accepts empty values for keys
108+
# additionally, to prevent other yaml parsing issues, make sure we always convert the key/value to string first
109+
# for both env and secrets
110+
107111
@field_validator("env", mode="before")
108112
@classmethod
109-
def dict_or_empty(cls, value: Any) -> dict[str, Any]:
110-
return value if isinstance(value, dict) else {}
113+
def dict_or_empty(cls, value: Any) -> dict[str, str]:
114+
return (
115+
{f"{str(key)}": f"{str(value)}" for key, value in value.items()}
116+
if isinstance(value, dict)
117+
else {}
118+
)
119+
120+
@field_validator("secrets", mode="before")
121+
@classmethod
122+
def secrets_or_empty(cls, value: Any) -> dict[str, str]:
123+
return (
124+
{f"{str(key)}": f"{str(value)}" for key, value in value.items()}
125+
if isinstance(value, dict)
126+
else {}
127+
)
111128

112129
@field_validator("steps", mode="before")
113130
@classmethod
@@ -498,10 +515,9 @@ def workflow_job_rows(self) -> list[dict[str, Any]]:
498515
for job_key, job in document.jobs.items():
499516
secret_refs = []
500517
variable_refs = []
501-
if isinstance(job.secrets, dict):
502-
secret_refs.extend(
503-
mapping_references(SECRET_REFERENCE_RE, job.secrets, "secrets")
504-
)
518+
secret_refs.extend(
519+
mapping_references(SECRET_REFERENCE_RE, job.secrets, "secrets")
520+
)
505521
secret_refs.extend(mapping_references(SECRET_REFERENCE_RE, job.env, "env"))
506522
variable_refs.extend(
507523
mapping_references(VARIABLE_REFERENCE_RE, job.env, "env")

0 commit comments

Comments
 (0)