mirror of
https://github.com/PerpetualSoftware/pad.git
synced 2026-09-20 09:33:28 +00:00
7cda0d7896
Migrates from xarmian/pad to PerpetualSoftware/pad across the entire
repo and updates the product subtitle to "Collaborate with your AI
agents".
Go module rename
- go.mod: github.com/xarmian/pad → github.com/PerpetualSoftware/pad
- All Go imports updated across cmd/pad, internal/{cli,server,store,
models,collections,items,events,metrics,webhooks} (~130 files)
- Test fixtures with the literal repo slug ("xarmian/pad" in JSON
shapes, SSH/HTTPS git URL strings, workspace_context fixtures)
also updated, including the secondary repo entry
(xarmian/pad-web → PerpetualSoftware/pad-web — pad-web was also
moved to the org per branch context)
Docs / config
- README badges, install instructions, brew tap, Docker image, source
build path, sponsor link (sponsor link kept as personal @xarmian)
- Subtitle: "Project management for developers and AI agents." →
"Collaborate with your AI agents." (README, manifests, web layout
meta, .goreleaser homebrew description)
- CONTRIBUTING.md, SECURITY.md, skills/INSTALL.md
- .goreleaser.yaml: homebrew_casks owner, GHCR image, release github
owner, cosign cert-identity regex, comments
- .github/workflows/release.yml: tap/release comments
- deploy/k8s/deployment.yaml: container image
- docs/deployment.md: clone URL
- web/static/{site.webmanifest,manifest.json}: description
- web/src/routes/+layout.svelte: meta description + og:description
Brew tap path is PerpetualSoftware/tap/pad (CamelCase, matches
GitHub user case). GHCR image is ghcr.io/perpetualsoftware/pad
(lowercased per GHCR's URL normalization). CODEOWNERS @xarmian and
FUNDING.yml github: xarmian intentionally retained — those are the
personal maintainer / sponsor account, separate from the org repo.
Verification: go build ./..., go test ./... (all pkgs pass), web
build, and make install all clean (TASK-844, TASK-845).
139 lines
3.8 KiB
Go
139 lines
3.8 KiB
Go
package store
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
"github.com/PerpetualSoftware/pad/internal/models"
|
|
)
|
|
|
|
// CreateWebhook registers a new webhook for a workspace.
|
|
func (s *Store) CreateWebhook(workspaceID string, input models.WebhookCreate) (*models.Webhook, error) {
|
|
id := newID()
|
|
ts := now()
|
|
|
|
evts := input.Events
|
|
if evts == "" {
|
|
evts = `["*"]`
|
|
}
|
|
|
|
_, err := s.db.Exec(s.q(`
|
|
INSERT INTO webhooks (id, workspace_id, url, secret, events, active, created_at, updated_at, failure_count)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)
|
|
`), id, workspaceID, input.URL, input.Secret, evts, s.dialect.BoolToInt(true), ts, ts)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("insert webhook: %w", err)
|
|
}
|
|
|
|
return s.GetWebhook(id)
|
|
}
|
|
|
|
// GetWebhook retrieves a single webhook by ID.
|
|
func (s *Store) GetWebhook(id string) (*models.Webhook, error) {
|
|
var wh models.Webhook
|
|
var active bool
|
|
var createdAt, updatedAt string
|
|
var lastTriggeredAt *string
|
|
|
|
err := s.db.QueryRow(s.q(`
|
|
SELECT id, workspace_id, url, secret, events, active, created_at, updated_at, last_triggered_at, failure_count
|
|
FROM webhooks
|
|
WHERE id = ?
|
|
`), id).Scan(
|
|
&wh.ID, &wh.WorkspaceID, &wh.URL, &wh.Secret, &wh.Events,
|
|
&active, &createdAt, &updatedAt, &lastTriggeredAt, &wh.FailureCount,
|
|
)
|
|
if err == sql.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, fmt.Errorf("get webhook: %w", err)
|
|
}
|
|
|
|
wh.Active = active
|
|
wh.CreatedAt = parseTime(createdAt)
|
|
wh.UpdatedAt = parseTime(updatedAt)
|
|
wh.LastTriggeredAt = parseTimePtr(lastTriggeredAt)
|
|
return &wh, nil
|
|
}
|
|
|
|
// ListWebhooks returns all webhooks for a workspace.
|
|
func (s *Store) ListWebhooks(workspaceID string) ([]models.Webhook, error) {
|
|
rows, err := s.db.Query(s.q(`
|
|
SELECT id, workspace_id, url, secret, events, active, created_at, updated_at, last_triggered_at, failure_count
|
|
FROM webhooks
|
|
WHERE workspace_id = ?
|
|
ORDER BY created_at ASC
|
|
`), workspaceID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list webhooks: %w", err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
var result []models.Webhook
|
|
for rows.Next() {
|
|
var wh models.Webhook
|
|
var active bool
|
|
var createdAt, updatedAt string
|
|
var lastTriggeredAt *string
|
|
|
|
if err := rows.Scan(
|
|
&wh.ID, &wh.WorkspaceID, &wh.URL, &wh.Secret, &wh.Events,
|
|
&active, &createdAt, &updatedAt, &lastTriggeredAt, &wh.FailureCount,
|
|
); err != nil {
|
|
return nil, fmt.Errorf("scan webhook: %w", err)
|
|
}
|
|
wh.Active = active
|
|
wh.CreatedAt = parseTime(createdAt)
|
|
wh.UpdatedAt = parseTime(updatedAt)
|
|
wh.LastTriggeredAt = parseTimePtr(lastTriggeredAt)
|
|
result = append(result, wh)
|
|
}
|
|
return result, rows.Err()
|
|
}
|
|
|
|
// DeleteWebhook removes a webhook by ID.
|
|
func (s *Store) DeleteWebhook(id string) error {
|
|
result, err := s.db.Exec(s.q("DELETE FROM webhooks WHERE id = ?"), id)
|
|
if err != nil {
|
|
return fmt.Errorf("delete webhook: %w", err)
|
|
}
|
|
n, _ := result.RowsAffected()
|
|
if n == 0 {
|
|
return sql.ErrNoRows
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UpdateWebhookFailure increments or resets the failure count for a webhook.
|
|
// If failed is true, the failure_count is incremented. If it reaches the
|
|
// threshold of 10, the webhook is auto-deactivated.
|
|
// If failed is false, the failure_count is reset to 0 and last_triggered_at is updated.
|
|
func (s *Store) UpdateWebhookFailure(id string, failed bool) error {
|
|
ts := now()
|
|
if failed {
|
|
_, err := s.db.Exec(s.q(`
|
|
UPDATE webhooks
|
|
SET failure_count = failure_count + 1,
|
|
updated_at = ?,
|
|
active = CASE WHEN failure_count + 1 >= 10 THEN FALSE ELSE active END
|
|
WHERE id = ?
|
|
`), ts, id)
|
|
if err != nil {
|
|
return fmt.Errorf("update webhook failure: %w", err)
|
|
}
|
|
} else {
|
|
_, err := s.db.Exec(s.q(`
|
|
UPDATE webhooks
|
|
SET failure_count = 0,
|
|
last_triggered_at = ?,
|
|
updated_at = ?
|
|
WHERE id = ?
|
|
`), ts, ts, id)
|
|
if err != nil {
|
|
return fmt.Errorf("update webhook success: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|