Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions scripts/generate-monthly-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,22 @@ async function main() {
}

const summaries: string[] = []
const prsWithImages: { repo: string; number: number; image: string }[] = []
for (const file of files) {
const prs = JSON.parse(fs.readFileSync(path.join(prDir, file), "utf8"))
for (const pr of prs) {
summaries.push(`- ${pr.repo} #${pr.number}: ${pr.title}`)

const body: string = pr.body || ""
const afterIndex = body.toLowerCase().indexOf("after")
const searchText = afterIndex >= 0 ? body.slice(afterIndex) : body
const imageRegex =
/!\[[^\]]*?\]\((https?:\/\/[^)]+)\)|(https?:\/\/\S+?\.(?:png|jpg|jpeg|gif|svg))/i
const match = searchText.match(imageRegex) || body.match(imageRegex)
const image = match?.[1] || match?.[2]
if (image) {
prsWithImages.push({ repo: pr.repo, number: pr.number, image })
}
}
}

Expand All @@ -57,10 +69,26 @@ async function main() {
outDir,
`${year}-${month.toString().padStart(2, "0")}.md`,
)
fs.writeFileSync(
filePath,
`# Changelog ${year}-${month.toString().padStart(2, "0")}\n\n${object.changelog}\n`,
)
let changelog = `# Changelog ${year}-${month.toString().padStart(2, "0")}\n\n${object.changelog}\n`

const escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
for (const pr of prsWithImages) {
const slug = `${pr.repo.replace(/\//g, "-")}-${pr.number}`
const linkRegex = new RegExp(
`(https://github.com/${escapeRegExp(pr.repo)}/pull/${pr.number}\))`,
)
changelog = changelog.replace(linkRegex, `$1 [(image)](#${slug})`)
}

if (prsWithImages.length > 0) {
changelog += "\n## PR Images\n\n"
for (const pr of prsWithImages) {
const slug = `${pr.repo.replace(/\//g, "-")}-${pr.number}`
changelog += `### ${slug}\n\n![image](${pr.image})\n\n`
}
}

fs.writeFileSync(filePath, changelog)
console.log(`Updated ${filePath}`)
}

Expand Down