* 解析任务行
(line: string, section: string)
| 150 | * 解析任务行 |
| 151 | */ |
| 152 | private parseTaskLine(line: string, section: string): Partial<WorkflowTask> { |
| 153 | const isCompleted = line.includes('- [x]'); |
| 154 | const taskText = line.replace(/^- \[[x ]\]\s*/, '').trim(); |
| 155 | |
| 156 | // 提取任务ID(如果存在) |
| 157 | const idMatch = taskText.match(/\[ID:([^\]]+)\]/); |
| 158 | const id = idMatch ? idMatch[1] : this.generateTaskId(); |
| 159 | |
| 160 | // 提取优先级 |
| 161 | const priorityMatch = taskText.match(/\[优先级:([^\]]+)\]/); |
| 162 | const priority = this.mapPriority(priorityMatch ? priorityMatch[1] : 'medium'); |
| 163 | |
| 164 | // 提取任务标题 |
| 165 | const title = taskText |
| 166 | .replace(/\[ID:[^\]]+\]/g, '') |
| 167 | .replace(/\[优先级:[^\]]+\]/g, '') |
| 168 | .replace(/\[估时:[^\]]+\]/g, '') |
| 169 | .trim(); |
| 170 | |
| 171 | // 确定任务状态 |
| 172 | let status: TaskStatus = 'todo'; |
| 173 | if (isCompleted) { |
| 174 | status = 'completed'; |
| 175 | } else if (section) { |
| 176 | // 验证section是否为有效的TaskStatus |
| 177 | const validStatuses: TaskStatus[] = [ |
| 178 | 'todo', |
| 179 | 'in-progress', |
| 180 | 'completed', |
| 181 | 'blocked', |
| 182 | 'cancelled', |
| 183 | ]; |
| 184 | if (validStatuses.includes(section as TaskStatus)) { |
| 185 | status = section as TaskStatus; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | return { |
| 190 | id, |
| 191 | title, |
| 192 | status, |
| 193 | priority, |
| 194 | dependencies: [], |
| 195 | tags: [], |
| 196 | notes: [], |
| 197 | createdAt: new Date(), |
| 198 | updatedAt: new Date(), |
| 199 | }; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * 解析任务详情 |
no test coverage detected