(issue)
| 359 | } |
| 360 | |
| 361 | async analyzeArticleLabels(issue) { |
| 362 | try { |
| 363 | const labels = Array.isArray(issue.labels) |
| 364 | ? issue.labels.map(label => typeof label === 'string' ? label : label.name) |
| 365 | : JSON.parse(issue.labels || '[]'); |
| 366 | |
| 367 | const content = issue.body || ''; |
| 368 | |
| 369 | // 获取标签分类信息 |
| 370 | const labelInfo = await Promise.all( |
| 371 | labels.map(label => |
| 372 | new Promise((resolve, reject) => { |
| 373 | this.db.get( |
| 374 | 'SELECT category FROM label_categories WHERE label = ?', |
| 375 | [label], |
| 376 | (err, row) => { |
| 377 | if (err) reject(err); |
| 378 | else resolve({ |
| 379 | label, |
| 380 | category: row ? row.category : 'uncategorized' |
| 381 | }); |
| 382 | } |
| 383 | ); |
| 384 | }) |
| 385 | ) |
| 386 | ); |
| 387 | |
| 388 | // 计算标签权重 |
| 389 | const weights = this.calculateLabelWeights(labels, content); |
| 390 | |
| 391 | // 保存到数据库 |
| 392 | const insertSQL = ` |
| 393 | INSERT OR REPLACE INTO article_labels |
| 394 | (issue_number, label, category, weight) |
| 395 | VALUES (?, ?, ?, ?) |
| 396 | `; |
| 397 | |
| 398 | for (const {label, category} of labelInfo) { |
| 399 | await new Promise((resolve, reject) => { |
| 400 | this.db.run( |
| 401 | insertSQL, |
| 402 | [issue.number, label, category, weights[label] || 1.0], |
| 403 | (err) => { |
| 404 | if (err) reject(err); |
| 405 | else resolve(); |
| 406 | } |
| 407 | ); |
| 408 | }); |
| 409 | } |
| 410 | } catch (error) { |
| 411 | console.error(`Error analyzing labels for issue #${issue.number}:`, error); |
| 412 | // 继续处理下一个文章,而不是中断整个过程 |
| 413 | return; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | calculateLabelWeights(labels, content) { |
| 418 | const weights = {}; |
no test coverage detected