🐛 fix(vscode): 摘修复按 Gitea PR 提交列表分组

This commit is contained in:
cruldra committed 2026-09-01 18:53:41 +08:00
1 parent c0f8da5514
commit 4d3b2a0d67
6 files changed
+193 -34

No files matched your search

+6 -17
View File
@@ -25,6 +25,9 @@ export interface UnreleasedCommit {
author: string
date: string
body: string
/** Gitea 查到的所属 PR;没有就不分组。 */
pr?: number
prTitle?: string
}
export interface ReleaseCommitGroup {
@@ -79,34 +82,20 @@ export function pickCurrentRelease(prefix: string, remoteBranches: string[]): st
return remoteBranches.filter(b => b.startsWith(prefix)).sort().at(-1)
}
export function parsePrNumber(text: string): number | undefined {
const close = /\b(?:closes|fixes|resolves)\s+#(\d+)/i.exec(text)
if (close)
return Number(close[1])
const paren = /\(#(\d+)\)/.exec(text)
if (paren)
return Number(paren[1])
return undefined
}
function stripPrFromSubject(subject: string): string {
return subject.replace(/\s*\(#\d+\)\s*$/, '').trim()
}
/** 同 PR 收一组(新→旧首次出现顺序),认不出 PR 的进「未关联 PR」。 */
/** 同 PR 收一组(新→旧首次出现顺序)。pr 号来自 Gitea,不是扫提交说明。 */
export function groupCommitsByPr(commits: UnreleasedCommit[]): ReleaseCommitGroup[] {
const prGroups = new Map<number, ReleaseCommitGroup>()
const prOrder: number[] = []
const ungrouped: UnreleasedCommit[] = []
for (const c of commits) {
const pr = parsePrNumber(`${c.subject}\n${c.body}`)
const pr = c.pr
if (pr === undefined) {
ungrouped.push(c)
continue
}
let g = prGroups.get(pr)
if (!g) {
g = { pr, title: stripPrFromSubject(c.subject), authors: [], commits: [] }
g = { pr, title: c.prTitle?.trim() || c.subject, authors: [], commits: [] }
prGroups.set(pr, g)
prOrder.push(pr)
}