Skip to content

Commit

Permalink
🐛 fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Nov 30, 2023
1 parent 1bdbd3e commit 4b8ae6e
Show file tree
Hide file tree
Showing 30 changed files with 172 additions and 132 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
rev: v0.1.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand All @@ -20,13 +20,13 @@ repos:
stages: [commit]

- repo: https://github.com/psf/black
rev: 23.10.1
rev: 23.11.0
hooks:
- id: black
stages: [commit]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v3.1.0
hooks:
- id: prettier
types_or: [javascript, jsx, ts, tsx, markdown, yaml]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ uvicorn = ">=0.18.3,<1.0.0"

[tool.black]
preview = true
target-version = ["py311", "py312"]
line-length = 88
extend-exclude = '''
'''
Expand All @@ -54,7 +55,7 @@ select = ["E", "W", "F", "UP", "C", "T", "PYI", "PT", "Q"]
ignore = ["E402", "C901", "UP037"]

line-length = 88
target-version = "py38"
target-version = "py311"

[tool.ruff.extend-per-file-ignores]
"./scripts/*" = ["T201"]
Expand Down
5 changes: 2 additions & 3 deletions scripts/html_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys
import asyncio
from pathlib import Path
from typing import Optional
from argparse import ArgumentParser

from nonebot import logger, get_adapter
Expand All @@ -24,7 +23,7 @@


async def gen_issue_html(
issue: str, comment: Optional[int] = None, output_file: Optional[str] = None
issue: str, comment: int | None = None, output_file: str | None = None
):
m = re.match(rf"^{FULLREPO_REGEX}#{ISSUE_REGEX}$", issue)
if not m:
Expand Down Expand Up @@ -52,7 +51,7 @@ async def gen_issue_html(
issue.add_argument("-o", "--output-file", required=False, help="output file path")


async def gen_diff_html(pr: str, output_file: Optional[str] = None):
async def gen_diff_html(pr: str, output_file: str | None = None):
m = re.match(rf"^{FULLREPO_REGEX}#{ISSUE_REGEX}$", pr)
if not m:
print("Invalid pr format, should be: <owner>/<repo>#<issue>")
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2020-09-20 23:59:20
@LastEditors : yanyongyu
@LastEditTime : 2023-10-08 14:06:14
@LastEditTime : 2023-11-29 14:27:38
@Description : GitHub Main Plugin
@GitHub : https://github.com/yanyongyu
"""
Expand All @@ -27,3 +27,5 @@
_webhook_plugins |= nonebot.load_plugins(
str((Path(__file__).parent / "webhooks").resolve())
)

from . import apis as apis
4 changes: 3 additions & 1 deletion src/plugins/github/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2021-03-15 20:18:12
@LastEditors : yanyongyu
@LastEditTime : 2023-03-30 20:42:10
@LastEditTime : 2023-11-29 14:27:01
@Description : External APIs for github plugin
@GitHub : https://github.com/yanyongyu
"""
Expand All @@ -19,3 +19,5 @@
loader=jinja2.FileSystemLoader(Path(__file__).parent / "templates"),
enable_async=True,
)

from . import auth as auth
4 changes: 2 additions & 2 deletions src/plugins/github/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__author__ = "yanyongyu"

from typing import Any, Dict, Literal
from typing import Any, Literal

from nonebot.adapters.github.config import OAuthApp, GitHubApp
from pydantic import Extra, BaseModel, validator, parse_obj_as, root_validator
Expand All @@ -30,7 +30,7 @@ class Config(BaseModel, extra=Extra.ignore):
github_command_priority: int = 50

@root_validator(pre=True)
def validate_app(cls, values: Dict[str, Any]) -> Dict[str, Any]:
def validate_app(cls, values: dict[str, Any]) -> dict[str, Any]:
"""Auto get app from github adapter config"""

if not (apps := values.get("github_apps")):
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/github/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2023-10-07 17:18:14
@LastEditors : yanyongyu
@LastEditTime : 2023-10-07 17:18:14
@LastEditTime : 2023-11-30 12:11:39
@Description : None
@GitHub : https://github.com/yanyongyu
"""
Expand All @@ -11,7 +11,8 @@

from functools import wraps
from types import TracebackType
from typing import Any, Generic, TypeVar, Callable, ParamSpec, AsyncGenerator
from typing import Any, Generic, TypeVar, ParamSpec
from collections.abc import Callable, AsyncGenerator

P = ParamSpec("P")
R = TypeVar("R", covariant=True)
Expand All @@ -22,7 +23,7 @@ def __init__(
__self,
__func: Callable[P, AsyncGenerator[R, Any]],
*args: P.args,
**kwargs: P.kwargs
**kwargs: P.kwargs,
):
__self.func = __func
__self.args = args
Expand Down Expand Up @@ -68,7 +69,7 @@ async def __aexit__(
if exc is exc_value:
return False
if (
isinstance(exc_value, (StopIteration, StopAsyncIteration))
isinstance(exc_value, StopIteration | StopAsyncIteration)
and exc.__cause__ is exc_value
):
return False
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/github/dependencies/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
@Author : yanyongyu
@Date : 2023-10-07 17:11:56
@LastEditors : yanyongyu
@LastEditTime : 2023-10-07 17:13:38
@LastEditTime : 2023-11-29 16:15:24
@Description : None
@GitHub : https://github.com/yanyongyu
"""

