Skip to content

Commit 5b1fa0f

Browse files
committed
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
1 parent dce40bb commit 5b1fa0f

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

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

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,35 +96,45 @@ object NewPullRequestData {
9696
_ => ""
9797
)
9898

99-
s"""|$updatesText
100-
|
101-
|## Usage
102-
|✅ **Please merge!**
103-
|
104-
|I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.
105-
|
106-
|${skipVersionMessage}If you have any feedback, just mention me in the comments below.
107-
|
108-
|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.
109-
|
110-
|_Have a fantastic day writing Scala!_
111-
|
112-
|${details.map(_.toHtml).mkString("\n")}
113-
|
114-
|<sup>
115-
|${labels.mkString("labels: ", ", ", "")}
116-
|</sup>
117-
|
118-
|<!-- scala-steward = ${metadataJson(update, labels)} -->""".stripMargin.trim
119-
}
99+
val plainBody =
100+
s"""|$updatesText
101+
|
102+
|## Usage
103+
|✅ **Please merge!**
104+
|
105+
|I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.
106+
|
107+
|${skipVersionMessage}If you have any feedback, just mention me in the comments below.
108+
|
109+
|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.
110+
|
111+
|_Have a fantastic day writing Scala!_
112+
|
113+
|${details.map(_.toHtml).mkString("\n")}
114+
|
115+
|<sup>
116+
|${labels.mkString("labels: ", ", ", "")}
117+
|</sup>
118+
|""".stripMargin.trim
120119

121-
def metadataJson(update: Update, labels: List[String]): String =
122-
Json
123-
.obj(
124-
"Update" -> update.asJson,
125-
"Labels" -> Json.fromValues(labels.map(_.asJson))
126-
)
127-
.toString
120+
val metadataJson =
121+
Json
122+
.obj(
123+
"Update" -> update.asJson,
124+
"Labels" -> Json.fromValues(labels.map(_.asJson))
125+
)
126+
.toString
127+
128+
val bodyWithMetadata =
129+
s"""$plainBody
130+
|
131+
|<!-- scala-steward = $metadataJson -->""".stripMargin
132+
133+
// Github limits PR descriptions to 65536 unicode characters
134+
if (bodyWithMetadata.length < 65536)
135+
bodyWithMetadata
136+
else plainBody
137+
}
128138

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

0 commit comments

Comments
 (0)