📦 docs: 修改发布按钮样式

This commit is contained in:
snowykami 2024-09-18 01:04:37 +08:00
parent c8cb341afb
commit 8eb626b8da

View File

@ -32,6 +32,17 @@ def push_check_result(issue: Issue, result: str):
else: else:
issue.create_comment("检查结果: " + result) issue.create_comment("检查结果: " + result)
def push_publish_result(issue: Issue, result: str):
cid = None
for cm in issue.get_comments():
if cm.body.startswith("发布结果") and cm.user.login == bot_id:
cid = cm.id
break
if cid is not None:
issue.get_comment(cid).edit("发布结果: " + result)
else:
issue.create_comment("发布结果: " + result)
# opened: 创建新的资源包,预审核 # opened: 创建新的资源包,预审核
# edited: 编辑资源包信息,需重新审核 # edited: 编辑资源包信息,需重新审核
@ -106,45 +117,59 @@ def pre_check(github: Github, issue: Issue, repo: Repository) -> err:
# closed # closed
def add_resource(github: Github, issue: Issue, repo: Repository): def add_resource(github: Github, issue: Issue, repo: Repository) -> err:
parser = MarkdownParser(issue.body) # 检测关闭者是否为仓库管理员
parser.parse_front_matters() try:
name = parser.front_matters.get("name") closed_by = issue.closed_by
desc = parser.front_matters.get("desc") if closed_by is None:
link = parser.front_matters.get("link") push_publish_result(issue, "❌ 无法获取关闭者信息。")
homepage = parser.front_matters.get("homepage") # optional return ValueError("无法获取关闭者信息。")
author = parser.front_matters.get("author") if not any([True for u in repo.get_collaborators() if u.login == closed_by.login]):
push_publish_result(issue, "❌ 你不是仓库管理员,无法发布资源包。")
return ValueError("你不是仓库管理员,无法发布资源包。")
# 编辑仓库内的json文件 parser = MarkdownParser(issue.body)
resources = json.load(open(RESOURCE_JSON)) parser.parse_front_matters()
resources.append({ name = parser.front_matters.get("name")
"name" : name, desc = parser.front_matters.get("desc")
"description": desc, link = parser.front_matters.get("link")
"link" : link, homepage = parser.front_matters.get("homepage") # optional
"homepage" : homepage, author = parser.front_matters.get("author")
"author" : author
}) # 编辑仓库内的json文件
ref = repo.get_git_ref("heads/main") resources = json.load(open(RESOURCE_JSON))
tree = repo.create_git_tree( resources.append({
base_tree=repo.get_git_commit(ref.object.sha).tree, "name" : name,
tree=[ "description": desc,
InputGitTreeElement( "link" : link,
path=RESOURCE_JSON, "homepage" : homepage,
mode="100644", "author" : author
type="blob", })
content=json.dumps(resources, indent=4, ensure_ascii=False) ref = repo.get_git_ref("heads/main")
) tree = repo.create_git_tree(
] base_tree=repo.get_git_commit(ref.object.sha).tree,
) tree=[
commit = repo.create_git_commit( InputGitTreeElement(
message=f":package: 发布资源: {name}", path=RESOURCE_JSON,
tree=tree, mode="100644",
parents=[repo.get_git_commit(ref.object.sha)] type="blob",
) content=json.dumps(resources, indent=4, ensure_ascii=False)
ref.edit(commit.sha) )
issue.remove_from_labels("pre-checked") ]
issue.add_to_labels("passed") )
issue.create_comment(f"✅ 资源包 {name} 已发布!商店页面稍后就会更新。") commit = repo.create_git_commit(
message=f":package: 发布资源: {name}",
tree=tree,
parents=[repo.get_git_commit(ref.object.sha)]
)
ref.edit(commit.sha)
if "pre-checked" in issue.labels:
issue.remove_from_labels("pre-checked")
issue.add_to_labels("passed")
push_publish_result(issue, f"✅ 资源包 {name} 已发布!商店页面稍后就会更新。")
except Exception as e:
push_publish_result(issue, f"❌ 发布失败: {str(e)}")
return e
def handle_resource(github: Github, issue: Issue, repo: Repository, act_type: str): def handle_resource(github: Github, issue: Issue, repo: Repository, act_type: str):
@ -153,6 +178,8 @@ def handle_resource(github: Github, issue: Issue, repo: Repository, act_type: st
on_first_open(github, issue, repo) on_first_open(github, issue, repo)
pre_check(github, issue, repo) pre_check(github, issue, repo)
elif act_type == CLOSED: elif act_type == CLOSED:
add_resource(github, issue, repo) e = add_resource(github, issue, repo)
if e != nil:
print(f"Error: {e}")
else: else:
print("No operation found for the issue: ", act_type) print("No operation found for the issue: ", act_type)