fix: レビューコメントがない PR でも --pr が機能するよう修正

This commit is contained in:
nrslib 2026-03-02 22:02:55 +09:00
parent 47612d9dcc
commit 8edf8b02d8
4 changed files with 14 additions and 20 deletions

View File

@ -213,23 +213,23 @@ describe('PR resolution in routing', () => {
mockExit.mockRestore();
});
it('should exit with error when PR has no review comments', async () => {
it('should pass to interactive mode even when PR has no review comments', async () => {
// Given
mockOpts.pr = 456;
const emptyPrReview = createMockPrReview({ reviews: [], comments: [] });
mockCheckCliStatus.mockReturnValue({ available: true });
mockFetchPrReviewComments.mockReturnValue(emptyPrReview);
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => {
throw new Error('process.exit called');
});
// When
await executeDefaultAction();
// When/Then
await expect(executeDefaultAction()).rejects.toThrow('process.exit called');
expect(mockExit).toHaveBeenCalledWith(1);
expect(mockInteractiveMode).not.toHaveBeenCalled();
mockExit.mockRestore();
// Then: PR title/description/files are still passed to interactive mode
expect(mockInteractiveMode).toHaveBeenCalledWith(
'/test/cwd',
expect.stringContaining('## PR #456 Review Comments:'),
expect.anything(),
undefined,
);
});
it('should not resolve issues when --pr is specified', async () => {

View File

@ -863,7 +863,7 @@ describe('executePipeline', () => {
expect(exitCode).toBe(2);
});
it('should return exit code 2 when PR has no review comments', async () => {
it('should succeed even when PR has no review comments', async () => {
mockFetchPrReviewComments.mockReturnValueOnce({
number: 456,
title: 'Fix auth bug',
@ -874,6 +874,7 @@ describe('executePipeline', () => {
reviews: [],
files: ['src/auth.ts'],
});
mockExecuteTask.mockResolvedValueOnce(true);
const exitCode = await executePipeline({
prNumber: 456,
@ -882,7 +883,8 @@ describe('executePipeline', () => {
cwd: '/tmp/test',
});
expect(exitCode).toBe(2);
expect(exitCode).toBe(0);
expect(mockFormatPrReviewAsTask).toHaveBeenCalled();
});
it('should return exit code 2 when PR fetch fails', async () => {

View File

@ -97,10 +97,6 @@ async function resolvePrInput(
async () => getGitProvider().fetchPrReviewComments(prNumber),
);
if (prReview.reviews.length === 0 && prReview.comments.length === 0) {
throw new Error(`PR #${prNumber} has no review comments`);
}
return { initialInput: formatPrReviewAsTask(prReview) };
}

View File

@ -107,10 +107,6 @@ export function resolveTaskContent(options: PipelineExecutionOptions): TaskConte
(provider) => provider.fetchPrReviewComments(options.prNumber!),
);
if (!prReview) return undefined;
if (prReview.reviews.length === 0 && prReview.comments.length === 0) {
error(`PR #${options.prNumber} has no review comments`);
return undefined;
}
const task = formatPrReviewAsTask(prReview);
success(`PR #${options.prNumber} fetched: "${prReview.title}"`);
return { task, prBranch: prReview.headRefName };