Skip to content

Commit

Permalink
Add JSON metadata in PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior authored and mzuehlke committed Nov 8, 2024
1 parent ae6494d commit 5301c19
Show file tree
Hide file tree
Showing 3 changed files with 359 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.scalasteward.core.forge.data

import cats.syntax.all._
import io.circe.Json
import io.circe.syntax._
import org.http4s.Uri
import org.scalasteward.core.data._
import org.scalasteward.core.edit.EditAttempt
Expand Down Expand Up @@ -112,9 +114,18 @@ object NewPullRequestData {
|<sup>
|${labels.mkString("labels: ", ", ", "")}
|</sup>
|""".stripMargin.trim
|
|<!-- scala-steward = ${metadataJson(update, labels)} -->""".stripMargin.trim
}

def metadataJson(update: Update, labels: List[String]): String =
Json
.obj(
"Update" -> update.asJson,
"Labels" -> Json.fromValues(labels.map(_.asJson))
)
.toString

def renderUpdateInfoUrls(updateInfoUrls: List[UpdateInfoUrl]): Option[String] =
Option.when(updateInfoUrls.nonEmpty) {
updateInfoUrls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,35 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "ch.qos.logback",
| "artifactId" : {
| "name" : "logback-classic",
| "maybeCrossName" : null
| },
| "version" : "1.2.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "1.2.3"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| "Labels" : [
| "library-update"
| ]
|} -->""".stripMargin

assertEquals(body, expected)
}
Expand Down Expand Up @@ -127,7 +155,35 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "ch.qos.logback",
| "artifactId" : {
| "name" : "logback-classic",
| "maybeCrossName" : null
| },
| "version" : "1.2.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "1.2.3"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| "Labels" : [
| "library-update"
| ]
|} -->""".stripMargin

assertEquals(body, expected)
}
Expand Down Expand Up @@ -191,7 +247,65 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "Grouped" : {
| "name" : "my-group",
| "title" : "The PR title",
| "updates" : [
| {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "ch.qos.logback",
| "artifactId" : {
| "name" : "logback-classic",
| "maybeCrossName" : null
| },
| "version" : "1.2.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "1.2.3"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "com.example",
| "artifactId" : {
| "name" : "foo",
| "maybeCrossName" : null
| },
| "version" : "1.0.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "2.0.0"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| }
| ]
| }
| },
| "Labels" : [
| "library-update"
| ]
|} -->""".stripMargin

assertEquals(body, expected)
}
Expand Down Expand Up @@ -248,7 +362,35 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "ch.qos.logback",
| "artifactId" : {
| "name" : "logback-classic",
| "maybeCrossName" : null
| },
| "version" : "1.2.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "1.2.3"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| "Labels" : [
| "library-update"
| ]
|} -->""".stripMargin

assertEquals(body, expected)
}
Expand Down Expand Up @@ -642,7 +784,38 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update, early-semver-patch, semver-spec-patch, commit-count:0
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "ch.qos.logback",
| "artifactId" : {
| "name" : "logback-classic",
| "maybeCrossName" : null
| },
| "version" : "1.2.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "1.2.3"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| "Labels" : [
| "library-update",
| "early-semver-patch",
| "semver-spec-patch",
| "commit-count:0"
| ]
|} -->""".stripMargin

val expected = NewPullRequestData(
title = "Update logback-classic to 1.2.3",
Expand Down Expand Up @@ -731,7 +904,70 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update, early-semver-patch, semver-spec-patch, early-semver-major, semver-spec-major, commit-count:0
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "Grouped" : {
| "name" : "my-group",
| "title" : null,
| "updates" : [
| {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "ch.qos.logback",
| "artifactId" : {
| "name" : "logback-classic",
| "maybeCrossName" : null
| },
| "version" : "1.2.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "1.2.3"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "com.example",
| "artifactId" : {
| "name" : "foo",
| "maybeCrossName" : null
| },
| "version" : "1.0.0",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "2.0.0"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| }
| ]
| }
| },
| "Labels" : [
| "library-update",
| "early-semver-patch",
| "semver-spec-patch",
| "early-semver-major",
| "semver-spec-major",
| "commit-count:0"
| ]
|} -->""".stripMargin

val expected = NewPullRequestData(
title = "Update for group my-group",
Expand Down Expand Up @@ -803,7 +1039,38 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update, early-semver-major, semver-spec-minor, commit-count:1
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "org.typelevel",
| "artifactId" : {
| "name" : "cats-effect",
| "maybeCrossName" : null
| },
| "version" : "2.5.5",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "3.4.2"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| "Labels" : [
| "library-update",
| "early-semver-major",
| "semver-spec-minor",
| "commit-count:1"
| ]
|} -->""".stripMargin

assertEquals(body, expected)
}
Expand Down Expand Up @@ -857,7 +1124,38 @@ class NewPullRequestDataTest extends FunSuite {
|
|<sup>
|labels: library-update, early-semver-major, semver-spec-minor, commit-count:1
|</sup>""".stripMargin
|</sup>
|
|<!-- scala-steward = {
| "Update" : {
| "ForArtifactId" : {
| "crossDependency" : [
| {
| "groupId" : "com.lihaoyi",
| "artifactId" : {
| "name" : "os-lib",
| "maybeCrossName" : null
| },
| "version" : "0.7.8",
| "sbtVersion" : null,
| "scalaVersion" : null,
| "configurations" : null
| }
| ],
| "newerVersions" : [
| "0.9.1"
| ],
| "newerGroupId" : null,
| "newerArtifactId" : null
| }
| },
| "Labels" : [
| "library-update",
| "early-semver-major",
| "semver-spec-minor",
| "commit-count:1"
| ]
|} -->""".stripMargin

assertEquals(body, expected)
}
Expand Down
Loading

0 comments on commit 5301c19

Please sign in to comment.