From 6c60e611215c459e4e8557ecf3901c2ecf0c0999 Mon Sep 17 00:00:00 2001 From: Pavel Gromov Date: Wed, 23 Aug 2023 15:59:02 +0200 Subject: [PATCH] [space] Split commit message on title and description #IDEA-326754 Fixed GitOrigin-RevId: 469546af05b5eadea834dc7b5a234b43bcb11b9d --- .../ui/codereview/commits/commitsUtil.kt | 12 ++- .../commits/CodeReviewCommitTest.kt | 76 +++++++++++++++++++ .../model/impl/GHPRReviewFlowViewModelImpl.kt | 16 +--- .../plugins/github/GithubUtilTest.kt | 4 +- 4 files changed, 85 insertions(+), 23 deletions(-) create mode 100644 platform/collaboration-tools/test/com/intellij/collaboration/codereview/commits/CodeReviewCommitTest.kt diff --git a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/commits/commitsUtil.kt b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/commits/commitsUtil.kt index c0eed9093f1f..71010f14bc06 100644 --- a/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/commits/commitsUtil.kt +++ b/platform/collaboration-tools/src/com/intellij/collaboration/ui/codereview/commits/commitsUtil.kt @@ -1,21 +1,19 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.collaboration.ui.codereview.commits -import com.intellij.openapi.util.Couple - /** - * Splits full commit message into subject and description in GitHub style: + * Splits full commit message into subject and description: * First line becomes subject, everything after first line becomes description * Also supports empty line that separates subject and description * * @param commitMessage full commit message - * @return couple of subject and description based on full commit message + * @return pair of subject and description based on full commit message */ -fun getGithubLikeFormattedDescriptionMessage(commitMessage: String?): Couple { +fun splitCommitMessage(commitMessage: String?): Pair { //Trim original val message = commitMessage?.trim { it <= ' ' } ?: "" if (message.isEmpty()) { - return Couple.of("", "") + return Pair("", "") } val firstLineEnd = message.indexOf("\n") val subject: String @@ -33,5 +31,5 @@ fun getGithubLikeFormattedDescriptionMessage(commitMessage: String?): Couple { - val idx = commitMessage.indexOf("\n\n") - return if (idx < 0) "" to commitMessage - else { - val subject = commitMessage.substring(0, idx) - if (subject.contains("\n")) "" to commitMessage - else subject to commitMessage.substring(idx + 2) - } -} \ No newline at end of file + reviews.any { it.author?.id == user.id } \ No newline at end of file diff --git a/plugins/github/test/org/jetbrains/plugins/github/GithubUtilTest.kt b/plugins/github/test/org/jetbrains/plugins/github/GithubUtilTest.kt index 108e24402857..bf8ac50c81b3 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/GithubUtilTest.kt +++ b/plugins/github/test/org/jetbrains/plugins/github/GithubUtilTest.kt @@ -1,7 +1,7 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.github -import com.intellij.collaboration.ui.codereview.commits.getGithubLikeFormattedDescriptionMessage +import com.intellij.collaboration.ui.codereview.commits.splitCommitMessage import org.junit.Assert.assertEquals import org.junit.Test @@ -37,7 +37,7 @@ class GithubUtilTest { } private fun assertCommitMessage(expectedSubject: String, expectedDescription: String, fullMessage: String?) { - val message = getGithubLikeFormattedDescriptionMessage(fullMessage) + val message = splitCommitMessage(fullMessage) assertEquals(expectedSubject, message.first) assertEquals(expectedDescription, message.second) }