feat: templates per ticket type

Each ticket type can carry a starting description and a checklist, edited
in the project settings. New tickets of that type get the description
when they come without one and always get the checklist; the new ticket
form says what the template will add.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 15:58:37 +02:00
parent 8994590b54
commit 5863d773be
23 changed files with 565 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ import {
IssueType,
ProjectRole,
TRACKER_FACTORIES,
defaultProjectSettings,
} from '@task-stream/api/tracker/domain';
import {
FakeUserDirectory,
@@ -77,6 +78,7 @@ import { DeleteCommentCommand } from './delete-comment.command';
import { PublishReleaseCommand } from './publish-release.command';
import { SetIssueReleaseCommand } from './set-issue-release.command';
import { WriteAccess } from './write-access';
import { UpdateProjectSettingsCommand } from './update-project-settings.command';
import { ReadAccess } from '../queries/read-access';
import { FindProjectsRepository } from '../ports/find-projects.repository';
@@ -595,6 +597,35 @@ describe('tracker commands (event sourced)', () => {
).toBe('No sprint is under way');
});
it("fills a new ticket with its type's template", async () => {
const { run, rehydrator } = await setup();
const projectId = await projectWithTeam(run);
const settings = defaultProjectSettings();
settings.issueTypes[0].template = {
description: '## Pasos para reproducir',
checklist: ['Probar en Safari', 'Adjuntar captura'],
};
await run(new UpdateProjectSettingsCommand('owner', projectId, settings));
const plain = await run(
new CreateIssueCommand('qa', projectId, IssueType.BUG, 'Crash', {}),
);
const written = await run(
new CreateIssueCommand('qa', projectId, IssueType.BUG, 'Crash 2', {
description: 'Ya lo explico yo',
}),
);
const first = await rehydrator.rehydrate(plain.id, Issue);
expect(first.description).toBe('## Pasos para reproducir');
expect(first.checklist.map((i) => i.text)).toEqual([
'Probar en Safari',
'Adjuntar captura',
]);
expect((await rehydrator.rehydrate(written.id, Issue)).description).toBe(
'Ya lo explico yo',
);
});
it('does not let viewers modify tickets', async () => {
const { run } = await setup();
const projectId = await projectWithTeam(run);

View File

@@ -1,3 +1,4 @@
import { randomUUID } from 'node:crypto';
import { CommandHandler, EventPublisher, ICommandHandler } from '@nestjs/cqrs';
import { IssueFactory, assertCanNest } from '@task-stream/api/tracker/domain';
import { IssueNumbersRepository } from '../ports/issue-numbers.repository';
@@ -39,9 +40,14 @@ export class CreateIssueCommandHandler
0,
);
const template = command.useTemplate
? workflow.templateOf(command.type)
: null;
const issue = this.issueFactory.create(
{
...command.details,
description:
command.details.description?.trim() || template?.description || null,
projectId: project.id,
projectKey: project.key,
number: await this.issueNumbers.next(project.id),
@@ -55,6 +61,8 @@ export class CreateIssueCommandHandler
);
if (command.releaseId) issue.setRelease(command.actorId, command.releaseId);
if (parent) issue.setParent(command.actorId, parent);
for (const step of template?.checklist ?? [])
issue.addChecklistItem(command.actorId, randomUUID(), step);
this.eventPublisher.mergeObjectContext(issue);
await issue.commitAndWait();

View File

@@ -16,6 +16,8 @@ export class CreateIssueCommand extends Command<CommandResult> {
public readonly parentId?: string | null,
/** Imports only: start in this (active) status instead of the first one. */
public readonly initialStatus?: string | null,
/** Fill in the type's template (imports bring their own content). */
public readonly useTemplate = true,
) {
super();
}

View File

@@ -115,6 +115,7 @@ export class ImportIssuesCommandHandler
null,
null,
row.status,
false,
),
);
report.created++;