From f214c0b2cbb41a5dfd268bdeadaa2dfaf050ac37 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 23 Nov 2020 13:41:57 +0800 Subject: [PATCH 1/5] :memo: add cross plugin guide --- docs/.vuepress/config.js | 8 +++++++- docs/advanced/export-and-require.md | 1 + docs/advanced/permission.md | 2 +- docs/advanced/runtime-hook.md | 2 +- docs/advanced/scheduler.md | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 docs/advanced/export-and-require.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index e339e2ca..e4f24184 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -118,7 +118,13 @@ module.exports = context => ({ title: "进阶", collapsable: false, sidebar: "auto", - children: ["", "scheduler", "permission", "runtime-hook"] + children: [ + "", + "scheduler", + "permission", + "runtime-hook", + "export-and-require" + ] } ], "/api/": [ diff --git a/docs/advanced/export-and-require.md b/docs/advanced/export-and-require.md new file mode 100644 index 00000000..832b0e75 --- /dev/null +++ b/docs/advanced/export-and-require.md @@ -0,0 +1 @@ +# 跨插件访问 diff --git a/docs/advanced/permission.md b/docs/advanced/permission.md index 30e20002..7190bcdd 100644 --- a/docs/advanced/permission.md +++ b/docs/advanced/permission.md @@ -1 +1 @@ -# 权限控制 \ No newline at end of file +# 权限控制 diff --git a/docs/advanced/runtime-hook.md b/docs/advanced/runtime-hook.md index ed3968a4..58bca681 100644 --- a/docs/advanced/runtime-hook.md +++ b/docs/advanced/runtime-hook.md @@ -1 +1 @@ -# 运行时插槽 \ No newline at end of file +# 运行时插槽 diff --git a/docs/advanced/scheduler.md b/docs/advanced/scheduler.md index 99d906d3..53e6cedc 100644 --- a/docs/advanced/scheduler.md +++ b/docs/advanced/scheduler.md @@ -1 +1 @@ -# 定时任务 \ No newline at end of file +# 定时任务 From bdd7e9514a416c0e7ab7a24c0bda221967f06419 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 23 Nov 2020 13:46:36 +0800 Subject: [PATCH 2/5] :memo: add plugin publish guide --- docs/.vuepress/config.js | 8 ++++++++ docs/advanced/publish-plugin.md | 1 + 2 files changed, 9 insertions(+) create mode 100644 docs/advanced/publish-plugin.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index e4f24184..f7c87283 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -125,6 +125,14 @@ module.exports = context => ({ "runtime-hook", "export-and-require" ] + }, + { + title: "发布", + collapsable: false, + sidebar: "auto", + children: [ + "publish-plugin" + ] } ], "/api/": [ diff --git a/docs/advanced/publish-plugin.md b/docs/advanced/publish-plugin.md new file mode 100644 index 00000000..68e2e6f9 --- /dev/null +++ b/docs/advanced/publish-plugin.md @@ -0,0 +1 @@ +# 发布插件 From b7642394f401caa3107974ab1a05f6f2f98c9455 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 23 Nov 2020 14:15:30 +0800 Subject: [PATCH 3/5] :memo: update guide --- docs/guide/installation.md | 7 ++++--- docs/guide/loading-a-plugin.md | 11 +---------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/docs/guide/installation.md b/docs/guide/installation.md index 907630c9..2b54eae1 100644 --- a/docs/guide/installation.md +++ b/docs/guide/installation.md @@ -44,7 +44,8 @@ pip install nonebot2[scheduler] poetry add nonebot2[scheduler] ``` -[View On GitHub](https://github.com/agronholm/apscheduler) +[![apscheduler](https://img.shields.io/github/stars/agronholm/apscheduler?style=social)](https://github.com/agronholm/apscheduler) + ### NoneBot-Test @@ -57,7 +58,7 @@ pip install nonebot2[test] poetry add nonebot2[test] ``` -[View On GitHub](https://github.com/nonebot/nonebot-test) +[![nonebot-test](https://img.shields.io/github/stars/nonebot/nonebot-test?style=social)](https://github.com/nonebot/nonebot-test) ### CLI @@ -70,7 +71,7 @@ pip install nonebot2[cli] poetry add nonebot2[cli] ``` -[View On GitHub](https://github.com/yanyongyu/nb-cli) +[![nb-cli](https://img.shields.io/github/stars/nonebot/nb-cli?style=social)](https://github.com/yanyongyu/nb-cli) ### 我全都要 diff --git a/docs/guide/loading-a-plugin.md b/docs/guide/loading-a-plugin.md index b648b4b6..2a3016d5 100644 --- a/docs/guide/loading-a-plugin.md +++ b/docs/guide/loading-a-plugin.md @@ -52,12 +52,7 @@ if __name__ == "__main__": ::: :::danger 警告 -插件间不应该存在过多的耦合,如果确实需要导入某个插件内的数据,可以使用如下两种方法: - -1. (推荐) `from plugin_name import xxx` 而非 `from awesome_bot.plugins.plugin_name import xxx` -2. 在需要导入其他插件的文件中添加 `__package__ = "plugins"; from .plugin_name import xxx` (将共同的上层目录设定为父包后使用相对导入) - -具体可以参考:[nonebot/nonebot2#32](https://github.com/nonebot/nonebot2/issues/32) +插件间不应该存在过多的耦合,如果确实需要导入某个插件内的数据,可以参考 [进阶-跨插件访问](../advanced/export-and-require.md) ::: ## 加载单个插件 @@ -113,10 +108,6 @@ _sub_plugins |= nonebot.load_plugins( 插件将会被加载并存储于 `_sub_plugins` 中。 -:::tip 提示 -如果在父插件中需要定义事件响应器,应在**子插件被加载后**进行定义 -::: - ## 运行结果 尝试运行 `nb run` 或者 `python bot.py`,可以看到日志输出了类似如下内容: From 1fe38afa95af0d69360a51ea0cc69339fc40e6bd Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Thu, 26 Nov 2020 20:18:36 +0800 Subject: [PATCH 4/5] :bug: fix workflow vulnerability #79 --- .../{api_docs.yml => build_docs.yml} | 15 +++------ .github/workflows/upload_docs.yml | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) rename .github/workflows/{api_docs.yml => build_docs.yml} (60%) create mode 100644 .github/workflows/upload_docs.yml diff --git a/.github/workflows/api_docs.yml b/.github/workflows/build_docs.yml similarity index 60% rename from .github/workflows/api_docs.yml rename to .github/workflows/build_docs.yml index f4ee792b..8f4b0dc2 100644 --- a/.github/workflows/api_docs.yml +++ b/.github/workflows/build_docs.yml @@ -1,7 +1,7 @@ name: Build API Doc on: - pull_request_target: + pull_request: types: [ opened, synchronize, reopened ] jobs: @@ -12,7 +12,6 @@ jobs: - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} - token: ${{ secrets.GH_TOKEN }} - name: Set up Python uses: actions/setup-python@v2 @@ -32,11 +31,7 @@ jobs: - name: Copy Files run: cp -r ./build/markdown/* ./docs/api/ - - run: | - git config user.name nonebot - git config user.email nonebot@nonebot.dev - git add . - git diff-index --quiet HEAD || git commit -m ":memo: update api docs" - git remote -vv - git remote add target ${{github.event.pull_request.head.repo.clone_url}} - git push target HEAD:${{github.event.pull_request.head.ref}} + - uses: actions/upload-artifact@v2 + with: + name: docs + path: docs/ diff --git a/.github/workflows/upload_docs.yml b/.github/workflows/upload_docs.yml new file mode 100644 index 00000000..d20c3677 --- /dev/null +++ b/.github/workflows/upload_docs.yml @@ -0,0 +1,33 @@ +name: Upload API Doc + +on: + workflow_run: + workflows: ["Build API Doc"] + types: + - completed + +jobs: + upload: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.workflow_run.head_sha }} + token: ${{ secrets.GH_TOKEN }} + + - uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: docs + path: docs/ + + - env: + REF: ${{ github.event.workflow_run.head_branch }} + run: | + git config user.name GitHub + git config user.email noreply@github.com + git add . + git diff-index --quiet HEAD || git commit -m ":memo: update api docs" + git remote add target "https://github.com/${{ github.event.workflow_run.head_repository.full_name }}.git" + git push target HEAD:$REF From 309c6d1ed0c8c77393bbfe7ddf6e15751b79c21d Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Thu, 26 Nov 2020 20:53:28 +0800 Subject: [PATCH 5/5] :construction_worker: update user info for pr --- .github/workflows/upload_docs.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/upload_docs.yml b/.github/workflows/upload_docs.yml index d20c3677..5b306c01 100644 --- a/.github/workflows/upload_docs.yml +++ b/.github/workflows/upload_docs.yml @@ -24,10 +24,12 @@ jobs: - env: REF: ${{ github.event.workflow_run.head_branch }} + PR_REPO: ${{ github.event.workflow_run.head_repository.full_name }} + PR_USER: ${{ github.event.workflow_run.head_repository.owner.login }} run: | - git config user.name GitHub - git config user.email noreply@github.com + git config user.name $PR_USER + git config user.email $PR_USER@users.noreply.github.com git add . git diff-index --quiet HEAD || git commit -m ":memo: update api docs" - git remote add target "https://github.com/${{ github.event.workflow_run.head_repository.full_name }}.git" + git remote add target https://github.com/$PR_REPO.git git push target HEAD:$REF