Skip to content

Commit

Permalink
style: 格式化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
MarleneJiang committed Aug 27, 2023
1 parent fa3e8c1 commit 4b136cb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
14 changes: 11 additions & 3 deletions .github/actions_scripts/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
author = os.environ["AUTHOR"]
license_info = os.environ["LICENSE"]
homepage = os.environ["HOMEPAGE"]
tags = os.environ["TAGS"].replace("[", "").replace("]", "").replace("'", "").replace('"', "").split(",")
tags = (
os.environ["TAGS"]
.replace("[", "")
.replace("]", "")
.replace("'", "")
.replace('"', "")
.split(",")
)


def get_json() -> dict[str, Any]:
"""获取对应json文件并解析."""
Expand All @@ -36,7 +44,7 @@ def add_info(json_data: list[dict[str, str]], infos: dict[str, Any]) -> bool:
i["license"] = infos["license"]
i["homepage"] = infos["homepage"]
i["tags"] = infos["tags"]
i["time"] = infos["time"]
i["time"] = infos["time"]
return True
json_data.append(infos)
return False
Expand Down Expand Up @@ -71,7 +79,7 @@ def main() -> None:
"homepage": homepage,
"tags": tags,
"is_official": False,
"time":formatted_time
"time": formatted_time,
}
if add_info(data_list, info):
set_action_outputs(
Expand Down
9 changes: 7 additions & 2 deletions .github/actions_scripts/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
sys.exit(1)

if TYPE not in {"plugin", "adapter", "bot"}:
sys.stdout.write("Invalid TYPE value. Must be one of 'plugin', 'adapter', or 'bot'.")
sys.stdout.write(
"Invalid TYPE value. Must be one of 'plugin', 'adapter', or 'bot'."
)
sys.exit(1)

bot = Bot(config_file=None)

old_error_or_exception = Bot.error_or_exception


def error_or_exception(self: Bot, message: str, exception: Exception) -> None:
"""出现错误直接退出."""
old_error_or_exception(self, message, exception)
sys.stdout.write(message)
sys.exit(1)


Bot.error_or_exception = error_or_exception

if TYPE == "plugin":
Expand All @@ -31,6 +36,7 @@ def error_or_exception(self: Bot, message: str, exception: Exception) -> None:
if TYPE == "bot":
sys.exit(0)


@bot.bot_run_hook
async def bot_run_hook(bot: Bot) -> None:
"""在 Bot 启动后直接退出。."""
Expand All @@ -41,4 +47,3 @@ async def bot_run_hook(bot: Bot) -> None:

if __name__ == "__main__":
bot.run()

10 changes: 7 additions & 3 deletions .github/actions_scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
MODULE_NAME = os.environ["MODULE_NAME"]
TYPE = os.environ["TYPE"]


def check_module(module_name: str) -> bool:
"""Check module name."""
import importlib

if module_name == "null":
return False
if "-" in module_name:
Expand All @@ -26,15 +28,17 @@ def check_module(module_name: str) -> bool:
else:
return True


def alicebot_test() -> None:
"""验证插件是否能在 alicebot 中正常运行."""
try:

# 要执行的 Python 脚本路径
python_script_path = ".github/actions_scripts/plugin_test.py"
# 整个命令
command = f"python {python_script_path} {MODULE_NAME} {TYPE}"
result = subprocess.run(command, timeout=10, check=True, shell=True,capture_output=True) # noqa: S602
result = subprocess.run(
command, timeout=10, check=True, shell=True, capture_output=True
) # noqa: S602
if result.returncode != 0:
msg = f"脚本执行失败: {result.stdout}"
raise ValueError(msg) from None
Expand Down Expand Up @@ -62,7 +66,7 @@ def get_meta_info() -> None:
author = metadata.get_all("Author")
if author is None:
email = metadata.get_all("Author-email")
if email is not None and "<" in email[0]: # PDM发包问题
if email is not None and "<" in email[0]: # PDM发包问题
author = [email[0].split("<")[0].strip()]
else:
set_action_outputs({"result": "error", "output": "作者信息获取失败"})
Expand Down
16 changes: 8 additions & 8 deletions .github/actions_scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@


def set_action_outputs(output_pairs: dict[str, str]) -> None:
"""Sets the GitHub Action outputs, with backwards compatibility for self-hosted runners without a GITHUB_OUTPUT environment file. Keyword arguments: output_pairs - Dictionary of outputs with values."""
if "GITHUB_OUTPUT" in os.environ :
with Path(os.environ["GITHUB_OUTPUT"]).open(mode="a") as f :
for key, value in output_pairs.items() :
f.write(f"{key}={value}\n")
else :
for key, value in output_pairs.items() :
print(f"::set-output name={key}::{value}") # noqa: T201
"""Sets the GitHub Action outputs, with backwards compatibility for self-hosted runners without a GITHUB_OUTPUT environment file. Keyword arguments: output_pairs - Dictionary of outputs with values."""
if "GITHUB_OUTPUT" in os.environ:
with Path(os.environ["GITHUB_OUTPUT"]).open(mode="a") as f:
for key, value in output_pairs.items():
f.write(f"{key}={value}\n")
else:
for key, value in output_pairs.items():
print(f"::set-output name={key}::{value}") # noqa: T201

0 comments on commit 4b136cb

Please sign in to comment.