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(); 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 // Given
mockOpts.pr = 456; mockOpts.pr = 456;
const emptyPrReview = createMockPrReview({ reviews: [], comments: [] }); const emptyPrReview = createMockPrReview({ reviews: [], comments: [] });
mockCheckCliStatus.mockReturnValue({ available: true }); mockCheckCliStatus.mockReturnValue({ available: true });
mockFetchPrReviewComments.mockReturnValue(emptyPrReview); mockFetchPrReviewComments.mockReturnValue(emptyPrReview);
const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => { // When
throw new Error('process.exit called'); await executeDefaultAction();
});
// When/Then // Then: PR title/description/files are still passed to interactive mode
await expect(executeDefaultAction()).rejects.toThrow('process.exit called'); expect(mockInteractiveMode).toHaveBeenCalledWith(
expect(mockExit).toHaveBeenCalledWith(1); '/test/cwd',
expect(mockInteractiveMode).not.toHaveBeenCalled(); expect.stringContaining('## PR #456 Review Comments:'),
expect.anything(),
mockExit.mockRestore(); undefined,
);
}); });
it('should not resolve issues when --pr is specified', async () => { it('should not resolve issues when --pr is specified', async () => {

View File

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

View File

@ -97,10 +97,6 @@ async function resolvePrInput(
async () => getGitProvider().fetchPrReviewComments(prNumber), 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) }; return { initialInput: formatPrReviewAsTask(prReview) };
} }

View File

@ -107,10 +107,6 @@ export function resolveTaskContent(options: PipelineExecutionOptions): TaskConte
(provider) => provider.fetchPrReviewComments(options.prNumber!), (provider) => provider.fetchPrReviewComments(options.prNumber!),
); );
if (!prReview) return undefined; 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); const task = formatPrReviewAsTask(prReview);
success(`PR #${options.prNumber} fetched: "${prReview.title}"`); success(`PR #${options.prNumber} fetched: "${prReview.title}"`);
return { task, prBranch: prReview.headRefName }; return { task, prBranch: prReview.headRefName };