mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 08:33:36 +00:00
fix: adress pr comments
This commit is contained in:
@@ -5,22 +5,14 @@
|
|||||||
|
|
||||||
import * as secureFs from './secure-fs.js';
|
import * as secureFs from './secure-fs.js';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import type { PRState, WorktreePRInfo } from '@automaker/types';
|
||||||
|
|
||||||
|
// Re-export types for backwards compatibility
|
||||||
|
export type { PRState, WorktreePRInfo };
|
||||||
|
|
||||||
/** Maximum length for sanitized branch names in filesystem paths */
|
/** Maximum length for sanitized branch names in filesystem paths */
|
||||||
const MAX_SANITIZED_BRANCH_PATH_LENGTH = 200;
|
const MAX_SANITIZED_BRANCH_PATH_LENGTH = 200;
|
||||||
|
|
||||||
/** GitHub PR states as returned by the GitHub API */
|
|
||||||
export type PRState = 'OPEN' | 'MERGED' | 'CLOSED';
|
|
||||||
|
|
||||||
export interface WorktreePRInfo {
|
|
||||||
number: number;
|
|
||||||
url: string;
|
|
||||||
title: string;
|
|
||||||
/** PR state: OPEN, MERGED, or CLOSED */
|
|
||||||
state: PRState;
|
|
||||||
createdAt: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorktreeMetadata {
|
export interface WorktreeMetadata {
|
||||||
branch: string;
|
branch: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
} from '../common.js';
|
} from '../common.js';
|
||||||
import { updateWorktreePRInfo } from '../../../lib/worktree-metadata.js';
|
import { updateWorktreePRInfo } from '../../../lib/worktree-metadata.js';
|
||||||
import { createLogger } from '@automaker/utils';
|
import { createLogger } from '@automaker/utils';
|
||||||
|
import { validatePRState } from '@automaker/types';
|
||||||
|
|
||||||
const logger = createLogger('CreatePR');
|
const logger = createLogger('CreatePR');
|
||||||
|
|
||||||
@@ -273,7 +274,7 @@ export function createCreatePRHandler() {
|
|||||||
number: existingPr.number,
|
number: existingPr.number,
|
||||||
url: existingPr.url,
|
url: existingPr.url,
|
||||||
title: existingPr.title || title,
|
title: existingPr.title || title,
|
||||||
state: existingPr.state || 'OPEN',
|
state: validatePRState(existingPr.state),
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@@ -359,7 +360,7 @@ export function createCreatePRHandler() {
|
|||||||
number: existingPr.number,
|
number: existingPr.number,
|
||||||
url: existingPr.url,
|
url: existingPr.url,
|
||||||
title: existingPr.title || title,
|
title: existingPr.title || title,
|
||||||
state: existingPr.state || 'OPEN',
|
state: validatePRState(existingPr.state),
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
});
|
});
|
||||||
logger.debug(`Fetched and stored existing PR: #${existingPr.number}`);
|
logger.debug(`Fetched and stored existing PR: #${existingPr.number}`);
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ import {
|
|||||||
readAllWorktreeMetadata,
|
readAllWorktreeMetadata,
|
||||||
updateWorktreePRInfo,
|
updateWorktreePRInfo,
|
||||||
type WorktreePRInfo,
|
type WorktreePRInfo,
|
||||||
type PRState,
|
|
||||||
} from '../../../lib/worktree-metadata.js';
|
} from '../../../lib/worktree-metadata.js';
|
||||||
import { createLogger } from '@automaker/utils';
|
import { createLogger } from '@automaker/utils';
|
||||||
|
import { validatePRState } from '@automaker/types';
|
||||||
import {
|
import {
|
||||||
checkGitHubRemote,
|
checkGitHubRemote,
|
||||||
type GitHubRemoteStatus,
|
type GitHubRemoteStatus,
|
||||||
@@ -221,7 +221,7 @@ async function fetchGitHubPRs(projectPath: string): Promise<Map<string, Worktree
|
|||||||
url: pr.url,
|
url: pr.url,
|
||||||
title: pr.title,
|
title: pr.title,
|
||||||
// GitHub CLI returns state as uppercase: OPEN, MERGED, CLOSED
|
// GitHub CLI returns state as uppercase: OPEN, MERGED, CLOSED
|
||||||
state: pr.state as PRState,
|
state: validatePRState(pr.state),
|
||||||
createdAt: pr.createdAt,
|
createdAt: pr.createdAt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
/** GitHub PR states as returned by the GitHub API */
|
// Re-export shared types from @automaker/types
|
||||||
export type PRState = 'OPEN' | 'MERGED' | 'CLOSED';
|
export type { PRState, WorktreePRInfo } from '@automaker/types';
|
||||||
|
import type { PRState, WorktreePRInfo } from '@automaker/types';
|
||||||
export interface WorktreePRInfo {
|
|
||||||
number: number;
|
|
||||||
url: string;
|
|
||||||
title: string;
|
|
||||||
/** PR state: OPEN, MERGED, or CLOSED */
|
|
||||||
state: PRState;
|
|
||||||
createdAt: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WorktreeInfo {
|
export interface WorktreeInfo {
|
||||||
path: string;
|
path: string;
|
||||||
|
|||||||
@@ -292,3 +292,7 @@ export type {
|
|||||||
EventReplayHookResult,
|
EventReplayHookResult,
|
||||||
} from './event-history.js';
|
} from './event-history.js';
|
||||||
export { EVENT_HISTORY_VERSION, DEFAULT_EVENT_HISTORY_INDEX } 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