takt: tasuku-taktga-surupull-request (#336)

This commit is contained in:
nrs 2026-02-22 21:52:40 +09:00 committed by GitHub
parent b309233aeb
commit 4a7dea48ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 5 deletions

View File

@ -173,6 +173,63 @@ describe('postExecutionFlow', () => {
expect(result.prFailed).toBeUndefined(); expect(result.prFailed).toBeUndefined();
expect(result.prUrl).toBe('https://github.com/org/repo/pull/1'); expect(result.prUrl).toBe('https://github.com/org/repo/pull/1');
}); });
it('issues が渡された場合、PRタイトルにIssue番号プレフィックスが付与される', async () => {
mockFindExistingPr.mockReturnValue(undefined);
await postExecutionFlow({
...baseOptions,
task: 'Fix the bug',
issues: [{ number: 123, title: 'This title should not appear in PR', body: '', labels: [], comments: 0 }],
});
expect(mockCreatePullRequest).toHaveBeenCalledWith(
'/project',
expect.objectContaining({ title: '[#123] Fix the bug' }),
);
});
it('issues が空配列の場合、PRタイトルにプレフィックスは付与されない', async () => {
mockFindExistingPr.mockReturnValue(undefined);
await postExecutionFlow({
...baseOptions,
issues: [],
});
expect(mockCreatePullRequest).toHaveBeenCalledWith(
'/project',
expect.objectContaining({ title: 'Fix the bug' }),
);
});
it('issues が undefined の場合、PRタイトルにプレフィックスは付与されない', async () => {
mockFindExistingPr.mockReturnValue(undefined);
await postExecutionFlow(baseOptions);
expect(mockCreatePullRequest).toHaveBeenCalledWith(
'/project',
expect.objectContaining({ title: 'Fix the bug' }),
);
});
it('Issueプレフィックス付きタイトルが100文字を超える場合、適切に省略される', async () => {
mockFindExistingPr.mockReturnValue(undefined);
const longTask = 'A'.repeat(120);
const expectedTitle = `[#123] ${'A'.repeat(90)}...`;
await postExecutionFlow({
...baseOptions,
task: longTask,
issues: [{ number: 123, title: 'Long issue', body: '', labels: [], comments: 0 }],
});
expect(mockCreatePullRequest).toHaveBeenCalledWith(
'/project',
expect.objectContaining({ title: expectedTitle }),
);
});
}); });
describe('resolveDraftPr', () => { describe('resolveDraftPr', () => {

View File

@ -211,7 +211,7 @@ export function submitPullRequest(
options: Pick<PipelineExecutionOptions, 'task' | 'repo' | 'draftPr'>, options: Pick<PipelineExecutionOptions, 'task' | 'repo' | 'draftPr'>,
): string | undefined { ): string | undefined {
info('Creating pull request...'); info('Creating pull request...');
const prTitle = taskContent.issue ? taskContent.issue.title : (options.task ?? 'Pipeline task'); const prTitle = taskContent.issue ? `[#${taskContent.issue.number}] ${taskContent.issue.title}` : (options.task ?? 'Pipeline task');
const report = `Piece \`${piece}\` completed successfully.`; const report = `Piece \`${piece}\` completed successfully.`;
const prBody = buildPipelinePrBody(pipelineConfig, taskContent.issue, report); const prBody = buildPipelinePrBody(pipelineConfig, taskContent.issue, report);

View File

@ -103,9 +103,13 @@ export async function postExecutionFlow(options: PostExecutionOptions): Promise<
} else { } else {
info('Creating pull request...'); info('Creating pull request...');
const prBody = buildPrBody(issues, report); const prBody = buildPrBody(issues, report);
const firstIssue = issues?.[0];
const issuePrefix = firstIssue ? `[#${firstIssue.number}] ` : '';
const truncatedTask = task.length > 100 - issuePrefix.length ? `${task.slice(0, 100 - issuePrefix.length - 3)}...` : task;
const prTitle = issuePrefix + truncatedTask;
const prResult = createPullRequest(projectCwd, { const prResult = createPullRequest(projectCwd, {
branch, branch,
title: task.length > 100 ? `${task.slice(0, 97)}...` : task, title: prTitle,
body: prBody, body: prBody,
base: baseBranch, base: baseBranch,
repo, repo,

View File

@ -29,9 +29,8 @@ function toRomajiSafely(text: string): string {
); );
} }
return convertedChunks.join(''); return convertedChunks.join('');
} catch { } catch (err) {
// Avoid blocking branch/task creation on rare parser edge cases or deep recursion log.error('Failed to convert to romaji', { error: err, textLength: text.length });
// with very long mixed/ASCII inputs.
return text; return text;
} }
} }