Skip to content

Commit

Permalink
upgrade all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
pschichtel committed Oct 4, 2024
1 parent 0b5397f commit a1be13f
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '21'
- name: Coursier cache
uses: coursier/cache-action@v6
- name: Build and Publish
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/MainController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class MainController(cached: Cached,
blogPosts <- tumblr.allPosts
projects <- github.getProjects
} yield {
val blogDocs = blogPosts.map(TumblrDoc)
val projectDocs = projects.map(ProjectDoc)
val blogDocs = blogPosts.map(TumblrDoc.apply)
val projectDocs = projects.map(ProjectDoc.apply)

val docs: Seq[Doc] = blogDocs ++ projectDocs

Expand Down
13 changes: 6 additions & 7 deletions app/service/Formats.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package service

import java.net.URL

import play.api.libs.json._
import java.net.URI
import play.api.libs.json.*

object Formats {

implicit object UrlFormat extends Format[URL] {
override def reads(json: JsValue): JsResult[URL] = json match {
case JsString(s) => JsSuccess(new URL(s))
implicit object UrlFormat extends Format[URI] {
override def reads(json: JsValue): JsResult[URI] = json match {
case JsString(s) => JsSuccess(URI(s))
case _ => JsError("Not a URL")
}

override def writes(o: URL): JsValue = JsString(o.toString)
override def writes(o: URI): JsValue = JsString(o.toString)
}

implicit val repo: Format[Repo] = Json.format
Expand Down
76 changes: 39 additions & 37 deletions app/service/Github.scala
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
package service

import java.net.URL
import java.net.URI
import java.time.temporal.ChronoUnit
import java.time.{LocalDate, ZoneId, ZonedDateTime}

import com.fasterxml.jackson.core.JsonParseException
import play.api.cache.SyncCacheApi
import play.api.libs.json._
import play.api.libs.json.*
import play.api.libs.ws.WSAuthScheme.BASIC
import play.api.libs.ws.WSClient
import play.api.libs.ws.JsonBodyWritables.*
import play.api.{Configuration, Logger}
import service.CacheHelper.{CacheDuration, ProjectsCacheKey}
import service.Formats._
import service.Formats.*

import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}

case class Repo(name: String, html_url: String, full_name: String, created_at: ZonedDateTime, default_branch: String) {
def file(path: String, branch: String = default_branch) = s"https://raw.githubusercontent.com/$full_name/$branch/$path"

lazy val latestRelease = new URL(s"https://github.com/$full_name/releases/latest")
lazy val latestRelease = URI(s"https://github.com/$full_name/releases/latest")
}

case class JamInfo(name: String, number: Int, theme: String, site: URL, comments: Seq[String])
case class JamInfo(name: String, number: Int, theme: String, site: URI, comments: Seq[String])

case class WebCheat(label: String, gameObject: String, message: String)

case class ProjectMeta(name: String, description: String, jam: Option[JamInfo], authors: Seq[String],
download: Option[URL], soundtrack: Option[URL], date: Option[LocalDate], web: Option[URL], cheats: Option[Seq[WebCheat]])
download: Option[URI], soundtrack: Option[URI], date: Option[LocalDate], web: Option[URI], cheats: Option[Seq[WebCheat]])

case class Project(repoName: String, displayName: String, url: URL, description: String,
jam: Option[JamInfo], authors: Seq[String], imageUrl: URL,
createdAt: ZonedDateTime, download: URL, soundtrack: Option[URL], web: Option[URL], cheats: Seq[WebCheat],
case class Project(repoName: String, displayName: String, url: URI, description: String,
jam: Option[JamInfo], authors: Seq[String], imageUrl: URI,
createdAt: ZonedDateTime, download: URI, soundtrack: Option[URI], web: Option[URI], cheats: Seq[WebCheat],
coreUsers: Seq[User], guests: Seq[User])

case class Team(name: String, id: Int, slug: String, description: String)
Expand Down Expand Up @@ -91,8 +91,8 @@ class GithubService(ws: WSClient, cache: SyncCacheApi, config: Configuration, im
.map(d => d.atStartOfDay(ZoneId.systemDefault()))
.getOrElse(basics.created_at)
val (core, guests) = memberLookup.getOrElse(basics.name, (Seq.empty, Seq.empty))
Project(basics.name, meta.name, new URL(basics.html_url), meta.description, meta.jam,
meta.authors.sorted, new URL(basics.file(".banana4life/main.png")), date,
Project(basics.name, meta.name, URI(basics.html_url), meta.description, meta.jam,
meta.authors.sorted, URI(basics.file(".banana4life/main.png")), date,
meta.download.getOrElse(basics.latestRelease), meta.soundtrack, meta.web, meta.cheats.getOrElse(Nil),
core.sortBy(_.name), guests.sortBy(_.name))
}.recover({
Expand Down Expand Up @@ -130,7 +130,7 @@ class GithubService(ws: WSClient, cache: SyncCacheApi, config: Configuration, im
val allTeams = teams zip members zip repos map {
case ((t, m), r) => (t, m, r)
}
val coreTeam = allTeams.find(_._1.name == CoreTeam).map(_._2).getOrElse(Set.empty).map(_.login).toSet
val coreTeam = allTeams.find(_._1.name == CoreTeam).map(_._2).getOrElse(Set.empty[Member]).map(_.login).toSet

def getUser(m: Seq[Member]) = {
m.map { mm =>
Expand All @@ -146,29 +146,31 @@ class GithubService(ws: WSClient, cache: SyncCacheApi, config: Configuration, im
}

def getMembers = {
ws.url("https://api.github.com/graphql").withAuth(config.get[String]("github.tokenUser"), config.get[String]("github.token"), BASIC).post(
Json.obj("query" -> "query { organization(login:\"Banana4Life\") { membersWithRole(last:100) { nodes { login, name } } } }")
).map(_.json).map { v =>
logger.info(v.toString())
v \ "data" \ "organization" \ "membersWithRole" \ "nodes"
} collect {
case JsDefined(JsArray(nodes)) => nodes.map { value =>
val login = (value \ "login").get
val name = value \ "name" match {
case JsDefined(n) =>
n match {
case JsNull => login
case JsString("") => login
case _ => n
}
case _ => login
}

User(login.as[String], name.as[String])
}
case _ => Seq.empty
} map { users =>
users.map(user => (user.login, user)).toMap
}
val query = Json.obj("query" -> "query { organization(login:\"Banana4Life\") { membersWithRole(last:100) { nodes { login, name } } } }")
ws.url("https://api.github.com/graphql").withAuth(config.get[String]("github.tokenUser"), config.get[String]("github.token"), BASIC)
.post(query)
.map(_.json)
.map { v =>
logger.info(v.toString())
v \ "data" \ "organization" \ "membersWithRole" \ "nodes"
} collect {
case JsDefined(JsArray(nodes)) => nodes.map { value =>
val login = (value \ "login").get
val name = value \ "name" match {
case JsDefined(n) =>
n match {
case JsNull => login
case JsString("") => login
case _ => n
}
case _ => login
}

User(login.as[String], name.as[String])
}
case _ => Seq.empty
} map { users =>
users.map(user => (user.login, user)).toMap
}
}
}
6 changes: 3 additions & 3 deletions app/service/HealthCheck.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package service

import akka.actor.ActorSystem
import akka.stream.Materializer
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.Materializer
import play.api.libs.ws.ahc.AhcWSClient

import scala.concurrent.Await
Expand All @@ -10,7 +10,7 @@ import scala.concurrent.duration.Duration
object HealthCheck {
def main(args: Array[String]): Unit = {
val actorSystem = ActorSystem.create("healthcheck")
implicit val materializer = Materializer.matFromSystem(actorSystem)
implicit val materializer: Materializer = Materializer.matFromSystem(actorSystem)
val client = AhcWSClient()

try {
Expand Down
12 changes: 6 additions & 6 deletions app/service/YoutubeService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import com.google.api.services.youtube.model.ThumbnailDetails
import com.google.api.services.youtube.{YouTube, YouTubeRequestInitializer}
import play.api.{Configuration, Logging}

import java.net.URL
import java.net.URI
import java.time.{Instant, ZoneOffset, ZonedDateTime}
import scala.concurrent.{ExecutionContext, Future}
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

object DummyInitializer extends HttpRequestInitializer {
override def initialize(request: HttpRequest): Unit = {}
}

case class YtVideo(id: String, channelName: String, name: String, description: String, thumbnail: URL, publishedAt: ZonedDateTime) {
lazy val url = new URL(s"https://www.youtube.com/watch?v=$id")
case class YtVideo(id: String, channelName: String, name: String, description: String, thumbnail: URI, publishedAt: ZonedDateTime) {
lazy val url = URI(s"https://www.youtube.com/watch?v=$id")
}

class YoutubeService(conf: Configuration, implicit val ec: ExecutionContext) extends Logging{
Expand Down Expand Up @@ -51,9 +51,9 @@ class YoutubeService(conf: Configuration, implicit val ec: ExecutionContext) ext
}
}

def getBestThumbnailURL(id: String, thumbs: ThumbnailDetails): URL = {
def getBestThumbnailURL(id: String, thumbs: ThumbnailDetails): URI = {
val p = Seq(thumbs.getMaxres, thumbs.getHigh, thumbs.getMedium, thumbs.getStandard, thumbs.getDefault)
new URL(p.filter(_ != null).head.getUrl)
URI(p.filter(_ != null).head.getUrl)
}

def getVideosOfPlaylist(id: String): Seq[YtVideo] = {
Expand Down
8 changes: 4 additions & 4 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<nav>
<div class="main-column">
<ul>
<li><a href="@routes.MainController.index()" class="@(if(title == "Home") "current")">Home</a></li>
<li><a href="@routes.BlogController.firstBlogPage()" class="@(if(title == "Blog") "current")">Blog</a></li>
<li><a href="@routes.MainController.projects()" class="@(if(title == "Projects") "current")">Projects</a></li>
<li><a href="@routes.MainController.about()" class="@(if(title == "About") "current")">About</a></li>
<li><a href="@routes.MainController.index()" class="@(if(title == "Home") "current" else "")">Home</a></li>
<li><a href="@routes.BlogController.firstBlogPage()" class="@(if(title == "Blog") "current" else "")">Blog</a></li>
<li><a href="@routes.MainController.projects()" class="@(if(title == "Projects") "current" else "")">Projects</a></li>
<li><a href="@routes.MainController.about()" class="@(if(title == "About") "current" else "")">About</a></li>
</ul>
</div>
<div class="clear"></div>
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version := "1.0"
lazy val root = (project in file("."))
.enablePlugins(PlayScala)

scalaVersion := "2.13.11"
scalaVersion := "3.3.3"

routesGenerator := InjectedRoutesGenerator

Expand All @@ -32,7 +32,7 @@ Compile / packageDoc / publishArtifact := false

Assets / pipelineStages := Seq(digest, gzip)

jibBaseImage := "docker.io/library/eclipse-temurin:11-jre-alpine"
jibBaseImage := "docker.io/library/eclipse-temurin:21-jre-alpine"
jibRegistry := "ghcr.io"
jibOrganization := "banana4life"
jibName := "website"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.2
sbt.version=1.10.2
7 changes: 5 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.20")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.5")

// web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.4")

// build
addSbtPlugin("de.gccc.sbt" % "sbt-jib" % "1.3.6")
addSbtPlugin("de.gccc.sbt" % "sbt-jib" % "1.3.7")

// util
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")

0 comments on commit a1be13f

Please sign in to comment.