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:
@@ -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`,
|
||||
|
||||
@@ -19,6 +19,7 @@ type WebhookEvent struct {
|
||||
EventType string
|
||||
Branch string
|
||||
CommitSHA sql.NullString
|
||||
CommitURL sql.NullString
|
||||
Payload sql.NullString
|
||||
Matched bool
|
||||
Processed bool
|
||||
@@ -42,8 +43,8 @@ func (w *WebhookEvent) Save(ctx context.Context) error {
|
||||
// Reload refreshes the webhook event from the database.
|
||||
func (w *WebhookEvent) Reload(ctx context.Context) error {
|
||||
query := `
|
||||
SELECT id, app_id, event_type, branch, commit_sha, payload,
|
||||
matched, processed, created_at
|
||||
SELECT id, app_id, event_type, branch, commit_sha, commit_url,
|
||||
payload, matched, processed, created_at
|
||||
FROM webhook_events WHERE id = ?`
|
||||
|
||||
row := w.db.QueryRow(ctx, query, w.ID)
|
||||
@@ -54,11 +55,11 @@ func (w *WebhookEvent) Reload(ctx context.Context) error {
|
||||
func (w *WebhookEvent) insert(ctx context.Context) error {
|
||||
query := `
|
||||
INSERT INTO webhook_events (
|
||||
app_id, event_type, branch, commit_sha, payload, matched, processed
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
app_id, event_type, branch, commit_sha, commit_url, payload, matched, processed
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
|
||||
result, err := w.db.Exec(ctx, query,
|
||||
w.AppID, w.EventType, w.Branch, w.CommitSHA,
|
||||
w.AppID, w.EventType, w.Branch, w.CommitSHA, w.CommitURL,
|
||||
w.Payload, w.Matched, w.Processed,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -86,7 +87,7 @@ func (w *WebhookEvent) update(ctx context.Context) error {
|
||||
func (w *WebhookEvent) scan(row *sql.Row) error {
|
||||
return row.Scan(
|
||||
&w.ID, &w.AppID, &w.EventType, &w.Branch, &w.CommitSHA,
|
||||
&w.Payload, &w.Matched, &w.Processed, &w.CreatedAt,
|
||||
&w.CommitURL, &w.Payload, &w.Matched, &w.Processed, &w.CreatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -102,8 +103,8 @@ func FindWebhookEvent(
|
||||
event.ID = id
|
||||
|
||||
row := db.QueryRow(ctx, `
|
||||
SELECT id, app_id, event_type, branch, commit_sha, payload,
|
||||
matched, processed, created_at
|
||||
SELECT id, app_id, event_type, branch, commit_sha, commit_url,
|
||||
payload, matched, processed, created_at
|
||||
FROM webhook_events WHERE id = ?`,
|
||||
id,
|
||||
)
|
||||
@@ -128,8 +129,8 @@ func FindWebhookEventsByAppID(
|
||||
limit int,
|
||||
) ([]*WebhookEvent, error) {
|
||||
query := `
|
||||
SELECT id, app_id, event_type, branch, commit_sha, payload,
|
||||
matched, processed, created_at
|
||||
SELECT id, app_id, event_type, branch, commit_sha, commit_url,
|
||||
payload, matched, processed, created_at
|
||||
FROM webhook_events WHERE app_id = ? ORDER BY created_at DESC LIMIT ?`
|
||||
|
||||
rows, err := db.Query(ctx, query, appID, limit)
|
||||
@@ -146,7 +147,7 @@ func FindWebhookEventsByAppID(
|
||||
|
||||
scanErr := rows.Scan(
|
||||
&event.ID, &event.AppID, &event.EventType, &event.Branch,
|
||||
&event.CommitSHA, &event.Payload, &event.Matched,
|
||||
&event.CommitSHA, &event.CommitURL, &event.Payload, &event.Matched,
|
||||
&event.Processed, &event.CreatedAt,
|
||||
)
|
||||
if scanErr != nil {
|
||||
@@ -165,8 +166,8 @@ func FindUnprocessedWebhookEvents(
|
||||
db *database.Database,
|
||||
) ([]*WebhookEvent, error) {
|
||||
query := `
|
||||
SELECT id, app_id, event_type, branch, commit_sha, payload,
|
||||
matched, processed, created_at
|
||||
SELECT id, app_id, event_type, branch, commit_sha, commit_url,
|
||||
payload, matched, processed, created_at
|
||||
FROM webhook_events
|
||||
WHERE matched = 1 AND processed = 0 ORDER BY created_at ASC`
|
||||
|
||||
@@ -184,7 +185,7 @@ func FindUnprocessedWebhookEvents(
|
||||
|
||||
scanErr := rows.Scan(
|
||||
&event.ID, &event.AppID, &event.EventType, &event.Branch,
|
||||
&event.CommitSHA, &event.Payload, &event.Matched,
|
||||
&event.CommitSHA, &event.CommitURL, &event.Payload, &event.Matched,
|
||||
&event.Processed, &event.CreatedAt,
|
||||
)
|
||||
if scanErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user