Skip to content

Commit

Permalink
Ensure PR description is not too long
Browse files Browse the repository at this point in the history
With the addition of structured metadata to PR description the content was growing too large when multiple updates got grouped together.
Now the metadata gets only appended, if the length is still below 65536 characters.

Fixes: #3476
  • Loading branch information
mzuehlke committed Dec 3, 2024
1 parent dce40bb commit 5b1fa0f
Showing 1 changed file with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,45 @@ object NewPullRequestData {
_ => ""
)

s"""|$updatesText
|
|## Usage
|✅ **Please merge!**
|
|I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.
|
|${skipVersionMessage}If you have any feedback, just mention me in the comments below.
|
|Configure Scala Steward for your repository with a [`${RepoConfigAlg.repoConfigBasename}`](${org.scalasteward.core.BuildInfo.gitHubUrl}/blob/${org.scalasteward.core.BuildInfo.gitHeadCommit}/docs/repo-specific-configuration.md) file.
|
|_Have a fantastic day writing Scala!_
|
|${details.map(_.toHtml).mkString("\n")}
|
|<sup>
|${labels.mkString("labels: ", ", ", "")}
|</sup>
|
|<!-- scala-steward = ${metadataJson(update, labels)} -->""".stripMargin.trim
}
val plainBody =
s"""|$updatesText
|
|## Usage
|✅ **Please merge!**
|
|I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.
|
|${skipVersionMessage}If you have any feedback, just mention me in the comments below.
|
|Configure Scala Steward for your repository with a [`${RepoConfigAlg.repoConfigBasename}`](${org.scalasteward.core.BuildInfo.gitHubUrl}/blob/${org.scalasteward.core.BuildInfo.gitHeadCommit}/docs/repo-specific-configuration.md) file.
|
|_Have a fantastic day writing Scala!_
|
|${details.map(_.toHtml).mkString("\n")}
|
|<sup>
|${labels.mkString("labels: ", ", ", "")}
|</sup>
|""".stripMargin.trim

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

val bodyWithMetadata =
s"""$plainBody
|
|<!-- scala-steward = $metadataJson -->""".stripMargin

// Github limits PR descriptions to 65536 unicode characters
if (bodyWithMetadata.length < 65536)
bodyWithMetadata
else plainBody

Check warning on line 136 in modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala

View check run for this annotation

Codecov / codecov/patch

modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala#L136

Added line #L136 was not covered by tests
}

def renderUpdateInfoUrls(updateInfoUrls: List[UpdateInfoUrl]): Option[String] =
Option.when(updateInfoUrls.nonEmpty) {
Expand Down

0 comments on commit 5b1fa0f

Please sign in to comment.