Created
July 5, 2021 20:40
-
-
Save andyczerwonka/f15d1a2192034da45965a475a0692e0e to your computer and use it in GitHub Desktop.
Revisions
-
andyczerwonka created this gist
Jul 5, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import java.io.{InputStream, OutputStream} import com.amazonaws.services.lambda.runtime.{Context, RequestStreamHandler} import com.softwaremill.sttp._ import io.circe.Json import io.circe.generic.auto._ import io.circe.parser._ import io.circe.syntax._ class JiraDiscord extends RequestStreamHandler with Helpers { override def handleRequest(input: InputStream, output: OutputStream, context: Context): Unit = { val logger = context.getLogger val rawJson = scala.io.Source.fromInputStream(input).getLines().mkString("\n") val jsonDoc = parse(rawJson).getOrElse(Json.Null) extractJiraBody(jsonDoc) map { json => logger.log(json.spaces2) JiraParser.parse(json) map { event => implicit val backend: SttpBackend[Id, Nothing] = HttpURLConnectionBackend() try { val title = s"${event.key}: ${event.summary}" val desc = s"**${event.eventTypeLabel}**\n${event.description()}" val msg = DiscordWebhook(title, event.url, desc, event.author()).asJson.noSpaces val request = sttp .contentType("application/json") .header("User-Agent", userAgent) .body(msg) .post(discordUri(jsonDoc)) request.send() output.write(ok) } finally { backend.close() } } } } }