Ticket contract for automated reporters: dedup_key, source, links, reopen window (#123)
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 44s
Lint / PHP requirements (version + extensions) (push) Successful in 42s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m15s
Lint / JS (eslint) (pull_request) Successful in 34s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 42s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 4m13s
Security / PHP Security (semgrep) (pull_request) Successful in 3m25s
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 44s
Lint / PHP requirements (version + extensions) (push) Successful in 42s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m15s
Lint / JS (eslint) (pull_request) Successful in 34s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 42s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 4m13s
Security / PHP Security (semgrep) (pull_request) Successful in 3m25s
From the thor#1 plan: each reporter (gandalf, hwmonDaemon, thor) decides
what "the same problem" is, and Tinker enforces it.
- dedup_key on create_ticket_api.php (scope:subject:kind, A-Za-z0-9_.:-,
case-sensitive). The hash becomes sha256("key:" + key) and the title is
not looked at; an invalid key is a 400. Keyless callers hash exactly as
before (checked over every prod title).
- Recurrence window for every reporter, keyed or not: a match on a ticket
closed under AUTO_REOPEN_WINDOW_DAYS (7) ago reopens it as before
(subject to the Workflow Designer); an older one gets a new ticket that
takes over the dedup slot (tickets.hash stays UNIQUE, the old ticket
gives it up), carries the key, records recurrence_of, is linked
relates_to, and gets a history comment. action: new_recurrence.
- GET api/tickets_api.php?dedup_key= returns the newest ticket with that
key plus its recurrence chain; ?source= filters the list.
- New api/ticket_link_api.php (link/unlink, read_write) through
DependencyService::link()/unlink(), now shared with MCP
link_tickets/unlink_tickets; audit rows record the key name.
- tickets.source records the API key name. Shown as the creator instead of
"System" on the dashboard and ticket page, a Source filter in the
sidebar, source in MCP results and a search_tickets filter. Comments the
create API writes name the reporter instead of a hard-coded
"hwmonDaemon", and system-linked comments display that name.
- Migration 008 (dedup_key, source, recurrence_of). Scripts:
backfill_ticket_source.php (pre-#123 tickets, where certain) and
backfill_dedup_keys.php (mapping file supplied by the app).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13ffc51cb7
commit
7061c40d4d
20 files changed
+1025
-206
No files matched your search
@@ -26,6 +26,7 @@ final class TicketReadTools
|
||||
* @param int|null $priority Exact priority: 1 (critical) to 5 (minimal).
|
||||
* @param string|null $category Exact category name.
|
||||
* @param string|null $assignee "me", "unassigned", or a username.
|
||||
* @param string|null $source Reporter that created the ticket through the API, e.g. "gandalf", "hwmonDaemon", "thor". Comma-separated for several.
|
||||
* @param int $page Page number, starting at 1.
|
||||
* @param int $limit Tickets per page, 1-50.
|
||||
*
|
||||
@@ -37,6 +38,7 @@ final class TicketReadTools
|
||||
?int $priority = null,
|
||||
?string $category = null,
|
||||
?string $assignee = null,
|
||||
?string $source = null,
|
||||
int $page = 1,
|
||||
int $limit = 20,
|
||||
): array {
|
||||
@@ -68,6 +70,9 @@ final class TicketReadTools
|
||||
if ($assignee !== null && trim($assignee) !== '') {
|
||||
$filters['assigned_to'] = $this->resolveAssigneeFilter(trim($assignee), $user);
|
||||
}
|
||||
if ($source !== null && trim($source) !== '') {
|
||||
$filters['source'] = explode(',', $source);
|
||||
}
|
||||
|
||||
$page = max(1, $page);
|
||||
$limit = min(50, max(1, $limit));
|
||||
@@ -140,7 +145,7 @@ final class TicketReadTools
|
||||
$details['comment_count'] = count($comments);
|
||||
$details['comments'] = array_map(fn(array $c) => [
|
||||
'comment_id' => (int)$c['comment_id'],
|
||||
'author' => $c['display_name'] ?? $c['username'] ?? $c['user_name'] ?? null,
|
||||
'author' => $c['display_name_formatted'] ?? $c['display_name'] ?? $c['username'] ?? $c['user_name'] ?? null,
|
||||
'created_at' => $c['created_at'] ?? null,
|
||||
'reply_to' => isset($c['parent_comment_id']) ? (int)$c['parent_comment_id'] : null,
|
||||
'text' => $c['comment_text'] ?? '',
|
||||
@@ -275,6 +280,7 @@ final class TicketReadTools
|
||||
'visibility' => $t['visibility'] ?? 'public',
|
||||
'assigned_to' => $t['assigned_display_name'] ?? $t['assigned_username'] ?? null,
|
||||
'created_by' => $t['creator_display_name'] ?? $t['creator_username'] ?? null,
|
||||
'source' => $t['source'] ?? null,
|
||||
'created_at' => $t['created_at'] ?? null,
|
||||
'updated_at' => $t['updated_at'] ?? null,
|
||||
'url' => \UrlHelper::ticketUrl((string)$t['ticket_id']),
|
||||
|
||||
@@ -252,22 +252,12 @@ final class TicketWriteTools
|
||||
*/
|
||||
public function linkTickets(string $ticket_id, string $relation, string $other_ticket_id): array
|
||||
{
|
||||
$user = McpIdentity::user();
|
||||
[$ticketId, $otherId, $relation] = $this->linkArgs($ticket_id, $relation, $other_ticket_id);
|
||||
|
||||
$result = \DependencyService::add($this->conn, $user, [
|
||||
'ticket_id' => $ticketId,
|
||||
'depends_on_id' => $otherId,
|
||||
'dependency_type' => $relation,
|
||||
]);
|
||||
$result = \DependencyService::link($this->conn, McpIdentity::user(), $ticket_id, $relation, $other_ticket_id);
|
||||
if (empty($result['success'])) {
|
||||
if (($result['error'] ?? '') === 'Target ticket not found') {
|
||||
throw new ToolCallException("Ticket {$otherId} not found");
|
||||
}
|
||||
throw new ToolCallException($this->errorMessage($result, $ticketId));
|
||||
throw new ToolCallException((string)$result['error']);
|
||||
}
|
||||
|
||||
return ['ticket_id' => $ticketId, 'relation' => $relation, 'other_ticket_id' => $otherId];
|
||||
return ['ticket_id' => $result['ticket_id'], 'relation' => $result['relation'], 'other_ticket_id' => $result['other_ticket_id']];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,56 +273,17 @@ final class TicketWriteTools
|
||||
*/
|
||||
public function unlinkTickets(string $ticket_id, string $relation, string $other_ticket_id): array
|
||||
{
|
||||
$user = McpIdentity::user();
|
||||
[$ticketId, $otherId, $relation] = $this->linkArgs($ticket_id, $relation, $other_ticket_id);
|
||||
|
||||
// The same relationship can be stored from either ticket. duplicates
|
||||
// has no inverse type, so it is only ever stored one way.
|
||||
$inverse = ['blocks' => 'blocked_by', 'blocked_by' => 'blocks', 'relates_to' => 'relates_to'];
|
||||
$attempts = [[$ticketId, $otherId, $relation]];
|
||||
if (isset($inverse[$relation])) {
|
||||
$attempts[] = [$otherId, $ticketId, $inverse[$relation]];
|
||||
$result = \DependencyService::unlink($this->conn, McpIdentity::user(), $ticket_id, $relation, $other_ticket_id);
|
||||
if (empty($result['success'])) {
|
||||
throw new ToolCallException((string)$result['error']);
|
||||
}
|
||||
|
||||
$removed = 0;
|
||||
foreach ($attempts as [$from, $to, $type]) {
|
||||
$result = \DependencyService::remove($this->conn, $user, [
|
||||
'ticket_id' => $from,
|
||||
'depends_on_id' => $to,
|
||||
'dependency_type' => $type,
|
||||
]);
|
||||
if (empty($result['success'])) {
|
||||
throw new ToolCallException($this->errorMessage($result, $from));
|
||||
}
|
||||
$removed += (int)$result['removed'];
|
||||
}
|
||||
if ($removed === 0) {
|
||||
throw new ToolCallException("No {$relation} link between {$ticketId} and {$otherId}");
|
||||
}
|
||||
|
||||
return ['ticket_id' => $ticketId, 'relation' => $relation, 'other_ticket_id' => $otherId, 'removed' => true];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0:string,1:string,2:string}
|
||||
*/
|
||||
private function linkArgs(string $ticketId, string $relation, string $otherId): array
|
||||
{
|
||||
$ticketId = trim($ticketId);
|
||||
$otherId = trim($otherId);
|
||||
$relation = strtolower(trim($relation));
|
||||
if (!in_array($relation, \DependencyService::TYPES, true)) {
|
||||
throw new ToolCallException('relation must be one of: ' . implode(', ', \DependencyService::TYPES));
|
||||
}
|
||||
foreach ([$ticketId, $otherId] as $id) {
|
||||
if (!ctype_digit($id)) {
|
||||
throw new ToolCallException("Ticket {$id} not found");
|
||||
}
|
||||
}
|
||||
if ($ticketId === $otherId) {
|
||||
throw new ToolCallException('A ticket cannot be linked to itself');
|
||||
}
|
||||
return [$ticketId, $otherId, $relation];
|
||||
return [
|
||||
'ticket_id' => $result['ticket_id'],
|
||||
'relation' => $result['relation'],
|
||||
'other_ticket_id' => $result['other_ticket_id'],
|
||||
'removed' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user