Skip to content

Commit

Permalink
feat: Pydantic 2.7.1 PR (#225)
Browse files Browse the repository at this point in the history
* Update poetry.lock

* Update pyproject.toml

* Update branch_protection.py

* Update file.py

* Update secret.py

* Update pyproject.toml

* Update poetry.lock

* Update branch_protection.py

* Update file.py

* Update branch_protection.py

* Update secret.py

* Update secret.py

* Update file.py

* Merge remote-tracking branch 'src/main' into feat/pydantic2.0

* Update test_file.py

* Update file.py

* Update test_file.py

* Update file.py

* Update test_file.py

* Update action-integration.yml

* Update pyproject.toml

* Update poetry.lock

* Update secret.py

* Update main.py
  • Loading branch information
shiro authored May 16, 2024
1 parent b0d70fb commit c1e014a
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/action-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Action Integration Test
on:
push:
pull_request:
pull_request_target:
jobs:
action-integration-testing:
name: Action Integration Testing
Expand All @@ -22,7 +22,7 @@ jobs:
# test with the local checkout of the action
uses: ./
with:
token: ${{ secrets.THIS_PAT }}
token: ${{ secrets.THIS_PAT || github.token }}
action: "check"
- name: Check outputs
run: |
Expand Down
153 changes: 111 additions & 42 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ repo-manager = "repo_manager.main:main"

[tool.poetry.dependencies]
python = "^3.11"
pydantic = "^1.10.9"
pydantic = "^2.7.1"
typing-extensions = "^4.7.1"
actions-toolkit = "^0.1.15"
pygithub = "^2.3.0"
pyyaml = "^6.0"
Expand All @@ -33,7 +34,7 @@ reorder-python-imports = "^3.12.0"
pytest-xdist = "^3.2.1"
pyupgrade = "^3.15.0"
pyflakes = "^3.1.0"
black = "^24.2.0"
black = "^24.4.1"


[build-system]
Expand Down
3 changes: 2 additions & 1 deletion repo_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def main(): # noqa: C901
if to_check is not None:
this_check, this_diffs = check(inputs["repo_object"], to_check)
check_result &= this_check
diffs[check_name] = this_diffs
if this_diffs is not None:
diffs[check_name] = this_diffs

actions_toolkit.debug(json_diff := json.dumps({}))
actions_toolkit.set_output("diff", json_diff)
Expand Down
4 changes: 2 additions & 2 deletions repo_manager/schemas/branch_protection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pydantic import BaseModel # pylint: disable=E0611
from pydantic import conint
from typing import Annotated
from pydantic import Field

OptBool = bool | None
Expand Down Expand Up @@ -32,7 +32,7 @@ class DismissalOptions(BaseModel):


class PROptions(BaseModel):
required_approving_review_count: conint(ge=1, le=6) | None = Field(
required_approving_review_count: Annotated[int, Field(strict=True, gt=1, le=6)] | None = Field(
None, description="The number of approvals required. (1-6)"
)
dismiss_stale_reviews: OptBool = Field(
Expand Down
19 changes: 11 additions & 8 deletions repo_manager/schemas/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from pathlib import Path
from typing import Optional

from pydantic import BaseModel # pylint: disable=E0611
from pydantic import Field
from pydantic import validator
from pydantic import (
BaseModel, # pylint: disable=E0611
Field,
ValidationInfo,
field_validator,
)

OptBool = Optional[bool]
OptStr = Optional[str]
Expand Down Expand Up @@ -38,17 +41,17 @@ class FileConfig(BaseModel):
+ "means to lookup the default branch of the repo",
)

@validator("src_file", pre=True)
def validate_src_file(cls, v, values) -> Path:
if v is None and values["exists"]:
@field_validator("src_file", mode="before")
def validate_src_file(cls, v, info: ValidationInfo) -> Path:
if v is None and info.data["exists"]:
raise ValueError("Missing src_file")
v = str(v)
if v.startswith("remote:"):
values["remote_src"] = True
info.data["remote_src"] = True
v = v.replace("remote://", "")
return Path(v)

@validator("dest_file")
@field_validator("dest_file")
def validate_dest_file(cls, v) -> Path:
if v is None:
raise ValueError("Missing dest_file")
Expand Down
30 changes: 15 additions & 15 deletions repo_manager/schemas/secret.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
from typing import Optional

from pydantic import BaseModel # pylint: disable=E0611
from pydantic import Field
from pydantic import validator
from pydantic import (
BaseModel, # pylint: disable=E0611
Field,
ValidationInfo,
field_validator,
)

OptBool = Optional[bool]
OptStr = Optional[str]
Expand All @@ -13,28 +16,25 @@ class SecretEnvError(Exception): ...


class Secret(BaseModel):
type: OptStr = Field(None, description="Type of secret, can be `dependabot` or `actions`")
key: OptStr = Field(None, description="Secret's name.")
type: str = Field(
"actions",
description="Type of secret, can be `dependabot` or `actions` or an `environment` path",
)
key: str = Field(None, description="Secret's name.")
env: OptStr = Field(None, description="Environment variable to pull the secret from")
value: OptStr = Field(None, description="Value to set this secret to")
value: OptStr = Field(None, description="Value to set this secret to", validate_default=True)
required: OptBool = Field(
True,
description="Setting a value as not required allows you to not pass in an env var without causing an error",
)
exists: OptBool = Field(True, description="Set to false to delete a secret")

@validator("type")
def validate_type(cls, v):
if v not in ["dependabot", "actions"]:
raise ValueError("Secret type must be either `dependabot` or `actions`")
return v

@validator("value", always=True)
def validate_value(cls, v, values) -> OptStr:
@field_validator("value")
def validate_value(cls, v, info: ValidationInfo) -> OptStr:
if v is None:
return None

if values["env"] is not None:
if info.data["env"] is not None:
raise ValueError("Cannot set an env and a value in the same secret, remove one.")

return v
Expand Down

0 comments on commit c1e014a

Please sign in to comment.