Skip to content

Commit f6a63aa

Browse files
committed
bugfix: fix yaml parse issue
1 parent e95dac2 commit f6a63aa

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed

debug/test_yaml_multiline.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
"""
3+
测试 YAML 多行字符串解析
4+
"""
5+
6+
import sys
7+
from pathlib import Path
8+
9+
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
10+
11+
from libs.utils import load_simple_yaml
12+
13+
14+
def test_multiline():
15+
"""测试多行字符串解析"""
16+
print("测试 task-checker.yml 的多行字符串解析")
17+
print("=" * 60)
18+
19+
config_path = Path(__file__).parent.parent / "src" / "config" / "task-checker.yml"
20+
config = load_simple_yaml(str(config_path))
21+
22+
reminder_template = config.get("reminder_template", "")
23+
24+
print(f"reminder_template 类型: {type(reminder_template)}")
25+
print(f"reminder_template 长度: {len(reminder_template) if isinstance(reminder_template, str) else 'N/A'}")
26+
print("\n内容:")
27+
print("-" * 60)
28+
print(reminder_template)
29+
print("-" * 60)
30+
31+
if isinstance(reminder_template, str) and len(reminder_template) > 0:
32+
print("\n✓ 多行字符串解析成功")
33+
34+
# 测试格式化
35+
try:
36+
formatted = reminder_template.format(
37+
assignees="@user1 @user2",
38+
priority="P0",
39+
hours=48.5,
40+
title="测试任务",
41+
timeout=72
42+
)
43+
print("\n格式化后的消息:")
44+
print("-" * 60)
45+
print(formatted)
46+
print("-" * 60)
47+
print("\n✓ 格式化成功")
48+
except Exception as e:
49+
print(f"\n✗ 格式化失败: {e}")
50+
else:
51+
print("\n✗ 多行字符串解析失败")
52+
print(f" 期望: 字符串")
53+
print(f" 实际: {type(reminder_template)}")
54+
55+
56+
if __name__ == "__main__":
57+
test_multiline()

src/components/task_checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def check_task_timeout(token, repo, issue, config, verbose=False):
107107
if not assignees:
108108
# No assignees, optionally notify in config
109109
if not config.get("notify_unassigned", False):
110-
return False
110+
if verbose:
111+
print(f" ⊘ 跳过: 无负责人且未启用 notify_unassigned")
112+
return {"skip_reason": "no_assignee"}
111113

112114
# Handle default_mention as string or list
113115
default_mention = config.get("default_mention", "@team")

src/libs/utils.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,61 @@ def parse_value(v: str):
3535

3636
root = {}
3737
stack = [(0, root)]
38-
for ln in lines:
38+
i = 0
39+
while i < len(lines):
40+
ln = lines[i]
3941
if not ln.strip() or ln.strip().startswith("#"):
42+
i += 1
4043
continue
4144
# Remove inline comments
4245
ln = ln.split("#")[0].rstrip()
4346
if not ln.strip():
47+
i += 1
4448
continue
4549
indent = len(ln) - len(ln.lstrip(" "))
4650
key, _, val = ln.strip().partition(":")
4751
val = val.strip()
4852
while stack and indent < stack[-1][0]:
4953
stack.pop()
5054
cur = stack[-1][1]
51-
if val == "":
55+
56+
# Check for multiline string (| or >)
57+
if val == "|" or val == ">":
58+
# Literal block scalar (|) or folded block scalar (>)
59+
preserve_newlines = (val == "|")
60+
multiline_content = []
61+
i += 1
62+
# Find the base indentation of the multiline content
63+
base_indent = None
64+
while i < len(lines):
65+
next_ln = lines[i]
66+
# Skip empty lines
67+
if not next_ln.strip():
68+
if base_indent is not None:
69+
multiline_content.append("")
70+
i += 1
71+
continue
72+
# Check if this line is part of the multiline content
73+
next_indent = len(next_ln) - len(next_ln.lstrip(" "))
74+
if base_indent is None:
75+
base_indent = next_indent
76+
if next_indent < indent + 2:
77+
# This line is at the same or lower indentation, end of multiline
78+
break
79+
# Add the line content (remove base indentation)
80+
content = next_ln[base_indent:] if len(next_ln) > base_indent else ""
81+
multiline_content.append(content.rstrip())
82+
i += 1
83+
# Join the lines
84+
if preserve_newlines:
85+
cur[key] = "\n".join(multiline_content)
86+
else:
87+
cur[key] = " ".join(multiline_content)
88+
continue
89+
elif val == "":
5290
cur[key] = {}
5391
stack.append((indent + 2, cur[key]))
5492
else:
5593
cur[key] = parse_value(val)
94+
i += 1
5695
return root

0 commit comments

Comments
 (0)