mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[space] Split commit message on title and description
#IDEA-326754 Fixed GitOrigin-RevId: 469546af05b5eadea834dc7b5a234b43bcb11b9d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
00f9cb922b
commit
6c60e61121
@@ -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<String> {
|
||||
fun splitCommitMessage(commitMessage: String?): Pair<String, String> {
|
||||
//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<Str
|
||||
description = ""
|
||||
}
|
||||
|
||||
return Couple.of(subject, description)
|
||||
return Pair(subject, description)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// 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.codereview.commits
|
||||
|
||||
import com.intellij.collaboration.ui.codereview.commits.splitCommitMessage
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class CodeReviewCommitTest {
|
||||
@Test
|
||||
fun `parse commit message title without description`() {
|
||||
val expectedTitle = "Commit title"
|
||||
val expectedDescription = ""
|
||||
|
||||
val commitMessage = """
|
||||
$expectedTitle
|
||||
""".trimIndent()
|
||||
|
||||
val (title, description) = splitCommitMessage(commitMessage)
|
||||
assertEquals(expectedTitle, title)
|
||||
assertEquals(expectedDescription, description)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parse commit message title with description`() {
|
||||
val expectedTitle = "Commit title"
|
||||
val expectedDescription = """
|
||||
* fixed: commit description
|
||||
""".trimIndent()
|
||||
|
||||
val commitMessage = """
|
||||
$expectedTitle
|
||||
|
||||
$expectedDescription
|
||||
""".trimIndent()
|
||||
|
||||
val (title, description) = splitCommitMessage(commitMessage)
|
||||
assertEquals(expectedTitle, title)
|
||||
assertEquals(expectedDescription, description)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parse commit message title with long description`() {
|
||||
val expectedTitle = "Commit title"
|
||||
val expectedDescription = """
|
||||
* fixed1: commit description1
|
||||
* fixed2: commit description2
|
||||
* fixed3: commit description3
|
||||
""".trimIndent()
|
||||
|
||||
val commitMessage = """
|
||||
$expectedTitle
|
||||
|
||||
$expectedDescription
|
||||
""".trimIndent()
|
||||
|
||||
val (title, description) = splitCommitMessage(commitMessage)
|
||||
assertEquals(expectedTitle, title)
|
||||
assertEquals(expectedDescription, description)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parse commit message title with empty description`() {
|
||||
val expectedTitle = "Commit title"
|
||||
val customDescription = " "
|
||||
|
||||
val commitMessage = """
|
||||
$expectedTitle
|
||||
|
||||
$customDescription
|
||||
""".trimIndent()
|
||||
|
||||
val (title, description) = splitCommitMessage(commitMessage)
|
||||
assertEquals(expectedTitle, title)
|
||||
assertEquals("", description)
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,12 @@ package org.jetbrains.plugins.github.pullrequest.ui.details.model.impl
|
||||
|
||||
import com.intellij.collaboration.async.nestedDisposable
|
||||
import com.intellij.collaboration.messages.CollaborationToolsBundle
|
||||
import com.intellij.collaboration.ui.SingleValueModel
|
||||
import com.intellij.collaboration.ui.asStateFlow
|
||||
import com.intellij.collaboration.ui.codereview.action.ReviewMergeCommitMessageDialog
|
||||
import com.intellij.collaboration.ui.codereview.commits.splitCommitMessage
|
||||
import com.intellij.collaboration.ui.codereview.details.data.ReviewRole
|
||||
import com.intellij.collaboration.ui.codereview.details.data.ReviewState
|
||||
import com.intellij.collaboration.util.CollectionDelta
|
||||
import com.intellij.collaboration.util.SingleCoroutineLauncher
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
@@ -247,14 +245,4 @@ private fun GHPullRequest.isAuthor(user: GHUser): Boolean =
|
||||
private fun GHPullRequest.isReviewer(user: GHUser): Boolean =
|
||||
reviewRequests.any { it.requestedReviewer?.id == user.id }
|
||||
||
|
||||
reviews.any { it.author?.id == user.id }
|
||||
|
||||
private fun splitCommitMessage(commitMessage: String): Pair<String, String> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
reviews.any { it.author?.id == user.id }
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user