mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-01-30 06:12:03 +00:00
fix: adress pr comments
This commit is contained in:
@@ -292,3 +292,7 @@ export type {
|
||||
EventReplayHookResult,
|
||||
} from './event-history.js';
|
||||
export { EVENT_HISTORY_VERSION, DEFAULT_EVENT_HISTORY_INDEX } from './event-history.js';
|
||||
|
||||
// Worktree and PR types
|
||||
export type { PRState, WorktreePRInfo } from './worktree.js';
|
||||
export { PR_STATES, validatePRState } from './worktree.js';
|
||||
|
||||
32
libs/types/src/worktree.ts
Normal file
32
libs/types/src/worktree.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Worktree and PR-related types
|
||||
* Shared across server and UI components
|
||||
*/
|
||||
|
||||
/** GitHub PR states as returned by the GitHub API (uppercase) */
|
||||
export type PRState = 'OPEN' | 'MERGED' | 'CLOSED';
|
||||
|
||||
/** Valid PR states for validation */
|
||||
export const PR_STATES: readonly PRState[] = ['OPEN', 'MERGED', 'CLOSED'] as const;
|
||||
|
||||
/**
|
||||
* Validates a PR state value from external APIs (e.g., GitHub CLI).
|
||||
* Returns the validated state if it matches a known PRState, otherwise returns 'OPEN' as default.
|
||||
* This is safer than type assertions as it handles unexpected values from external APIs.
|
||||
*
|
||||
* @param state - The state string to validate (can be any string)
|
||||
* @returns A valid PRState value
|
||||
*/
|
||||
export function validatePRState(state: string | undefined | null): PRState {
|
||||
return PR_STATES.find((s) => s === state) ?? 'OPEN';
|
||||
}
|
||||
|
||||
/** PR information stored in worktree metadata */
|
||||
export interface WorktreePRInfo {
|
||||
number: number;
|
||||
url: string;
|
||||
title: string;
|
||||
/** PR state: OPEN, MERGED, or CLOSED */
|
||||
state: PRState;
|
||||
createdAt: string;
|
||||
}
|
||||
Reference in New Issue
Block a user