From 80d1ab9bb2af4861464a5b11bc93dcb33164ab11 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Mon, 30 May 2022 21:24:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- defs/ci.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/defs/ci.py b/defs/ci.py index 25314bd..11d9530 100644 --- a/defs/ci.py +++ b/defs/ci.py @@ -58,11 +58,20 @@ async def get_artifact() -> Optional[Artifact]: return None +def format_branch(branch: str) -> str: + for i in ["-", ".", " ", ":"]: + branch = branch.replace(i, "_") + return branch + + def get_hash() -> str: req = get("https://api.github.com/repos/Grasscutters/Grasscutter/actions/runs?per_page=1&status=success") if req.status_code == 200: data = req.json() if data.get("workflow_runs", []): - return data["workflow_runs"][0]["head_commit"]["id"][:6] + " " + \ - data["workflow_runs"][0]["head_commit"]["message"][:50] + branch = data["workflow_runs"][0]["head_branch"] + hash_str = data["workflow_runs"][0]["head_commit"]["id"][:7] + message = data["workflow_runs"][0]["head_commit"]["message"][:200] + return f"#{format_branch(branch)} #{hash_str} \n\n" \ + f"{message}" return "Unknown."