This commit is contained in:
@@ -32,25 +32,47 @@ class ParameterChange:
|
||||
old_required: Optional[bool] = None
|
||||
detail: Optional[str] = None
|
||||
|
||||
def to_display_line(self) -> str:
|
||||
def to_markdown_line(self, *, plain: bool = False) -> str:
|
||||
"""
|
||||
格式化为通知模板中的一行文本。
|
||||
格式化为企微 Markdown 行。
|
||||
plain=True 时用于新增接口,直接列出参数,不加「新增」前缀。
|
||||
"""
|
||||
req_optional = self.required is False
|
||||
req_required = self.required is True
|
||||
|
||||
if plain and self.change_type == ChangeType.ADDED:
|
||||
tag = (
|
||||
'<font color="warning">必填</font>'
|
||||
if req_required
|
||||
else '<font color="comment">可选</font>'
|
||||
)
|
||||
return f'> `{self.param_type}` **{self.param_name}** · {tag}'
|
||||
|
||||
:return: 如 "删除: Boolean userType" 或 "重命名: String userName -> String accountName"
|
||||
"""
|
||||
if self.change_type == ChangeType.REMOVED:
|
||||
return f" - 删除: {self.param_type} {self.param_name}"
|
||||
return (
|
||||
f'<font color="warning">【删除】</font> '
|
||||
f'`{self.param_type}` ~~{self.param_name}~~'
|
||||
)
|
||||
if self.change_type == ChangeType.ADDED:
|
||||
req_text = f" (是否必填:{str(self.required).lower()})" if self.required is not None else ""
|
||||
return f" - 新增: {self.param_type} {self.param_name}{req_text}"
|
||||
tag = (
|
||||
'<font color="warning">必填</font>'
|
||||
if req_required
|
||||
else '<font color="comment">可选</font>'
|
||||
)
|
||||
return (
|
||||
f'<font color="info">【新增】</font> '
|
||||
f'`{self.param_type}` **{self.param_name}** · {tag}'
|
||||
)
|
||||
if self.change_type == ChangeType.RENAMED:
|
||||
return f" - 重命名: {self.old_type} {self.old_name} -> {self.param_type} {self.param_name}"
|
||||
return (
|
||||
f'<font color="comment">【重命名】</font> '
|
||||
f'`{self.old_type}` {self.old_name} → '
|
||||
f'`{self.param_type}` **{self.param_name}**'
|
||||
)
|
||||
if self.change_type == ChangeType.MODIFIED:
|
||||
parts = [f" - 修改: {self.param_name}"]
|
||||
if self.detail:
|
||||
parts.append(f" ({self.detail})")
|
||||
return "".join(parts)
|
||||
return f" - {self.change_type.value}: {self.param_name}"
|
||||
detail = f' · <font color="comment">{self.detail}</font>' if self.detail else ""
|
||||
return f'<font color="warning">【修改】</font> **{self.param_name}**{detail}'
|
||||
return f'- {self.param_name}'
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user