feat(api): allow template_name when creating project tasks via API - #4128
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughTask creation now accepts ChangesTask template resolution and uniqueness
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant AddTask
participant resolveTaskTemplate
participant TemplateManager
participant SqlDb
AddTask->>resolveTaskTemplate: Resolve template_id or template_name
resolveTaskTemplate->>TemplateManager: Request project-scoped template
TemplateManager->>SqlDb: Get template by ID or name
SqlDb-->>TemplateManager: Return template or error
TemplateManager-->>resolveTaskTemplate: Return resolved template
resolveTaskTemplate-->>AddTask: Set TemplateID and continue task creation
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…mplate_name-when-creating-project-tasks-via-api
There was a problem hiding this comment.
Pull request overview
This PR extends the Semaphore API task-creation flow to allow referencing a template by template_name in addition to template_id, with template_id taking precedence when both are provided. It adds database lookup support for resolving templates by name, updates API documentation accordingly, and introduces tests covering the new resolution behavior and edge cases.
Changes:
- Add
template_namesupport for task creation, resolving totemplate_idbefore the task enters the existing execution pipeline. - Add
GetTemplateByName(projectID, name)to the store interface with SQL implementation that rejects ambiguous names. - Update Swagger docs (both locations) and add API tests validating precedence and failure cases.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| web/public/swagger/api-docs.yml | Documents template_name support and precedence rules for task creation (web copy). |
| api-docs.yml | Documents template_name support and precedence rules for task creation (root copy). |
| db/Task.go | Adds TemplateName as a non-persisted field on db.Task and relaxes TemplateID struct-tag requirement. |
| db/Store.go | Extends TemplateManager with GetTemplateByName. |
| db/sql/template.go | Implements name-based template lookup with ambiguity detection. |
| api/projects/tasks.go | Adds template resolution helper used by the task-create API handler. |
| api/projects/tasks_test.go | Adds unit tests for template resolution by id/name, precedence, and error cases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@befika I think we also need to add new template name uniqueness validation. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (2)
api/projects/tasks.go:60
- A successful resolution leaves the request-only
TemplateNameon the task.TaskPool.AddTaskpasses that value throughCreateTask, which copies the struct, so the 201 response echoestemplate_name; when both fields were supplied it can even echo the ignored or invalid name. Clear it after resolving so task responses remain canonical and match subsequent reads.
if task.TemplateID != 0 {
tpl, err = c.store.GetTemplate(projectID, task.TemplateID)
return
}
tpl, err = c.store.GetTemplateByName(projectID, task.TemplateName)
if err != nil {
return
}
task.TemplateID = tpl.ID
return
api/projects/tasks.go:42
- The existing
AddTasksentence is now attached toresolveTaskTemplate's Go documentation, incorrectly claiming that this helper inserts a task and returns a header. Keep the resolver description here and move theAddTaskdescription back aboveAddTask.
// resolveTaskTemplate returns the template of the task, which may be referenced
// either by id or by name. The resolved id is written back to the task so the
// rest of the pipeline only deals with ids.
…-via-api' of github.com:befika/semaphore into sem-207-allow-template_name-when-creating-project-tasks-via-api
…uplicates during migration
Template names are now unique per project. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@db/sql/migration_2_20_2.go`:
- Around line 39-73: The duplicate tracking in migration 2.20.2 uses byte-exact
Go keys instead of the database’s case- and space-insensitive collation rules.
Update the reservation and generated-suffix checks in the duplicate-renaming
logic of migration_2_20_2.go to compare names using equivalent MySQL/MariaDB
collation semantics, then add a MySQL/MariaDB migration test in
migration_2_20_2_test.go covering collisions such as “Build”/“build” and
“Build”/“Build ” and verifying the generated names avoid unique-index conflicts.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d2fd0b8b-ede1-449b-8491-4d418466d145
📒 Files selected for processing (8)
api/projects/tasks_test.godb/Migration.godb/sql/migration.godb/sql/migration_2_20_2.godb/sql/migration_2_20_2_test.godb/sql/migrations/v2.20.2.sqldb/sql/template.godb/sql/template_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- api/projects/tasks_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
.dredd/hooks/capabilities.go (1)
297-299: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winPreserve an opt-out for name-sensitive Dredd transactions.
This rewrites every existing
namefield for matching template PUT requests. The API contract exposesnamein the template PUT body, so Dredd cannot send the documented value unchanged. (raw.githubusercontent.com)Restrict this rewrite to fixture setup transactions, or add an explicit opt-out. Keep a negative case that sends a duplicate name unchanged so the new uniqueness validation remains covered.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.dredd/hooks/capabilities.go around lines 297 - 299, The template PUT handling in the Dredd hook currently rewrites every name field, preventing name-sensitive transactions from sending documented values unchanged. Update the logic around bodyFieldProcessor to apply the rewrite only to fixture-setup transactions or honor an explicit opt-out, while preserving a negative duplicate-name transaction that bypasses rewriting and exercises uniqueness validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.dredd/hooks/capabilities.go:
- Around line 297-299: The template PUT handling in the Dredd hook currently
rewrites every name field, preventing name-sensitive transactions from sending
documented values unchanged. Update the logic around bodyFieldProcessor to apply
the rewrite only to fixture-setup transactions or honor an explicit opt-out,
while preserving a negative duplicate-name transaction that bypasses rewriting
and exercises uniqueness validation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 44d010ea-0d1f-4157-b809-5e4f7abda4b4
📒 Files selected for processing (1)
.dredd/hooks/capabilities.go
…-project-tasks-via-api
|
Looks really cool. Will merge ASAP. |
Summary by CodeRabbit
New Features
Migration
Documentation