Skip to content

Commit 31e0fa0

Browse files
committed
fix: bug on push events
1 parent 2d95cbc commit 31e0fa0

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/python_security_auditing/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from typing import Literal
66

7+
from pydantic import field_validator
78
from pydantic_settings import BaseSettings, SettingsConfigDict
89

910

@@ -36,6 +37,14 @@ class Settings(BaseSettings):
3637
github_run_id: str = ""
3738
pr_number: int | None = None
3839
github_event_name: str = ""
40+
41+
@field_validator("pr_number", mode="before")
42+
@classmethod
43+
def _empty_str_to_none(cls, v: object) -> object:
44+
if v == "":
45+
return None
46+
return v
47+
3948
github_head_ref: str = "" # Branch name for PRs
4049
github_step_summary: str = "" # Path to step summary file
4150

tests/test_settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def test_pr_number_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
6868
assert s.pr_number == 42
6969

7070

71+
def test_pr_number_empty_string(monkeypatch: pytest.MonkeyPatch) -> None:
72+
monkeypatch.setenv("PR_NUMBER", "")
73+
s = Settings()
74+
assert s.pr_number is None
75+
76+
7177
def test_post_pr_comment_false(monkeypatch: pytest.MonkeyPatch) -> None:
7278
monkeypatch.setenv("POST_PR_COMMENT", "false")
7379
s = Settings()

0 commit comments

Comments
 (0)