#!/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 # Format: "GiteaUsername:SlackID,GiteaUser2:SlackID2" (same as Go's ParseManualMappings) # These bypass the Gitea API email lookup + Slack email lookup if [ -n "$MANUAL_USER_MAPPINGS" ]; then 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" | tr ',' '\n' | while IFS=':' read -r name slack_id; do name=$(echo "$name" | xargs) slack_id=$(echo "$slack_id" | xargs) [ -z "$name" ] && continue [ -z "$slack_id" ] && continue sqlite3 /app/data/notifications.db \ "INSERT OR REPLACE INTO users(gitea_username, slack_id, slack_name, updated_at) VALUES('$name','$slack_id','$name',datetime('now'));" \ 2>/dev/null || true done fi exec ./gitea-notification-hub -config /app/config/config.yaml -debug