[github] Show merge commit info for PR merge events

GitOrigin-RevId: eeec10d8121ef2a06680bfba3836ae024d3ff314
This commit is contained in:
Ivan Semenov
2020-06-16 22:26:05 +03:00
committed by intellij-monorepo-bot
parent 59359004be
commit 4321c7fd54
9 changed files with 43 additions and 18 deletions
@@ -1,5 +1,6 @@
fragment commitShort on Commit {
...commitHash
url
messageHeadlineHTML
author {
name
@@ -59,6 +59,10 @@ fragment mergedEvent on MergedEvent {
...actorInfo
}
createdAt
commit {
...commitShort
}
mergeRefName
}
fragment assignedEvent on AssignedEvent {
@@ -322,6 +322,7 @@ pull.request.timeline.renamed=renamed this from <b>{0}</b> to <b>{1}</b>
pull.request.timeline.reopened=reopened this
pull.request.timeline.closed=closed this
pull.request.timeline.merged=merged this
pull.request.timeline.merged.commit=merged commit {0} into {1}
pull.request.timeline.requested.review=requested a review from
pull.request.timeline.removed.review.request=removed review request from
pull.request.timeline.started.review=started a review
@@ -6,13 +6,14 @@ import com.fasterxml.jackson.annotation.JsonProperty
class GHCommit(id: String,
oid: String,
abbreviatedOid: String,
url: String,
val messageHeadline: String,
messageHeadlineHTML: String,
val messageBodyHTML: String,
author: GHGitActor?,
val committer: GHGitActor?,
@JsonProperty("parents") parents: GHNodes<GHCommitHash>)
: GHCommitShort(id, oid, abbreviatedOid, messageHeadlineHTML, author) {
: GHCommitShort(id, oid, abbreviatedOid, url, messageHeadlineHTML, author) {
val parents = parents.nodes
}
@@ -4,6 +4,8 @@ package org.jetbrains.plugins.github.api.data
open class GHCommitShort(id: String,
oid: String,
abbreviatedOid: String,
val url: String,
val messageHeadlineHTML: String,
val author: GHGitActor?)
: GHCommitHash(id, oid, abbreviatedOid)
: GHCommitHash(id, oid, abbreviatedOid) {
}
@@ -1,12 +1,15 @@
// Copyright 2000-2019 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.
// Copyright 2000-2020 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.api.data.pullrequest.timeline
import org.jetbrains.plugins.github.api.data.GHActor
import org.jetbrains.plugins.github.api.data.GHCommitShort
import org.jetbrains.plugins.github.api.data.pullrequest.GHPullRequestState
import java.util.*
class GHPRMergedEvent(override val actor: GHActor?,
override val createdAt: Date)
override val createdAt: Date,
val commit: GHCommitShort?,
val mergeRefName: String)
: GHPRTimelineEvent.State {
override val newState = GHPullRequestState.MERGED
}
@@ -167,7 +167,16 @@ class GHPRTimelineEventComponentFactoryImpl(private val avatarIconsProvider: GHA
val text = when (event.newState) {
GHPullRequestState.CLOSED -> GithubBundle.message("pull.request.timeline.closed")
GHPullRequestState.MERGED -> GithubBundle.message("pull.request.timeline.merged")
GHPullRequestState.MERGED -> {
val mergeEvent = (if (event is GHPRTimelineMergedStateEvents) event.lastStateEvent else event) as GHPRMergedEvent
if (mergeEvent.commit != null) {
//language=HTML
val commitText = """<a href='${mergeEvent.commit.url}'>${mergeEvent.commit.abbreviatedOid}</a>"""
val ref = branchHTML(mergeEvent.mergeRefName)
GithubBundle.message("pull.request.timeline.merged.commit", commitText, ref)
}
else GithubBundle.message("pull.request.timeline.merged")
}
GHPullRequestState.OPEN -> GithubBundle.message("pull.request.timeline.reopened")
}
@@ -195,15 +204,6 @@ class GHPRTimelineEventComponentFactoryImpl(private val avatarIconsProvider: GHA
}
private fun branchHTML(ref: GHGitRefName?) = ref?.name?.let { branchHTML(it) }
//language=HTML
private fun branchHTML(name: String): String {
val foreground = CurrentBranchComponent.TEXT_COLOR
val background = CurrentBranchComponent.getBranchPresentationBackground(UIUtil.getListBackground())
return """<span style='color: #${ColorUtil.toHex(foreground)}; background: #${ColorUtil.toHex(background)}'>
&nbsp;<icon-inline src='GithubIcons.Branch'/>$name&nbsp;</span>"""
}
}
private inner class ComplexEventComponentFactory : EventComponentFactory<GHPRTimelineEvent.Complex>() {
@@ -234,6 +234,15 @@ class GHPRTimelineEventComponentFactoryImpl(private val avatarIconsProvider: GHA
}
companion object {
private fun branchHTML(name: String): String {
val foreground = CurrentBranchComponent.TEXT_COLOR
val background = CurrentBranchComponent.getBranchPresentationBackground(UIUtil.getListBackground())
//language=HTML
return """<span style='color: #${ColorUtil.toHex(foreground)}; background: #${ColorUtil.toHex(background)}'>
&nbsp;<icon-inline src='GithubIcons.Branch'/>$name&nbsp;</span>"""
}
private fun StringBuilder.appendParagraph(text: String): StringBuilder {
if (text.isNotEmpty()) this.append("<p>").append(text).append("</p>")
return this
@@ -18,9 +18,13 @@ class GHPRTimelineMergedStateEvents(initialState: GHPRTimelineEvent.State) : GHP
override var newState: GHPullRequestState = initialState.newState
private set
var lastStateEvent = initialState
private set
override fun addNonMergedEvent(event: GHPRTimelineEvent.State) {
if (newState != GHPullRequestState.MERGED) {
newState = event.newState
lastStateEvent = event
}
}
@@ -49,7 +49,7 @@ class GHPRTimelineMergingModelTest : UsefulTestCase() {
GHPRRenamedTitleEvent(actor1, currentDate, "old", "new"),
GHPRClosedEvent(actor1, currentDate),
GHPRReopenedEvent(actor1, currentDate),
GHPRMergedEvent(actor1, currentDate)
GHPRMergedEvent(actor1, currentDate, null, "master")
))
assertEquals(2, model.size)
@@ -63,7 +63,7 @@ class GHPRTimelineMergingModelTest : UsefulTestCase() {
model.add(listOf(GHPRClosedEvent(actor1, currentDate)))
model.add(listOf(GHPRReopenedEvent(actor1, currentDate)))
model.add(listOf(GHPRMergedEvent(actor1, currentDate)))
model.add(listOf(GHPRMergedEvent(actor1, currentDate, null, "master")))
assertEquals(2, model.size)
}
@@ -120,7 +120,7 @@ class GHPRTimelineMergingModelTest : UsefulTestCase() {
//date difference
GHPRReopenedEvent(actor1, Date(currentDate.time + DateFormatUtil.YEAR)),
//actor difference
GHPRMergedEvent(actor2, Date(currentDate.time + DateFormatUtil.YEAR))
GHPRMergedEvent(actor2, Date(currentDate.time + DateFormatUtil.YEAR), null, "master")
))
assertEquals(7, model.size)
}
@@ -132,7 +132,7 @@ class GHPRTimelineMergingModelTest : UsefulTestCase() {
model.add(listOf(GHPRAssignedEvent(actor1, currentDate, createTestUser("user3"))))
model.add(listOf(GHPRClosedEvent(actor1, currentDate)))
model.add(listOf(GHPRReopenedEvent(actor1, Date(currentDate.time + DateFormatUtil.YEAR))))
model.add(listOf(GHPRMergedEvent(actor2, Date(currentDate.time + DateFormatUtil.YEAR))))
model.add(listOf(GHPRMergedEvent(actor2, Date(currentDate.time + DateFormatUtil.YEAR), null, "master")))
assertEquals(7, model.size)
}