mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
56df64c751
Adds current-architecture GitButler workspace, stack, and branch review support across Bun and Pi while preserving the existing Git, JJ, and P4 paths. Co-authored-by: Dan Susman <56033661+dansusman@users.noreply.github.com>
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { useMemo, useCallback } from 'react';
|
|
import { getDisplayRepo } from '@plannotator/shared/pr-types';
|
|
import type { PRMetadata } from '@plannotator/shared/pr-types';
|
|
import type { PRDiffScope } from '@plannotator/shared/pr-stack';
|
|
import type { CodeAnnotation } from '@plannotator/ui/types';
|
|
|
|
/** The active commit diff, if any — stamped onto annotations created while a
|
|
* commit:<sha> diff is on screen. Mirrors the PR fields: both exist so an
|
|
* in-place context switch (PR switch / diff-type switch) can't silently
|
|
* re-anchor old annotations to a diff they weren't made on. */
|
|
export interface CommitAnnotationContext {
|
|
sha: string;
|
|
subject?: string;
|
|
}
|
|
|
|
export interface GitButlerAnnotationContext {
|
|
diffType: string;
|
|
label?: string;
|
|
base?: string;
|
|
snapshotId?: string;
|
|
}
|
|
|
|
export function useAnnotationFactory(
|
|
prMetadata: PRMetadata | null,
|
|
diffScope?: PRDiffScope,
|
|
commitContext?: CommitAnnotationContext | null,
|
|
gitButlerContext?: GitButlerAnnotationContext | null,
|
|
) {
|
|
const prContext = useMemo(() => ({
|
|
...(prMetadata ? {
|
|
prUrl: prMetadata.url,
|
|
prNumber: prMetadata.platform === 'github' ? prMetadata.number : prMetadata.iid,
|
|
prTitle: prMetadata.title,
|
|
prRepo: getDisplayRepo(prMetadata),
|
|
...(diffScope ? { diffScope } : {}),
|
|
} : {}),
|
|
...(commitContext ? {
|
|
commitSha: commitContext.sha,
|
|
...(commitContext.subject ? { commitSubject: commitContext.subject } : {}),
|
|
} : {}),
|
|
...(gitButlerContext ? {
|
|
gitButlerDiffType: gitButlerContext.diffType,
|
|
...(gitButlerContext.label ? { gitButlerDiffLabel: gitButlerContext.label } : {}),
|
|
...(gitButlerContext.base ? { gitButlerBase: gitButlerContext.base } : {}),
|
|
...(gitButlerContext.snapshotId ? { gitButlerSnapshotId: gitButlerContext.snapshotId } : {}),
|
|
} : {}),
|
|
}), [prMetadata, diffScope, commitContext, gitButlerContext]);
|
|
|
|
const withPRContext = useCallback(
|
|
(annotation: CodeAnnotation): CodeAnnotation => ({ ...annotation, ...prContext }),
|
|
[prContext],
|
|
);
|
|
|
|
return { withPRContext };
|
|
}
|