__author__ = "yanyongyu"

from typing import Any

from nonebot.typing import T_State
from nonebot.params import Depends, RegexDict


async def store_regex_vars(state: T_State, group: dict[str, str] = RegexDict()):
async def store_regex_vars(state: T_State, group: dict[str, Any] = RegexDict()):
state.update(group)


Expand Down
3 changes: 2 additions & 1 deletion src/plugins/github/dependencies/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

__author__ = "yanyongyu"

from typing import Annotated
from contextlib import nullcontext
from typing import Annotated, AsyncGenerator
from collections.abc import AsyncGenerator

from nonebot import logger
from nonebot.params import Depends
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/github/dependencies/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2023-10-08 14:02:23
@LastEditors : yanyongyu
@LastEditTime : 2023-11-27 15:35:46
@LastEditTime : 2023-11-30 12:13:04
@Description : None
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -69,7 +69,7 @@ async def get_issue_or_pr_reply_tag(
Finish the session if the tag do not exists or is not issue or pull request tag.
"""
if not tag or not isinstance(tag, (IssueTag, PullRequestTag)):
if not tag or not isinstance(tag, IssueTag | PullRequestTag):
await matcher.finish()
return tag

Expand Down Expand Up @@ -105,7 +105,7 @@ async def store_tag_data(state: T_State, tag: OPTIONAL_REPLY_TAG) -> None:
state["owner"] = tag.owner
state["repo"] = tag.repo

if isinstance(tag, (IssueTag, PullRequestTag)):
if isinstance(tag, IssueTag | PullRequestTag):
state["issue"] = tag.number


Expand Down
4 changes: 2 additions & 2 deletions src/plugins/github/helpers/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2022-10-27 04:24:58
@LastEditors : yanyongyu
@LastEditTime : 2023-11-13 17:35:14
@LastEditTime : 2023-11-30 12:13:11
@Description : Rule helpers
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -57,7 +57,7 @@ async def reply_any(reply_tag: OPTIONAL_REPLY_TAG) -> bool:


async def reply_issue_or_pr(reply_tag: OPTIONAL_REPLY_TAG) -> bool:
return isinstance(reply_tag, (IssueTag, PullRequestTag))
return isinstance(reply_tag, IssueTag | PullRequestTag)


REPLY_ISSUE_OR_PR = Rule(reply_issue_or_pr)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/github/libs/renderer/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__author__ = "yanyongyu"

from typing import Generator
from collections.abc import Generator
from contextlib import contextmanager
from contextvars import Token, ContextVar

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/github/libs/renderer/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__author__ = "yanyongyu"

from datetime import datetime, timezone
from datetime import UTC, datetime

import humanize
from nonebot import logger
Expand Down Expand Up @@ -75,7 +75,7 @@ def relative_time(value: datetime | str) -> str:
if isinstance(value, str):
value = datetime.strptime(value, "%Y-%m-%dT%H:%M:%SZ")
if not value.tzinfo:
value = value.replace(tzinfo=timezone.utc)
value = value.replace(tzinfo=UTC)
now = datetime.now(value.tzinfo)
delta = now - value
if delta.microseconds > 0 and delta.days < 30:
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/github/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2022-09-06 07:31:43
@LastEditors : yanyongyu
@LastEditTime : 2023-11-25 19:36:03
@LastEditTime : 2023-11-29 15:04:01
@Description : Group model
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -51,14 +51,18 @@ async def create_or_update_by_info(

info = cast(GroupInfo, info)

insert_sql = insert(cls).values(user=info.dict(), bind_repo=bind_repo)
insert_sql = insert(cls).values(group=info.dict(), bind_repo=bind_repo)
update_sql = insert_sql.on_conflict_do_update(
set_={"bind_repo": insert_sql.excluded.bind_repo}
index_elements=[cls.group],
set_={"bind_repo": insert_sql.excluded.bind_repo},
).returning(cls)

async with get_session() as session:
result = await session.execute(update_sql)
return result.scalar_one()
group = result.scalar_one()
await session.commit()
await session.refresh(group)
return group

async def unbind(self) -> None:
"""Unbind group and repo"""
Expand Down
Loading

0 comments on commit 4b8ae6e

Please sign in to comment.