// Field mapping between MIME TODO issues and Bugzilla bugs import type { Issue, IssueType, IssueStatus, IssuePriority } from "../issue" import type { BugzillaCreatePayload, BugzillaUpdatePayload } from "./types" // Status mapping: TODO → Bugzilla const STATUS_TO_BZ: Record = { "open": { status: "CONFIRMED" }, "in-progress": { status: "IN_PROGRESS" }, "done": { status: "RESOLVED", resolution: "FIXED" }, "hold": { status: "RESOLVED", resolution: "LATER" }, "cancelled": { status: "RESOLVED", resolution: "WONTFIX" }, } // Priority mapping const PRIORITY_TO_BZ: Record = { "low": "Low", "medium": "Normal", "high": "Highest", } // Type → Severity mapping const TYPE_TO_SEVERITY: Record = { "feature": "enhancement", "bugfix": "normal", "hotfix": "critical", } export function statusToBugzilla(status: IssueStatus): { status: string; resolution?: string } { return STATUS_TO_BZ[status] ?? { status: "NEW" } } export function priorityToBugzilla(priority: IssuePriority): string { return PRIORITY_TO_BZ[priority] ?? "Normal" } export function typeToBugzilla(type: IssueType): string { return TYPE_TO_SEVERITY[type] ?? "normal" } export function resolveProductComponent( issue: Issue, bugzilla?: import("../tracker").BugzillaTracker ): { product: string; component: string } | null { if (!bugzilla) return null if (issue.module) { const mapping = bugzilla.mappings.find(m => m.module === issue.module) if (mapping) return { product: mapping.product, component: mapping.component } } // Fall back to first mapping return bugzilla.mappings.length > 0 ? { product: bugzilla.mappings[0].product, component: bugzilla.mappings[0].component } : null } export function issueToBugzillaCreate( issue: Issue, product: string, component: string, url?: string ): BugzillaCreatePayload { const bz = statusToBugzilla(issue.status) return { product, component, version: "unspecified", summary: issue.title, url, description: issue.description || undefined, priority: priorityToBugzilla(issue.priority), severity: typeToBugzilla(issue.type), op_sys: "All", rep_platform: "All", depends_on: issue.relationships.dependsOn ?? [], blocks: issue.relationships.blocks ?? [], see_also: (issue.relationships.relatesTo ?? []).map(String), } } export function issueToBugzillaUpdate(issue: Issue): BugzillaUpdatePayload { const bz = statusToBugzilla(issue.status) const payload: BugzillaUpdatePayload = { summary: issue.title, status: bz.status, priority: priorityToBugzilla(issue.priority), severity: typeToBugzilla(issue.type), depends_on: { set: issue.relationships.dependsOn ?? [] }, blocks: { set: issue.relationships.blocks ?? [] }, } if (bz.resolution) payload.resolution = bz.resolution return payload }