Skip to content

Commit

Permalink
优化 github release body 输出 #802
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Jun 1, 2024
1 parent 81a5df3 commit f3dc90a
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 130 deletions.
97 changes: 48 additions & 49 deletions scripts/_pkg/Const.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
docmap_sillot = {
"Feature": "引入特性 | Feature",
"Enhancement": "改进功能 | Enhancement",
"Bug": "修复错误 | Bugfix",
"Security": "安全相关 | Security",
"Document": "文档相关 | Document",
"Refactor": "开发重构 | Refactor",
"Abolishment": "移除废止 | Abolishment",
"Shinning": "闪亮之名 | Shinning",
"VSCE": "VSCode 扩展相关 | VSCE",
}
# 仅关注核心部分
docmap_siyuan = {
"Feature": "引入特性 | Feature",
"Enhancement": "改进功能 | Enhancement",
# "Bug": "修复错误 | Bugfix",
# "Document": "文档相关 | Document",
"Refactor": "开发重构 | Refactor",
"Abolishment": "移除废止 | Abolishment",
"Development": "开发者相关 | Development",
}

repo_siyuan = "siyuan-note/siyuan"
repo_sillot = "Hi-Windom/Sillot"
hostname = "api.github.com"


HEADER_sillot = '''
# ❤️ 欢迎共建汐洛 [email protected]
# 🚧 汐洛仅用于开发者测试,不要用来存储重要数据!
🚢 [Docker image](https://hub.docker.com/r/soltus/sillot/tags?page=1&ordering=last_updated) 📦 [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=Hi-Windom.sillot) 📦 [Chromium Browser Extension(维护中)](https://github.com/K-Sillot/Sillot-Be/releases)
<span>
<img src="https://img.shields.io/badge/Chromium 94+-black?logo=Google Chrome&logoColor=white" alt="" title=""/><img src="https://img.shields.io/badge/Windows 10+-black?logo=Windows 11" title=""/><img src="https://img.shields.io/badge/Docker-black?logo=docker" title=""/><img src="https://img.shields.io/badge/Android 12+-black?logo=android" title=""/>
</span>
---
'''

HEADER_siyuan = '''
'''

HEADER = {
"siyuan-note/siyuan": HEADER_siyuan,
"Hi-Windom/Sillot": HEADER_sillot
}
docmap_sillot = {
"Feature": "引入特性 | Feature",
"Enhancement": "改进功能 | Enhancement",
"Bug": "修复错误 | Bugfix",
"Security": "安全相关 | Security",
"Document": "文档相关 | Document",
"Refactor": "开发重构 | Refactor",
"Abolishment": "移除废止 | Abolishment",
"Shinning": "闪亮之名 | Shinning",
"VSCE": "VSCode 扩展相关 | VSCE",
}
# 仅关注核心部分
docmap_siyuan = {
"Feature": "引入特性 | Feature",
"Enhancement": "改进功能 | Enhancement",
# "Bug": "修复错误 | Bugfix",
# "Document": "文档相关 | Document",
"Refactor": "开发重构 | Refactor",
"Abolishment": "移除废止 | Abolishment",
"Development": "开发者相关 | Development",
}

repo_siyuan = "siyuan-note/siyuan"
repo_sillot = "Hi-Windom/Sillot"
hostname = "api.github.com"


HEADER_sillot = '''
# 🚧 汐洛仅用于开发者测试,不要用来存储重要数据!
🚢 [Docker image](https://hub.docker.com/r/soltus/sillot/tags?page=1&ordering=last_updated) 📦 [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=Hi-Windom.sillot) 📦 [Chromium Browser Extension(维护中)](https://github.com/K-Sillot/Sillot-Be/releases)
<span>
<img src="https://img.shields.io/badge/Chromium 94+-black?logo=Google Chrome&logoColor=white" alt="" title=""/><img src="https://img.shields.io/badge/Windows 10+-black?logo=Windows 11" title=""/><img src="https://img.shields.io/badge/Docker-black?logo=docker" title=""/><img src="https://img.shields.io/badge/Android 12+-black?logo=android" title=""/>
</span>
---
'''

HEADER_siyuan = '''
'''

HEADER = {
"siyuan-note/siyuan": HEADER_siyuan,
"Hi-Windom/Sillot": HEADER_sillot
}
162 changes: 81 additions & 81 deletions scripts/_pkg/Utils.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
import re, ast

def quote_versions_v2(s):
"""
支持一个或两个点号分隔的版本号,请确保格式正确,本函数不做校验
字符串示例: "[3.0.7, 3.0.6, 3.0, 3.1]"
"""
return ast.literal_eval(re.sub(r'(\b\d+(\.\d+){1,2}\b)', r'"\1"', s))

def find_milestone(repo, title, len=0):
"""Find the milestone in a repository that is similar to milestone title
Args:
repo (github.repository.Repository): The repository to search
title (str): the title to match
len: 版本号长度限制,默认 0 不限制
Returns:
The milestone which title matches the given argument.
If no milestone matches, it will return None
"""
thisRelease = title.split("/")[-1]
pat = re.search("v([0-9.]+)", thisRelease)
if not pat:
return None
if len > 0:
version = ".".join(pat.group(1).split(".")[:len])
else:
version = ".".join(pat.group(1).split(".")[:])

# REF https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#list-milestones
for milestone in repo.get_milestones(state="all"):
if version in milestone.title:
return milestone

def generate_msg(desc_mapping, docmap):
"""Print changelogs from direction."""
print()
for header in docmap:
if not desc_mapping[header]:
continue
print(f"#### {docmap[header]}\n")
for item in desc_mapping[header]:
print(f"* [{item['title']}]({item['url']})")
print()

