Add commit URL to Slack notifications with link and backtick formatting

- Add commit_url column to webhook_events and deployments tables
- Extract commit URL from webhook payload (from commit object or repo URL)
- Format Slack messages with backticks for branch and commit SHA
- Link commit SHA to the actual commit URL on the git server
- Keep plain text format for ntfy notifications
This commit is contained in:
2025-12-31 16:29:22 -08:00
parent 4cd12d717c
commit c4362c3143
6 changed files with 109 additions and 45 deletions

View File

@@ -37,6 +37,7 @@ type Deployment struct {
AppID string
WebhookEventID sql.NullInt64
CommitSHA sql.NullString
CommitURL sql.NullString
ImageID sql.NullString
ContainerID sql.NullString
Status DeploymentStatus
@@ -65,7 +66,7 @@ func (d *Deployment) Save(ctx context.Context) error {
// Reload refreshes the deployment from the database.
func (d *Deployment) Reload(ctx context.Context) error {
query := `
SELECT id, app_id, webhook_event_id, commit_sha, image_id,
SELECT id, app_id, webhook_event_id, commit_sha, commit_url, image_id,
container_id, status, logs, started_at, finished_at
FROM deployments WHERE id = ?`
@@ -156,12 +157,12 @@ func (d *Deployment) FinishedAtFormatted() string {
func (d *Deployment) insert(ctx context.Context) error {
query := `
INSERT INTO deployments (
app_id, webhook_event_id, commit_sha, image_id,
app_id, webhook_event_id, commit_sha, commit_url, image_id,
container_id, status, logs
) VALUES (?, ?, ?, ?, ?, ?, ?)`
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
result, err := d.db.Exec(ctx, query,
d.AppID, d.WebhookEventID, d.CommitSHA, d.ImageID,
d.AppID, d.WebhookEventID, d.CommitSHA, d.CommitURL, d.ImageID,
d.ContainerID, d.Status, d.Logs,
)
if err != nil {
@@ -193,7 +194,7 @@ func (d *Deployment) update(ctx context.Context) error {
func (d *Deployment) scan(row *sql.Row) error {
return row.Scan(
&d.ID, &d.AppID, &d.WebhookEventID, &d.CommitSHA, &d.ImageID,
&d.ID, &d.AppID, &d.WebhookEventID, &d.CommitSHA, &d.CommitURL, &d.ImageID,
&d.ContainerID, &d.Status, &d.Logs, &d.StartedAt, &d.FinishedAt,
)
}
@@ -210,7 +211,7 @@ func FindDeployment(
deploy.ID = deployID
row := deployDB.QueryRow(ctx, `
SELECT id, app_id, webhook_event_id, commit_sha, image_id,
SELECT id, app_id, webhook_event_id, commit_sha, commit_url, image_id,
container_id, status, logs, started_at, finished_at
FROM deployments WHERE id = ?`,
deployID,
@@ -236,7 +237,7 @@ func FindDeploymentsByAppID(
limit int,
) ([]*Deployment, error) {
query := `
SELECT id, app_id, webhook_event_id, commit_sha, image_id,
SELECT id, app_id, webhook_event_id, commit_sha, commit_url, image_id,
container_id, status, logs, started_at, finished_at
FROM deployments WHERE app_id = ?
ORDER BY started_at DESC, id DESC LIMIT ?`
@@ -255,7 +256,7 @@ func FindDeploymentsByAppID(
scanErr := rows.Scan(
&deploy.ID, &deploy.AppID, &deploy.WebhookEventID,
&deploy.CommitSHA, &deploy.ImageID, &deploy.ContainerID,
&deploy.CommitSHA, &deploy.CommitURL, &deploy.ImageID, &deploy.ContainerID,
&deploy.Status, &deploy.Logs, &deploy.StartedAt, &deploy.FinishedAt,
)
if scanErr != nil {
@@ -284,7 +285,7 @@ func LatestDeploymentForApp(
deploy := NewDeployment(deployDB)
row := deployDB.QueryRow(ctx, `
SELECT id, app_id, webhook_event_id, commit_sha, image_id,
SELECT id, app_id, webhook_event_id, commit_sha, commit_url, image_id,
container_id, status, logs, started_at, finished_at
FROM deployments WHERE app_id = ?
ORDER BY started_at DESC, id DESC LIMIT 1`,