Skip to content

Commit

Permalink
👷 添加ruff actions
Browse files Browse the repository at this point in the history
🐛 分支应该是main而不是master

💄 auto fix by pre-commit hooks

🔥 dependabot.yml的registrys需要token,先删除
  • Loading branch information
AzideCupric authored and felinae98 committed Jul 18, 2023
1 parent 7d4eb77 commit e50eb5d
Show file tree
Hide file tree
Showing 66 changed files with 69,031 additions and 7,944 deletions.
14 changes: 7 additions & 7 deletions .circleci/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ workflows:
ignore: /.*/
tags:
only: /^v.*/
context:
context:
- docker
image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME
cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_TAG}'
cache_from: "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_TAG}"
tag: latest,${CIRCLE_TAG}
update-description: true
docker-username: DOCKERHUB_USERNAME
Expand All @@ -91,13 +91,13 @@ workflows:
tags:
ignore: /.*/
tag: ${CIRCLE_BRANCH//\//-}
cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}'
cache_from: "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}"
- docker/publish:
<<: *docker-push
dockerfile: docker/Dockerfile_with_frontend_sentry
name: "docker/publish-sentry"
tag: sentry,${CIRCLE_TAG//\//-}-sentry
cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:sentry'
cache_from: "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:sentry"
- docker/publish:
<<: *docker-push
name: "docker/publish-debug-sentry"
Expand All @@ -108,7 +108,7 @@ workflows:
tags:
ignore: /.*/
tag: ${CIRCLE_BRANCH//\//-}-sentry
cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}-sentry'
cache_from: "$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}-sentry"

jobs:
build-frontend:
Expand Down Expand Up @@ -164,7 +164,8 @@ jobs:
# command: poetry run playwright install-deps && poetry run playwright install chromium
- run:
name: Coverage test
command: poetry run pytest --cov-report html --cov-report xml --cov=./src/plugins/nonebot_bison --junitxml=test-results/junit.xml
command:
poetry run pytest --cov-report html --cov-report xml --cov=./src/plugins/nonebot_bison --junitxml=test-results/junit.xml
-k 'not compare and not render'
- store_test_results:
path: test-results
Expand Down Expand Up @@ -215,4 +216,3 @@ jobs:
go install github.com/tcnksm/ghr@latest
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} \
-delete ${CIRCLE_TAG} -n ${CIRCLE_TAG} -b $(git log --format=%B -n 1 $CIRCLE_SHA1) ./dist
104 changes: 52 additions & 52 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
{
"name": "Default Linux Universal",
"image": "mcr.microsoft.com/devcontainers/universal:2-linux",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
},
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install -E all && poetry run pre-commit install && yarn install",
"customizations": {
"vscode": {
"settings": {
"python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "basic",
"ruff.organizeImports": false,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.fixAll.ruff": true,
"source.organizeImports": true
}
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.exclude": {
"**/__pycache__": true
},
"files.watcherExclude": {
"**/target/**": true,
"**/__pycache__": true
"name": "Default Linux Universal",
"image": "mcr.microsoft.com/devcontainers/universal:2-linux",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
},
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install -E all && poetry run pre-commit install && yarn install",
"customizations": {
"vscode": {
"settings": {
"python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "basic",
"ruff.organizeImports": false,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.fixAll.ruff": true,
"source.organizeImports": true
}
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.black-formatter",
"charliermarsh.ruff",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss"
]
}
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.exclude": {
"**/__pycache__": true
},
"files.watcherExclude": {
"**/target/**": true,
"**/__pycache__": true
}
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.black-formatter",
"charliermarsh.ruff",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss"
]
}
}
}
}
1 change: 0 additions & 1 deletion .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ runs:
uses: Gr1N/setup-poetry@v8
with:
poetry-version: "1.3.2"

2 changes: 1 addition & 1 deletion .github/actions/test-docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
wait-time:
description: how many seconds to wait for
required: true
default: '5'
default: "5"

runs:
using: composite
Expand Down
9 changes: 4 additions & 5 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
registries:
npm-npmjs:
type: npm-registry
url: "https://registry.npmmirror.com"
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
Expand All @@ -21,4 +17,7 @@ updates:
directory: "/admin-frontend/"
schedule:
interval: "weekly"

- package-ecosystem: github-actions
directory: "/"
schedule:
interval: weekly
4 changes: 2 additions & 2 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
cancel-in-progress: true
steps:
- uses: actions/checkout@v3

- uses: release-drafter/release-drafter@v5
id: release-drafter
env:
Expand All @@ -26,7 +26,7 @@ jobs:
uses: docker://ghcr.io/nonebot/auto-changelog:master
with:
latest_changes_position: '# Change Log\n\n'
latest_changes_title: '## 最近更新'
latest_changes_title: "## 最近更新"
replace_regex: '(?<=## 最近更新\n)[\s\S]*?(?=\n## )'
changelog_body: ${{ steps.release-drafter.outputs.body }}
commit_and_push: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
archive_regex: '(?<=## )最近更新(?=\n)'
archive_title: ${{ env.TAG_NAME }}
commit_and_push: false

- name: Push Tag
run: |
git config user.name github-actions[bot]
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


publish-docker:
runs-on: ubuntu-latest
needs: build-frontend
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Ruff Lint

on:
push:
branches:
- main
pull_request:
paths:
- "nonebot_bison/**"
- "extra_plugins/**"
- "tests/**"
- "bot.py"

