From 5b1fa0f94677ef50a02f8366d90a7f211438d969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Zu=CC=88hlke?= Date: Tue, 3 Dec 2024 19:39:21 +0100 Subject: [PATCH] Ensure PR description is not too long 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 --- .../core/forge/data/NewPullRequestData.scala | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala b/modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala index 4e659ac824..125c7fdc2e 100644 --- a/modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala +++ b/modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala @@ -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")} - | - | - |${labels.mkString("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")} + | + | + |${labels.mkString("labels: ", ", ", "")} + | + |""".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 + | + |""".stripMargin + + // Github limits PR descriptions to 65536 unicode characters + if (bodyWithMetadata.length < 65536) + bodyWithMetadata + else plainBody + } def renderUpdateInfoUrls(updateInfoUrls: List[UpdateInfoUrl]): Option[String] = Option.when(updateInfoUrls.nonEmpty) {