mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-11 05:17:24 +08:00
📦 docs: 资源商店新增发布资源功能
This commit is contained in:
parent
3c6380cb82
commit
3932dd60da
@ -12,4 +12,6 @@ PLUGIN_PREFIX = "Plugin: "
|
|||||||
PLUGIN_JSON = "docs/publics/plugins.json"
|
PLUGIN_JSON = "docs/publics/plugins.json"
|
||||||
RESOURCE_JSON = "docs/publics/resources.json"
|
RESOURCE_JSON = "docs/publics/resources.json"
|
||||||
|
|
||||||
edit_tip = "若要修改请编辑这段front matter,不要编辑正文/If you want to modify, please edit the front matter, do not edit the body"
|
edit_content_tip = "若要修改请编辑这段front matter,不要编辑正文/If you want to modify, please edit the front matter, do not edit the body"
|
||||||
|
|
||||||
|
edit_tip = "如需修改请编辑issue,请不要新建issue,我会自动检查"
|
||||||
|
@ -10,7 +10,7 @@ from github.Repository import Repository
|
|||||||
import json
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from liteyuki_flow.const import OPENED, EDITED, CLOSED, REOPENED, RESOURCE_JSON
|
from liteyuki_flow.const import OPENED, EDITED, CLOSED, REOPENED, RESOURCE_JSON, edit_tip
|
||||||
from liteyuki_flow.markdown_parser import MarkdownParser
|
from liteyuki_flow.markdown_parser import MarkdownParser
|
||||||
from liteyuki_flow.typ import err, nil
|
from liteyuki_flow.typ import err, nil
|
||||||
|
|
||||||
@ -20,6 +20,7 @@ headers = {
|
|||||||
"User-Agent": user_agent
|
"User-Agent": user_agent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# opened: 创建新的资源包,预审核
|
# opened: 创建新的资源包,预审核
|
||||||
# edited: 编辑资源包信息,需重新审核
|
# edited: 编辑资源包信息,需重新审核
|
||||||
# closed: 审核通过,修改json并提交
|
# closed: 审核通过,修改json并提交
|
||||||
@ -35,16 +36,15 @@ def pre_check(github: Github, issue: Issue, repo: Repository) -> err:
|
|||||||
homepage = parser.front_matters.get("homepage") # optional
|
homepage = parser.front_matters.get("homepage") # optional
|
||||||
author = parser.front_matters.get("author")
|
author = parser.front_matters.get("author")
|
||||||
if not all((name, desc, link, author)):
|
if not all((name, desc, link, author)):
|
||||||
issue.create_comment("name, desc, link, homepage 及 author 为必填字段.")
|
issue.create_comment("name, desc, link, homepage 及 author 为必填字段." + edit_tip)
|
||||||
return ValueError("name, desc, link, homepage 及 author 为必填字段.")
|
return ValueError("name, desc, link, homepage 及 author 为必填字段.")
|
||||||
|
|
||||||
# 下载并解析资源包
|
# 下载并解析资源包
|
||||||
r = requests.get(link, headers=headers)
|
r = requests.get(link, headers=headers)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
issue.create_comment("下载失败.")
|
issue.create_comment("下载失败." + edit_tip)
|
||||||
return ValueError("下载失败.")
|
return ValueError("下载失败.")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(f"tmp/{name}.zip", "wb") as f:
|
with open(f"tmp/{name}.zip", "wb") as f:
|
||||||
f.write(r.content)
|
f.write(r.content)
|
||||||
@ -54,12 +54,12 @@ def pre_check(github: Github, issue: Issue, repo: Repository) -> err:
|
|||||||
# 检测包内metadata.yml文件
|
# 检测包内metadata.yml文件
|
||||||
data = yaml.load(open(f"tmp/{name}/metadata.yml"), Loader=yaml.SafeLoader)
|
data = yaml.load(open(f"tmp/{name}/metadata.yml"), Loader=yaml.SafeLoader)
|
||||||
except Exception:
|
except Exception:
|
||||||
issue.create_comment("解析资源包失败,可能是格式问题或metadata.yml不存在.")
|
issue.create_comment("解析资源包失败,可能是格式问题或metadata.yml不存在." + edit_tip)
|
||||||
return ValueError("解析资源包失败,可能是格式问题或metadata.yml不存在.")
|
return ValueError("解析资源包失败,可能是格式问题或metadata.yml不存在.")
|
||||||
|
|
||||||
# 检测必要字段 name,description,version
|
# 检测必要字段 name,description,version
|
||||||
if not all((data.get("name"), data.get("description"), data.get("version"))):
|
if not all((data.get("name"), data.get("description"), data.get("version"))):
|
||||||
issue.create_comment("元数据中缺少必要字段 name, description 或 version.")
|
issue.create_comment("元数据中缺少必要字段 name, description 或 version." + edit_tip)
|
||||||
return ValueError("元数据中缺少必要字段 name, description 或 version.")
|
return ValueError("元数据中缺少必要字段 name, description 或 version.")
|
||||||
|
|
||||||
# 不检测重复资源包,因为资源包可能有多个版本
|
# 不检测重复资源包,因为资源包可能有多个版本
|
||||||
|
Loading…
Reference in New Issue
Block a user