Skip to content

Commit

Permalink
ci: 小調整變更記錄產生格式 (#388)
Browse files Browse the repository at this point in the history
歷史提交:
* ci: 小調整
* test: 測試工作流程
* ci: 完成!
* ci: 加個 test 提交
  • Loading branch information
xMikux committed Sep 7, 2023
1 parent f5d6c5b commit d6867cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
29 changes: 24 additions & 5 deletions .github/scripts/commit_formater.py
@@ -1,3 +1,4 @@
import os
import re
import sys

Expand Down Expand Up @@ -33,20 +34,38 @@ def type_title(type):

return type_mapping.get(type, "🔆 其他")

def replace_prs(commit_message):
pattern = r'\(#(\d+)\)'
def replace_link(match):
pr_number = match.group(1)
return f'([#{pr_number}]({PROJECT_URL}/pull/{pr_number}))'

updated_message = re.sub(pattern, replace_link, commit_message)

return updated_message

def short_sha_link(commit_sha):
short_sha = commit_sha[:7]

return f" ([{short_sha}]({PROJECT_URL}/commit/{commit_sha}))"

if __name__ == "__main__":
commit_message = sys.argv[1]
if len(sys.argv) < 2:
sys.exit(1)

PROJECT_URL = "https://github.com/xMikux/ModsTranslationPack"
commit_message = sys.argv[1]
commit_info = extract_conventional_commits(commit_message)
line = ""
commit_sha = os.environ["GITHUB_SHA"]

if commit_info:
line += "## {}\n\n".format(type_title(commit_info["type"]))
line = "## {}\n\n".format(type_title(commit_info["type"]))
if commit_info["scope"]:
line += "* **{}**: ".format(commit_info["scope"])
line += commit_info["description"]
line += replace_prs(commit_info["description"])
else:
line += "* {}".format(commit_info["description"])
line += "* {}".format(replace_prs(commit_info["description"]))
line += short_sha_link(commit_sha)

print(line)
else:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI-VerifyCommit.yml
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Verify Commit
uses: taskmedia/action-conventional-commits@v1.1.0
with:
types: "feat|fix|chore|ci|docs|refactor|mods_feat|mods_update|mods_fix|mods_improve|mods_localize|mods_remove"
types: "feat|fix|chore|ci|docs|refactor|test|mods_feat|mods_update|mods_fix|mods_improve|mods_localize|mods_remove"

0 comments on commit d6867cc

Please sign in to comment.