Skip to content

Commit 876f4fb

Browse files
authored
Merge pull request #3572 from scala-steward-org/pr-length-per-forge
Make maximum Pull Request length configurable
2 parents c1848e2 + 4ae99ff commit 876f4fb

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

modules/core/src/main/scala/org/scalasteward/core/forge/ForgeType.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ sealed trait ForgeType extends Product with Serializable {
4949
*/
5050
def pullRequestHeadFor(@nowarn fork: Repo, updateBranch: Branch): String = updateBranch.name
5151

52+
val maximumPullRequestLength: Int = 65536
53+
5254
val asString: String = this match {
5355
case AzureRepos => "azure-repos"
5456
case Bitbucket => "bitbucket"
@@ -66,6 +68,7 @@ object ForgeType {
6668
case object AzureRepos extends ForgeType {
6769
override val publicWebHost: Some[String] = Some("dev.azure.com")
6870
override def supportsForking: Boolean = false
71+
override val maximumPullRequestLength: Int = 4000
6972
val diffs: DiffUriPattern = (from, to) =>
7073
_ / "branchCompare" +? ("baseVersion", s"GT$from") +? ("targetVersion", s"GT$to")
7174
val files: FileUriPattern =
@@ -93,6 +96,7 @@ object ForgeType {
9396
override val publicWebHost: None.type = None
9497
override def supportsForking: Boolean = false
9598
override def supportsLabels: Boolean = false
99+
override val maximumPullRequestLength: Int = 32768
96100
val diffs: DiffUriPattern = Bitbucket.diffs
97101
val files: FileUriPattern = fileName => _ / "browse" / fileName
98102
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ object NewPullRequestData {
4949
artifactIdToUpdateInfoUrls: Map[String, List[UpdateInfoUrl]],
5050
filesWithOldVersion: List[String],
5151
configParsingError: Option[String],
52-
labels: List[String]
52+
labels: List[String],
53+
maximumPullRequestLength: Int
5354
): String = {
5455
val migrations = edits.collect { case scalafixEdit: ScalafixEdit => scalafixEdit }
5556
val appliedMigrations = migrationNote(migrations)
@@ -129,8 +130,7 @@ object NewPullRequestData {
129130
|
130131
|<!-- scala-steward = $metadataJson -->""".stripMargin
131132

132-
// Github limits PR descriptions to 65536 unicode characters
133-
if (bodyWithMetadata.length < 65536)
133+
if (bodyWithMetadata.length < maximumPullRequestLength)
134134
bodyWithMetadata
135135
else plainBody
136136
}
@@ -264,7 +264,8 @@ object NewPullRequestData {
264264
artifactIdToUpdateInfoUrls: Map[String, List[UpdateInfoUrl]] = Map.empty,
265265
filesWithOldVersion: List[String] = List.empty,
266266
addLabels: Boolean = false,
267-
labels: List[String] = List.empty
267+
labels: List[String] = List.empty,
268+
maximumPullRequestLength: Int = 65536
268269
): NewPullRequestData =
269270
NewPullRequestData(
270271
title = CommitMsg
@@ -280,7 +281,8 @@ object NewPullRequestData {
280281
artifactIdToUpdateInfoUrls,
281282
filesWithOldVersion,
282283
data.repoData.cache.maybeRepoConfigParsingError,
283-
labels
284+
labels,
285+
maximumPullRequestLength
284286
),
285287
head = branchName,
286288
base = data.baseBranch,

modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ final class NurtureAlg[F[_]](config: ForgeCfg)(implicit
241241
artifactIdToUpdateInfoUrls = artifactIdToUpdateInfoUrls.toMap,
242242
filesWithOldVersion = filesWithOldVersion,
243243
addLabels = config.addLabels,
244-
labels = data.repoData.config.pullRequestsOrDefault.customLabelsOrDefault ++ labels
244+
labels = data.repoData.config.pullRequestsOrDefault.customLabelsOrDefault ++ labels,
245+
maximumPullRequestLength = config.tpe.maximumPullRequestLength
245246
)
246247

247248
private def createPullRequest(data: UpdateData, edits: List[EditAttempt]): F[ProcessResult] =

modules/core/src/test/scala/org/scalasteward/core/forge/data/NewPullRequestDataTest.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class NewPullRequestDataTest extends FunSuite {
2525
artifactIdToUpdateInfoUrls = Map.empty,
2626
filesWithOldVersion = List.empty,
2727
configParsingError = None,
28-
labels = List("library-update")
28+
labels = List("library-update"),
29+
maximumPullRequestLength = 65536
2930
)
3031
val expected =
3132
s"""|## About this PR
@@ -114,7 +115,8 @@ class NewPullRequestDataTest extends FunSuite {
114115
artifactIdToUpdateInfoUrls = Map.empty,
115116
filesWithOldVersion = List.empty,
116117
configParsingError = None,
117-
labels = List("library-update")
118+
labels = List("library-update"),
119+
maximumPullRequestLength = 65536
118120
)
119121
val expected =
120122
s"""|## About this PR
@@ -200,7 +202,8 @@ class NewPullRequestDataTest extends FunSuite {
200202
artifactIdToUpdateInfoUrls = Map.empty,
201203
filesWithOldVersion = List.empty,
202204
configParsingError = None,
203-
labels = List("library-update")
205+
labels = List("library-update"),
206+
maximumPullRequestLength = 65536
204207
)
205208
val expected =
206209
s"""|## About this PR
@@ -320,7 +323,8 @@ class NewPullRequestDataTest extends FunSuite {
320323
artifactIdToUpdateInfoUrls = Map.empty,
321324
filesWithOldVersion = List.empty,
322325
configParsingError = Some("parsing error"),
323-
labels = List("library-update")
326+
labels = List("library-update"),
327+
maximumPullRequestLength = 65536
324328
)
325329
val expected =
326330
s"""|## About this PR
@@ -1004,7 +1008,8 @@ class NewPullRequestDataTest extends FunSuite {
10041008
"early-semver-major",
10051009
"semver-spec-minor",
10061010
"commit-count:1"
1007-
)
1011+
),
1012+
maximumPullRequestLength = 65536
10081013
)
10091014
val expected =
10101015
s"""|## About this PR
@@ -1089,7 +1094,8 @@ class NewPullRequestDataTest extends FunSuite {
10891094
"early-semver-major",
10901095
"semver-spec-minor",
10911096
"commit-count:1"
1092-
)
1097+
),
1098+
maximumPullRequestLength = 65536
10931099
)
10941100
val expected =
10951101
s"""|## About this PR

0 commit comments

Comments
 (0)