<commit_before>package jmailen.slakoverflow

import io.ktor.application.ApplicationCall
import io.ktor.application.call
import io.ktor.application.install
import io.ktor.content.HttpStatusCodeContent
import io.ktor.content.TextContent
import io.ktor.content.readText
import io.ktor.features.StatusPages
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.request.path
import io.ktor.request.receiveParameters
import io.ktor.request.uri
import io.ktor.request.userAgent
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.get
import io.ktor.routing.post
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.util.toMap
import jmailen.java.mask
import jmailen.serialization.Json
import jmailen.slakoverflow.slack.CommandResponse
import jmailen.slakoverflow.slack.ResponseType
import jmailen.slakoverflow.slack.SlackClient
import jmailen.slakoverflow.stackoverflow.StackOverflowClient

const val ENV_PORT = "PORT"
const val ENV_STACKAPPKEY = "STACKAPP_KEY"
const val ENV_SENTRY_DSN = "SENTRY_DSN"
const val DEFAULT_PORT = 8777

fun main(args: Array<String>) {
    val port = getPort()

    val server = embeddedServer(Netty, port) {
        install(StatusPages) {
            exception<Throwable> { cause ->
                Logger.error("request failed", cause, mapOf(
                    "path" to call.request.path(),
                    "userAgent" to (call.request.userAgent() ?: "unspecified")
                ))
                call.respond(HttpStatusCode.InternalServerError)
            }
        }
        routing {
            get("/") {
                handleRoot(call)
            }
            get("/siteinfo") {
                handleSiteInfo(call)
            }
            post("/slack/command/overflow") {
                handleCommandOverflow(call)
            }
            get("/testError") {
                throw IllegalArgumentException(call.request.queryParameters["message"] ?: "some error occurred")
            }
            post("/sentry") {
                handleSentry(call)
            }
        }
    }

    Logger.info("starting slakoverflow:$port")

    getStackAppKey()?.let { Logger.info("stack app key set: ${it.mask()}") }
    getSentryDSN()?.let { Logger.info("sentry dsn ${it.mask()}") }
    server.start(wait = true)<commit_msg>Test with different error to trigger sentry<commit_after>package jmailen.slakoverflow

import io.ktor.application.ApplicationCall
import io.ktor.application.call
import io.ktor.application.install
import io.ktor.content.HttpStatusCodeContent
import io.ktor.content.TextContent
import io.ktor.content.readText
import io.ktor.features.StatusPages
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.request.path
import io.ktor.request.receiveParameters
import io.ktor.request.uri
import io.ktor.request.userAgent
import io.ktor.response.respond
import io.ktor.response.respondText
import io.ktor.routing.get
import io.ktor.routing.post
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.util.toMap
import jmailen.java.mask
import jmailen.serialization.Json
import jmailen.slakoverflow.slack.CommandResponse
import jmailen.slakoverflow.slack.ResponseType
import jmailen.slakoverflow.slack.SlackClient
import jmailen.slakoverflow.stackoverflow.StackOverflowClient
import java.lang.IllegalStateException

const val ENV_PORT = "PORT"
const val ENV_STACKAPPKEY = "STACKAPP_KEY"
const val ENV_SENTRY_DSN = "SENTRY_DSN"
const val DEFAULT_PORT = 8777

fun main(args: Array<String>) {
    val port = getPort()

    val server = embeddedServer(Netty, port) {
        install(StatusPages) {
            exception<Throwable> { cause ->
                Logger.error("request failed", cause, mapOf(
                    "path" to call.request.path(),
                    "userAgent" to (call.request.userAgent() ?: "unspecified")
                ))
                call.respond(HttpStatusCode.InternalServerError)
            }
        }
        routing {
            get("/") {
                handleRoot(call)
            }
            get("/siteinfo") {
                handleSiteInfo(call)
            }
            post("/slack/command/overflow") {
                handleCommandOverflow(call)
            }
            get("/testError") {
                throw IllegalStateException(call.request.queryParameters["message"] ?: "some error occurred")
            }
            post("/sentry") {
                handleSentry(call)
            }
        }
    }

    Logger.info("starting slakoverflow:$port")

    getStackAppKey()?.let { Logger.info("stack app key set: ${it.mask()}") }
    getSentryDSN()?.let { Logger.info("sentry dsn ${it.mask()}") }
    server.start(wait = true)
{'fraction_non_alphanumeric': 0.10582444626743231, 'fraction_numerical': 0.0016406890894175555, 'mean_word_length': 2.754426481909161, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7140712', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1439, 'n_words': 259}