Skip to content

Commit

Permalink
Merge pull request #34 from con/updates
Browse files Browse the repository at this point in the history
Update for Pydantic 2.0 and Pygithub 2.0
  • Loading branch information
yarikoptic authored Nov 20, 2023
2 parents b8ad616 + 4223b31 commit 9c93332
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
5 changes: 2 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ python_requires = >= 3.10
install_requires =
click >= 8.0
click-loglevel ~= 0.2
pydantic ~= 1.7
PyGithub ~= 1.55
pydantic ~= 2.0
PyGithub ~= 2.0
ruamel.yaml ~= 0.15

[options.packages.find]
Expand Down Expand Up @@ -67,4 +67,3 @@ plugins = pydantic.mypy

[pydantic-mypy]
init_forbid_extra = True
warn_untypes_fields = True
29 changes: 14 additions & 15 deletions src/solidation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@
import os
from pathlib import Path
from random import sample
from re import Pattern
import re
from statistics import quantiles
from typing import TYPE_CHECKING, Any
from typing import Annotated, Any
from urllib.parse import quote
import click
from click_loglevel import LogLevel
from github import Github
from github import Auth, Github
from github.Issue import Issue
from github.PullRequest import PullRequest
from github.Repository import Repository
from pydantic import BaseModel, Field, StrictBool, constr
from pydantic import BaseModel, Field, StrictBool, StringConstraints
from ruamel.yaml import YAML
from . import __version__

log = logging.getLogger("solidation")

if TYPE_CHECKING:
GHUser = str
GHRepo = str
else:
GHUser = constr(regex=r"^[-_A-Za-z0-9]+$")
GHRepo = constr(regex=r"^[-_A-Za-z0-9]+/[-_.A-Za-z0-9]+$")
GHUser = Annotated[str, StringConstraints(pattern=r"^[-_A-Za-z0-9]+$")]
GHRepo = Annotated[str, StringConstraints(pattern=r"^[-_A-Za-z0-9]+/[-_.A-Za-z0-9]+$")]


class RepoSpec(BaseModel):
Expand All @@ -38,7 +34,7 @@ class RepoSpec(BaseModel):

class OrgSpec(BaseModel):
name: GHUser
fetch_members: StrictBool | Pattern = False
fetch_members: StrictBool | re.Pattern[str] = False
member_activity_only: bool = False

def member_fetched(self, user: str) -> bool:
Expand Down Expand Up @@ -80,7 +76,7 @@ class Consolidator:
since: datetime = field(init=False)

def __post_init__(self, token: str) -> None:
self.gh = Github(token)
self.gh = Github(auth=Auth.Token(token))
self.since = datetime.now(timezone.utc) - timedelta(
days=self.config.recent_days
)
Expand Down Expand Up @@ -339,7 +335,7 @@ def to_markdown(self) -> str:
f" {len(recent_closed_prs)}\n"
)

merged_prs = [i for i in recent_closed_prs if i.merged_at]
merged_prs = [i for i in recent_closed_prs if i.merged_at is not None]
if merged_prs:
for label, attr in (("Proposed", "user"), ("Merged", "merged_by")):
s += (
Expand All @@ -350,7 +346,10 @@ def to_markdown(self) -> str:
)
+ "\n"
)
pr_durations = [(i.merged_at - i.created_at).days for i in merged_prs]
pr_durations = []
for pr in merged_prs:
assert pr.merged_at is not None
pr_durations.append((pr.merged_at - pr.created_at).days)
if len(pr_durations) > 1:
s += f"- PR duration quantiles (days): {quantiles(pr_durations)}\n"

Expand Down Expand Up @@ -451,7 +450,7 @@ def main(config: Path, log_level: int) -> None:
)
log.info("solidation %s", __version__)
with config.open() as fp:
cfg = Configuration.parse_obj(YAML(typ="safe").load(fp))
cfg = Configuration.model_validate(YAML(typ="safe").load(fp))
cs = Consolidator(token=os.environ["GITHUB_TOKEN"], config=cfg)
report = cs.run()
print(report.to_markdown(), end="")
Expand Down

0 comments on commit 9c93332

Please sign in to comment.