Skip to content

Commit 252c43a

Browse files
fix: pydantic 2 fixes (#237)
* fix: pydantic 2 fixes * fix: poetry lock and model_validate * fix: rename github to gh * fix: cat out action.yml * fix: fix ci * fix: action integration test on PR and push to main
1 parent c1e014a commit 252c43a

15 files changed

+117
-88
lines changed

.github/workflows/action-integration.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
name: Action Integration Test
33
on:
44
push:
5-
pull_request_target:
5+
branches:
6+
- main
7+
pull_request:
68
jobs:
79
action-integration-testing:
810
name: Action Integration Testing
@@ -17,6 +19,8 @@ jobs:
1719
with:
1820
infile: action.yml
1921
varlist: "runs.image=Dockerfile"
22+
- name: cat action.yml
23+
run: cat action.yml
2024
- name: Test action
2125
id: test-action
2226
# test with the local checkout of the action

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: trailing-whitespace
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
1111
# Ruff version.
12-
rev: v0.4.3
12+
rev: v0.4.4
1313
hooks:
1414
# Run the linter.
1515
- id: ruff
@@ -21,7 +21,7 @@ repos:
2121
hooks:
2222
- id: prettier
2323
- repo: https://github.com/rhysd/actionlint
24-
rev: v1.6.27
24+
rev: v1.7.0
2525
hooks:
2626
- id: actionlint-docker
2727
name: Actionlint

poetry.lock

+49-49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

repo_manager/gh/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from functools import lru_cache
2+
3+
from github import Github
4+
from github.GithubException import GithubException
5+
from github.GithubException import UnknownObjectException
6+
7+
8+
@lru_cache
9+
def get_github_client(token: str, api_url: str) -> Github:
10+
""" """
11+
return Github(token, base_url=api_url)
12+
13+
14+
__all__ = ["get_github_client", "GithubException", "UnknownObjectException"]
File renamed without changes.
File renamed without changes.

repo_manager/github/repos.py repo_manager/gh/repos.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from github import Github
1+
from gh import Github
22
from github.Repository import Repository
33

44

File renamed without changes.
File renamed without changes.

repo_manager/github/__init__.py

-9
This file was deleted.

repo_manager/main.py

+30-17
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,43 @@
22
import sys
33

44
from actions_toolkit import core as actions_toolkit
5-
from github.GithubException import GithubException
6-
from github.GithubException import UnknownObjectException
75

8-
from repo_manager.github.branch_protections import check_repo_branch_protections
9-
from repo_manager.github.branch_protections import update_branch_protection
10-
from repo_manager.github.files import copy_file
11-
from repo_manager.github.files import delete_file
12-
from repo_manager.github.files import move_file
13-
from repo_manager.github.files import RemoteSrcNotFoundError
14-
from repo_manager.github.labels import check_repo_labels
15-
from repo_manager.github.labels import update_label
16-
from repo_manager.github.secrets import check_repo_secrets
17-
from repo_manager.github.secrets import create_secret
18-
from repo_manager.github.secrets import delete_secret
19-
from repo_manager.github.settings import check_repo_settings
20-
from repo_manager.github.settings import update_settings
6+
from repo_manager.gh.branch_protections import check_repo_branch_protections
7+
from repo_manager.gh.branch_protections import update_branch_protection
8+
from repo_manager.gh.files import copy_file
9+
from repo_manager.gh.files import delete_file
10+
from repo_manager.gh.files import move_file
11+
from repo_manager.gh.files import RemoteSrcNotFoundError
12+
from repo_manager.gh.labels import check_repo_labels
13+
from repo_manager.gh.labels import update_label
14+
from repo_manager.gh.secrets import check_repo_secrets
15+
from repo_manager.gh.secrets import create_secret
16+
from repo_manager.gh.secrets import delete_secret
17+
from repo_manager.gh.settings import check_repo_settings
18+
from repo_manager.gh.settings import update_settings
2119
from repo_manager.schemas import load_config
2220
from repo_manager.utils import get_inputs
21+
from yaml import YAMLError
22+
from pydantic import ValidationError
23+
from repo_manager.gh import GithubException, UnknownObjectException
2324

2425

2526
def main(): # noqa: C901
26-
inputs = get_inputs()
27+
try:
28+
inputs = get_inputs()
29+
# actions toolkit has very broad exceptions :(
30+
except Exception as exc:
31+
actions_toolkit.set_failed(f"Unable to collect inputs {exc}")
2732
actions_toolkit.debug(f"Loading config from {inputs['settings_file']}")
28-
config = load_config(inputs["settings_file"])
33+
try:
34+
config = load_config(inputs["settings_file"])
35+
except FileNotFoundError:
36+
actions_toolkit.set_failed(f"{inputs['settings_file']} does not exist or is not readable")
37+
except YAMLError as exc:
38+
actions_toolkit.set_failed(f"Unable to read {inputs['settings_file']} - {exc}")
39+
except ValidationError as exc:
40+
actions_toolkit.set_failed(f"{inputs['settings_file']} is invalid - {exc}")
41+
2942
actions_toolkit.debug(f"Inputs: {inputs}")
3043
if inputs["action"] == "validate":
3144
actions_toolkit.set_output("result", f"Validated {inputs['settings_file']}")

repo_manager/schemas/__init__.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@
66
from .label import Label
77
from .secret import Secret
88
from .settings import Settings
9+
from pydantic import Field
10+
from copy import copy
11+
12+
13+
def empty_list():
14+
this_list = list()
15+
return copy(this_list)
916

1017

1118
class RepoManagerConfig(BaseModel):
1219
settings: Settings | None
13-
branch_protections: list[BranchProtection] | None
14-
secrets: list[Secret] | None
15-
labels: list[Label] | None
16-
files: list[FileConfig] | None
20+
branch_protections: list[BranchProtection] = Field(default_factory=empty_list)
21+
secrets: list[Secret] = Field(default_factory=empty_list)
22+
labels: list[Label] = Field(default_factory=empty_list)
23+
files: list[FileConfig] = Field(default_factory=empty_list)
1724

1825
@property
1926
def secrets_dict(self):
@@ -37,4 +44,4 @@ def load_config(filename: str) -> RepoManagerConfig:
3744
with open(filename) as fh:
3845
this_dict = yaml.safe_load(fh)
3946

40-
return RepoManagerConfig(**this_dict)
47+
return RepoManagerConfig.model_validate(this_dict)

repo_manager/utils/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Needed to handle extracting certain attributes/fields from nested objects and lists
77
from itertools import repeat
88

9-
from repo_manager.github import get_github_client
9+
from repo_manager.gh import get_github_client
1010

1111
from ._inputs import INPUTS
1212

tests/unit/github/test_files.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pytest
22
from github.GithubException import UnknownObjectException
33

4-
from repo_manager.github import files
5-
from repo_manager.github.files import copy_file
6-
from repo_manager.github.files import RemoteSrcNotFoundError
4+
from repo_manager.gh import files
5+
from repo_manager.gh.files import copy_file
6+
from repo_manager.gh.files import RemoteSrcNotFoundError
77
from repo_manager.schemas import FileConfig
88

99
VALID_CONFIG = {

0 commit comments

Comments
 (0)