def get_issue_first_label(issue, docmap):
"""Get the first label from issue, if no labels, return empty string."""
for label in issue.get_labels():
if label.name in docmap:
return label.name
return ""

def generate_header_from_repo(repo_name, tag_name, lastestRelease, electron_version, action_file, HEADER=''):
thisRelease = tag_name.split("/")[-1]
pat = re.search("v([0-9.]+)", thisRelease)
if not pat:
return None

return f'''
<p align="center">
<a href="https://github.com/{repo_name}/actions/workflows/{action_file}"><img src="https://img.shields.io/github/actions/workflow/status/{repo_name}/{action_file}?logo=github&label={action_file}%20Action" style="cursor:pointer;height: 30px;margin: 3px auto;"/></a>
<a href="https://github.com/{repo_name}/releases/{thisRelease}/"><img src="https://img.shields.io/github/downloads/{repo_name}/{thisRelease}/total?logo=github" style="cursor:pointer;height: 30px;margin: 3px auto;"/></a>
<img alt="GitHub commits difference between two branches/tags/commits" src="https://img.shields.io/github/commits-difference/{repo_name}?base={lastestRelease}&head={thisRelease}&logo=git" style="cursor:pointer;height: 30px;margin: 3px auto;"/>
<img src="https://img.shields.io/badge/Electron {electron_version}-47848F.svg?style=flat&logo=Electron&logoColor=white" alt="Electron">
</p>
{HEADER}'''

def print_taget2siyuan(tag_name, otherReleaseArray):
print('# [@SiYuan](https://github.com/siyuan-note/siyuan)\n')
arr = quote_versions_v2(otherReleaseArray)
if len(arr) > 0:
print('''### 非目标思源版本更新:''', end="")
for v in arr:
print(f'''[v{v}](https://github.com/siyuan-note/siyuan/releases/tag/{v}) ''', end="")
print(f'''
## ⚓ [{tag_name}](https://github.com/siyuan-note/siyuan/releases/tag/{tag_name}) 值得注意的变化
''')
import re, ast

def quote_versions_v2(s):
"""
支持一个或两个点号分隔的版本号,请确保格式正确,本函数不做校验
字符串示例: "[3.0.7, 3.0.6, 3.0, 3.1]"
"""
return ast.literal_eval(re.sub(r'(\b\d+(\.\d+){1,2}\b)', r'"\1"', s))

def find_milestone(repo, title, len=0):
"""Find the milestone in a repository that is similar to milestone title
Args:
repo (github.repository.Repository): The repository to search
title (str): the title to match
len: 版本号长度限制,默认 0 不限制
Returns:
The milestone which title matches the given argument.
If no milestone matches, it will return None
"""
thisRelease = title.split("/")[-1]
pat = re.search("v([0-9.]+)", thisRelease)
if not pat:
return None
if len > 0:
version = ".".join(pat.group(1).split(".")[:len])
else:
version = ".".join(pat.group(1).split(".")[:])

# REF https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#list-milestones
for milestone in repo.get_milestones(state="all"):
if version in milestone.title:
return milestone

def generate_msg(desc_mapping, docmap):
"""Print changelogs from direction."""
print()
for header in docmap:
if not desc_mapping[header]:
continue
print(f"#### {docmap[header]}\n")
items = [f"[{item['title']}]({item['url']})" for item in desc_mapping[header]]
print(" | ".join(items))
print()

def get_issue_first_label(issue, docmap):
"""Get the first label from issue, if no labels, return empty string."""
for label in issue.get_labels():
if label.name in docmap:
return label.name
return ""

def generate_header_from_repo(repo_name, tag_name, lastestRelease, electron_version, action_file, HEADER=''):
thisRelease = tag_name.split("/")[-1]
pat = re.search("v([0-9.]+)", thisRelease)
if not pat:
return None

return f'''
<p align="center">
<a href="https://github.com/{repo_name}/actions/workflows/{action_file}"><img src="https://img.shields.io/github/actions/workflow/status/{repo_name}/{action_file}?logo=github&label={action_file}%20Action" style="cursor:pointer;height: 30px;margin: 3px auto;"/></a>
<a href="https://github.com/{repo_name}/releases/{thisRelease}/"><img src="https://img.shields.io/github/downloads/{repo_name}/{thisRelease}/total?logo=github" style="cursor:pointer;height: 30px;margin: 3px auto;"/></a>
<img alt="GitHub commits difference between two branches/tags/commits" src="https://img.shields.io/github/commits-difference/{repo_name}?base={lastestRelease}&head={thisRelease}&logo=git" style="cursor:pointer;height: 30px;margin: 3px auto;"/>
<img src="https://img.shields.io/badge/Electron {electron_version}-47848F.svg?style=flat&logo=Electron&logoColor=white" alt="Electron">
</p>
{HEADER}'''

def print_taget2siyuan(tag_name, otherReleaseArray):
print('# [@SiYuan](https://github.com/siyuan-note/siyuan)\n')
arr = quote_versions_v2(otherReleaseArray)
if len(arr) > 0:
print('''### 非目标思源版本更新:''', end="")
for v in arr:
print(f'''[v{v}](https://github.com/siyuan-note/siyuan/releases/tag/{v}) ''', end="")
print(f'''
## ⚓ [{tag_name}](https://github.com/siyuan-note/siyuan/releases/tag/{tag_name}) 值得注意的变化
''')

0 comments on commit f3dc90a

Please sign in to comment.