83 lines
2.8 KiB
TypeScript
83 lines
2.8 KiB
TypeScript
import type { AssetCategory } from './asset-classification'
|
|
import type { FileChange } from './types'
|
|
import type { PreparedAssetSummary } from './types'
|
|
|
|
/**
|
|
* Build a formatted commit message based on the upload context.
|
|
*
|
|
* Symbols:
|
|
* - ✅ = new file
|
|
* - 🔄 = modified file
|
|
* - ❌ = deleted file
|
|
* - Unchanged files are omitted entirely
|
|
*/
|
|
export function buildCommitMessage(
|
|
folderName: string,
|
|
modelFilename: string,
|
|
assetSummaries: PreparedAssetSummary[],
|
|
isReplace: boolean,
|
|
fileChanges: Map<string, FileChange>,
|
|
deletedFileNames: string[],
|
|
): string {
|
|
const title = isReplace
|
|
? `update: upload-gltf update -> ${folderName}`
|
|
: `update: upload-gltf add a new model -> ${folderName}`
|
|
|
|
const lines: string[] = [title, '']
|
|
|
|
// Model section — show status for new, changed, or unchanged
|
|
const modelSummary = assetSummaries.find((asset) => asset.kind === 'model')
|
|
const modelChange = fileChanges.get(modelFilename.toLowerCase())
|
|
if (modelChange === 'new') {
|
|
lines.push('📦 Model')
|
|
lines.push(` ✅ ${modelFilename}${modelSummary?.compressed ? ' (compressed)' : ''}`)
|
|
} else if (modelChange === 'changed') {
|
|
lines.push('📦 Model')
|
|
lines.push(` 🔄 ${modelFilename}${modelSummary?.compressed ? ' (compressed)' : ''}`)
|
|
} else if (modelChange === 'unchanged') {
|
|
lines.push('📦 Model')
|
|
lines.push(` ↔️ ${modelFilename}${modelSummary?.compressed ? ' (compressed)' : ' (inchange)'}`)
|
|
}
|
|
|
|
const grouped = new Map<AssetCategory, string[]>()
|
|
|
|
for (const asset of assetSummaries) {
|
|
if (asset.kind === 'model' || !asset.category) continue
|
|
|
|
const change = fileChanges.get(asset.filename.toLowerCase())
|
|
if (change === 'new') {
|
|
const current = grouped.get(asset.category) || []
|
|
current.push(` ✅ ${asset.filename}${asset.compressed ? ' (compressed)' : ''}`)
|
|
grouped.set(asset.category, current)
|
|
} else if (change === 'changed') {
|
|
const current = grouped.get(asset.category) || []
|
|
current.push(` 🔄 ${asset.filename}${asset.compressed ? ' (compressed)' : ''}`)
|
|
grouped.set(asset.category, current)
|
|
}
|
|
}
|
|
|
|
const sectionTitles: Record<AssetCategory, string> = {
|
|
color: '🎨 Textures (color)',
|
|
roughness: '🪶 Textures (roughness)',
|
|
normal: '🧭 Textures (normal)',
|
|
metalness: '🔩 Textures (metalness)',
|
|
assets: '🧩 Assets',
|
|
}
|
|
|
|
for (const category of ['color', 'roughness', 'normal', 'metalness', 'assets'] as const) {
|
|
const entries = grouped.get(category)
|
|
if (!entries || entries.length === 0) continue
|
|
lines.push('')
|
|
lines.push(sectionTitles[category])
|
|
lines.push(...entries)
|
|
}
|
|
|
|
if (deletedFileNames.length > 0) {
|
|
lines.push('')
|
|
lines.push('🗑 Deleted')
|
|
lines.push(...deletedFileNames.map((name) => ` ❌ ${name}`))
|
|
}
|
|
|
|
return lines.join('\n')
|
|
}
|