* Builds an issue document from a fetched issue.
( encodedProject: string, host: string, projectPath: string, issue: GitLabIssue )
| 433 | * Builds an issue document from a fetched issue. |
| 434 | */ |
| 435 | function issueToDocument( |
| 436 | encodedProject: string, |
| 437 | host: string, |
| 438 | projectPath: string, |
| 439 | issue: GitLabIssue |
| 440 | ): ExternalDocument | null { |
| 441 | const title = issue.title?.trim() || `Issue #${issue.iid}` |
| 442 | const description = typeof issue.description === 'string' ? issue.description : '' |
| 443 | const body = composeBody(title, description) |
| 444 | if (!body.trim()) return null |
| 445 | |
| 446 | const updatedAt = issue.updated_at ?? issue.created_at ?? '' |
| 447 | const createdAt = issue.created_at ?? '' |
| 448 | const author = issue.author?.username?.trim() || issue.author?.name?.trim() || '' |
| 449 | const labels = Array.isArray(issue.labels) ? issue.labels : [] |
| 450 | const milestone = issue.milestone?.title?.trim() || '' |
| 451 | |
| 452 | const fallbackUrl = projectPath |
| 453 | ? `https://${host}/${projectPath}/-/issues/${issue.iid}` |
| 454 | : undefined |
| 455 | |
| 456 | return { |
| 457 | externalId: `${ISSUE_PREFIX}${issue.iid}`, |
| 458 | title, |
| 459 | content: body, |
| 460 | contentDeferred: false, |
| 461 | mimeType: 'text/plain', |
| 462 | sourceUrl: issue.web_url || fallbackUrl, |
| 463 | contentHash: buildIssueContentHash(encodedProject, issue.iid, updatedAt), |
| 464 | metadata: { |
| 465 | contentType: 'issue', |
| 466 | title, |
| 467 | iid: issue.iid, |
| 468 | state: issue.state, |
| 469 | author, |
| 470 | labels, |
| 471 | milestone, |
| 472 | createdAt, |
| 473 | updatedAt, |
| 474 | }, |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Fetches the project record, used to resolve the human-readable path for |
no test coverage detected