⚡ perf(vscode): 摘修复用本地合并记录分组,列表改手风琴
This commit is contained in:
1 parent
cfabee08b7
commit
5284fc1730
8 files changed
+183
-221
No files matched your search
@@ -82,7 +82,15 @@ export function pickCurrentRelease(prefix: string, remoteBranches: string[]): st
|
||||
return remoteBranches.filter(b => b.startsWith(prefix)).sort().at(-1)
|
||||
}
|
||||
|
||||
/** 同 PR 收一组(新→旧首次出现顺序)。pr 号来自 Gitea,不是扫提交说明。 */
|
||||
/** Gitea 默认合并说明:Merge pull request '标题' (#260) from … */
|
||||
export function parseGiteaMergeSubject(subject: string): { number: number, title: string } | undefined {
|
||||
const m = /^Merge pull request '(.+)' \(#(\d+)\)/.exec(subject)
|
||||
if (!m)
|
||||
return undefined
|
||||
return { title: m[1], number: Number(m[2]) }
|
||||
}
|
||||
|
||||
/** 同 PR 收一组(新→旧首次出现顺序)。pr 号来自合并记录,不是扫提交说明。 */
|
||||
export function groupCommitsByPr(commits: UnreleasedCommit[]): ReleaseCommitGroup[] {
|
||||
const prGroups = new Map<number, ReleaseCommitGroup>()
|
||||
const prOrder: number[] = []
|
||||
@@ -151,6 +159,56 @@ export async function listReleaseBranches(o: { cwd: string, prefix: string }): P
|
||||
return names.filter(b => b.startsWith(o.prefix)).sort().reverse()
|
||||
}
|
||||
|
||||
/** 用本地 merge 记录把未发布 sha 对上 PR。不打 Gitea。 */
|
||||
export async function indexUnreleasedByMergePr(o: {
|
||||
cwd: string
|
||||
current: string
|
||||
devBranch: string
|
||||
shas: readonly string[]
|
||||
}): Promise<Map<string, { number: number, title: string }>> {
|
||||
const needed = new Set(o.shas)
|
||||
const out = new Map<string, { number: number, title: string }>()
|
||||
if (needed.size === 0)
|
||||
return out
|
||||
const raw = await mustGit(
|
||||
o.cwd,
|
||||
['log', '--right-only', '--cherry-pick', '--merges', '--format=%H%x00%s', unreleasedRange(o.current, o.devBranch)],
|
||||
'读取合并记录失败',
|
||||
)
|
||||
if (!raw)
|
||||
return out
|
||||
for (const line of raw.split('\n')) {
|
||||
const [sha, subject] = line.split('\0')
|
||||
if (!sha || !subject)
|
||||
continue
|
||||
const parsed = parseGiteaMergeSubject(subject)
|
||||
if (!parsed)
|
||||
continue
|
||||
const members = await mustGit(
|
||||
o.cwd,
|
||||
['rev-list', '--no-merges', `${sha}^1..${sha}^2`],
|
||||
`读取 PR #${parsed.number} 提交失败`,
|
||||
)
|
||||
for (const member of members ? members.split('\n') : []) {
|
||||
if (needed.has(member))
|
||||
out.set(member, parsed)
|
||||
}
|
||||
if (out.size === needed.size)
|
||||
return out
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
export function attachPulls<T extends { sha: string }>(
|
||||
commits: T[],
|
||||
index: Map<string, { number: number, title: string }>,
|
||||
): Array<T & { pr?: number, prTitle?: string }> {
|
||||
return commits.map((c) => {
|
||||
const hit = index.get(c.sha)
|
||||
return hit ? { ...c, pr: hit.number, prTitle: hit.title } : c
|
||||
})
|
||||
}
|
||||
|
||||
export async function listUnreleasedCommits(o: { cwd: string, devBranch: string, current: string }): Promise<UnreleasedCommit[]> {
|
||||
const out = await mustGit(
|
||||
o.cwd,
|
||||
|
||||
Reference in new issue
Block a user