(end: Date)
| 88 | } |
| 89 | |
| 90 | async function generateChangelog(end: Date) { |
| 91 | // Fix: The start should be the beginning of the same week as 'end', not a week before |
| 92 | const start = getWeekStart(end) |
| 93 | |
| 94 | // Format dates for git log command |
| 95 | const startDate = formatDate(start, 'yyyy-MM-dd') |
| 96 | const endDate = formatDate(end, 'yyyy-MM-dd') |
| 97 | |
| 98 | console.log(`\n📅 Processing week ending ${endDate}...`) |
| 99 | |
| 100 | // Check if changelog already exists for this week |
| 101 | const changelogDir = path.join(process.cwd(), 'changelog') |
| 102 | fs.mkdirSync(changelogDir, { recursive: true }) |
| 103 | const existingFiles = fs.readdirSync(changelogDir) |
| 104 | const existingChangelog = existingFiles.find((file) => |
| 105 | file.startsWith(endDate), |
| 106 | ) |
| 107 | |
| 108 | if (existingChangelog) { |
| 109 | console.log( |
| 110 | `⏭️ Changelog already exists for week ending ${endDate}, skipping...`, |
| 111 | ) |
| 112 | return true // Return true to indicate we should continue |
| 113 | } |
| 114 | |
| 115 | try { |
| 116 | // First, get all commit hashes and titles |
| 117 | console.log(`🔍 Fetching commits from ${startDate} to ${endDate}...`) |
| 118 | const commitsCommand = `git log --pretty=format:"%h : %s" --since="${startDate}" --until="${endDate}"` |
| 119 | const commits = execSync(commitsCommand, { encoding: 'utf-8' }) |
| 120 | .split('\n') |
| 121 | .filter((line) => line.trim()) |
| 122 | |
| 123 | if (commits.length === 0) { |
| 124 | console.log(`💤 No commits found for week ending ${endDate}`) |
| 125 | return false // Return false to indicate we found a week with no commits |
| 126 | } |
| 127 | |
| 128 | console.log(`📝 Found ${commits.length} commits, processing details...`) |
| 129 | |
| 130 | // Process each commit |
| 131 | const processedCommits: string[] = [] |
| 132 | for (const commit of commits) { |
| 133 | const [hash] = commit.split(' : ') |
| 134 | |
| 135 | // Get full commit details including body, without diff |
| 136 | const detailsCommand = `git show ${hash} --pretty=format:"%B" --no-patch` |
| 137 | const details = execSync(detailsCommand, { encoding: 'utf-8' }) |
| 138 | .split('\n') |
| 139 | .filter((line) => line.trim()) |
| 140 | // Remove the first line (commit message) and any empty lines |
| 141 | .slice(1) |
| 142 | .filter((line) => line.trim()) |
| 143 | // Split by bullet points and format each one |
| 144 | .map((line) => line.replace(/^-+\s*/, '')) |
| 145 | .filter((line) => line.trim()) |
| 146 | .map((line) => ` - ${line}`) |
| 147 | .join('\n') |
no test coverage detected