jobs:
ruff:
name: Ruff Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run Ruff Lint
uses: chartboost/ruff-action@v1
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ flag_management:
target: auto
threshold: 5%
- type: patch
target: 80%
target: 80%
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
go-cqhttp:
Expand All @@ -15,8 +15,8 @@ services:
# SUPERUSERS: '[<your QQ>]'
BISON_CONFIG_PATH: /data
# BISON_OUTER_URL: 'http://<your server ip>:8080/bison'
BISON_FILTER_LOG: 'true'
BISON_USE_PIC: 'false' # 如果需要将文字转为图片发送请改为true
BISON_FILTER_LOG: "true"
BISON_USE_PIC: "false" # 如果需要将文字转为图片发送请改为true
ports:
- 8080:8080
depends_on:
Expand Down
12 changes: 5 additions & 7 deletions extra_plugins/auto_agree.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from typing import Union

from nonebot import on_request
from nonebot.adapters.onebot.v11 import Bot
from nonebot.adapters.onebot.v11.event import FriendRequestEvent, GroupRequestEvent
from nonebot.log import logger
from nonebot.adapters.onebot.v11 import Bot
from nonebot.adapters.onebot.v11.event import GroupRequestEvent, FriendRequestEvent

friend_req = on_request(priority=5)


@friend_req.handle()
async def add_superuser(bot: Bot, event: Union[GroupRequestEvent, FriendRequestEvent]):
async def add_superuser(bot: Bot, event: GroupRequestEvent | FriendRequestEvent):
if str(event.user_id) not in bot.config.superusers:
return

if isinstance(event, FriendRequestEvent):
await event.approve(bot)
logger.info("add user {}".format(event.user_id))
logger.info(f"add user {event.user_id}")
else:
await event.approve(bot)
logger.info("add group {}".format(event.group_id))
logger.info(f"add group {event.group_id}")
4 changes: 2 additions & 2 deletions nonebot_bison/apis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .platform import platform_manager
from .scheduler import scheduler_dict
from .types import Target
from .scheduler import scheduler_dict
from .platform import platform_manager


async def check_sub_target(platform_name: str, target: Target):
Expand Down
10 changes: 4 additions & 6 deletions nonebot_bison/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from nonebot.log import logger
from nonebot_plugin_datastore.db import get_engine, post_db_init, pre_db_init
from sqlalchemy import inspect, text
from sqlalchemy import text, inspect
from nonebot_plugin_datastore.db import get_engine, pre_db_init, post_db_init

from .config.config_legacy import start_up as legacy_db_startup
from .config.db_migration import data_migrate
from .scheduler.manager import init_scheduler
from .config.config_legacy import start_up as legacy_db_startup


@pre_db_init
Expand Down Expand Up @@ -35,9 +35,7 @@ def _has_table(conn, table_name):
if await conn.run_sync(_has_table, "nonebot_bison_alembic_version"):
await conn.execute(text("drop table nonebot_bison_alembic_version"))

await conn.execute(
text("alter table alembic_version rename to nonebot_bison_alembic_version")
)
await conn.execute(text("alter table alembic_version rename to nonebot_bison_alembic_version"))


@post_db_init
Expand Down
22 changes: 8 additions & 14 deletions nonebot_bison/config/db_model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import datetime
from pathlib import Path

from nonebot_plugin_datastore import get_plugin_data
from nonebot_plugin_saa.utils import PlatformTarget
from sqlalchemy import JSON, ForeignKey, String, UniqueConstraint
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import Mapped, mapped_column, relationship
from nonebot_plugin_saa.utils import PlatformTarget
from nonebot_plugin_datastore import get_plugin_data
from sqlalchemy.orm import Mapped, relationship, mapped_column
from sqlalchemy import JSON, String, ForeignKey, UniqueConstraint

from ..types import Category, Tag
from ..types import Tag, Category

Model = get_plugin_data().Model
get_plugin_data().set_migration_dir(Path(__file__).parent / "migrations")
Expand All @@ -25,9 +25,7 @@ def saa_target(self) -> PlatformTarget:


class Target(Model):
__table_args__ = (
UniqueConstraint("target", "platform_name", name="unique-target-constraint"),
)
__table_args__ = (UniqueConstraint("target", "platform_name", name="unique-target-constraint"),)

id: Mapped[int] = mapped_column(primary_key=True)
platform_name: Mapped[str] = mapped_column(String(20))
Expand All @@ -36,9 +34,7 @@ class Target(Model):
default_schedule_weight: Mapped[int] = mapped_column(default=10)

subscribes: Mapped[list["Subscribe"]] = relationship(back_populates="target")
time_weight: Mapped[list["ScheduleTimeWeight"]] = relationship(
back_populates="target"
)
time_weight: Mapped[list["ScheduleTimeWeight"]] = relationship(back_populates="target")


class ScheduleTimeWeight(Model):
Expand All @@ -55,9 +51,7 @@ class Config:


class Subscribe(Model):
__table_args__ = (
UniqueConstraint("target_id", "user_id", name="unique-subscribe-constraint"),
)
__table_args__ = (UniqueConstraint("target_id", "user_id", name="unique-subscribe-constraint"),)

id: Mapped[int] = mapped_column(primary_key=True)
target_id: Mapped[int] = mapped_column(ForeignKey("nonebot_bison_target.id"))
Expand Down
Loading

0 comments on commit e50eb5d

Please sign in to comment.