#!/bin/sh set -e # Generate config.yaml from environment variables mkdir -p /app/config cat > /app/config/config.yaml << 'YAMLEOF' server: port: 8080 webhook_secret: "${GITEA_WEBHOOK_SECRET}" identity: provider: gitea cache_ttl: 24h gitea: url: "${GITEA_URL}" token: "${GITEA_API_TOKEN}" notification: provider: slack slack: bot_token: "${SLACK_BOT_TOKEN}" database: driver: sqlite dsn: "./data/notifications.db" rules: pr: notify_owner: true notify_reviewers: true notify_assignees: true issue: notify_assignees: true comment: notify_mentioned: true notify_thread_owner: true notify_reviewers: true YAMLEOF # Seed manual user mappings from MANUAL_USER_MAPPINGS env var (JSON: {"gitea_username":"slack_id",...}) # These bypass the Gitea API email lookup + Slack email lookup if [ -n "$MANUAL_USER_MAPPINGS" ]; then # Create table and indexes using single-line calls to avoid sh issues with multi-line SQL sqlite3 /app/data/notifications.db "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, gitea_username TEXT UNIQUE, gitea_id INTEGER, email TEXT UNIQUE, full_name TEXT, slack_id TEXT, slack_name TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP);" 2>/dev/null || true sqlite3 /app/data/notifications.db "CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);" 2>/dev/null || true sqlite3 /app/data/notifications.db "CREATE INDEX IF NOT EXISTS idx_users_gitea_username ON users(gitea_username);" 2>/dev/null || true sqlite3 /app/data/notifications.db "CREATE INDEX IF NOT EXISTS idx_users_slack_id ON users(slack_id);" 2>/dev/null || true echo "$MANUAL_USER_MAPPINGS" | jq -r 'to_entries[] | "\(.key) \(.value)"' 2>/dev/null | \ while read -r gitea_user slack_id; do [ -z "$gitea_user" ] && continue sqlite3 /app/data/notifications.db \ "INSERT OR REPLACE INTO users(gitea_username, slack_id, slack_name, updated_at) VALUES('$gitea_user','$slack_id','$gitea_user',datetime('now'));" \ 2>/dev/null || true done fi exec ./gitea-notification-hub -config /app/config/config.yaml