From 4321c7fd54d8c4cc2d708fe92c3108e6dcd536a9 Mon Sep 17 00:00:00 2001 From: Ivan Semenov Date: Mon, 15 Jun 2020 20:44:57 +0300 Subject: [PATCH] [github] Show merge commit info for PR merge events GitOrigin-RevId: eeec10d8121ef2a06680bfba3836ae024d3ff314 --- .../graphql/fragment/commitShort.graphql | 1 + .../graphql/query/pullRequestTimeline.graphql | 4 +++ .../messages/GithubBundle.properties | 1 + .../plugins/github/api/data/GHCommit.kt | 3 +- .../plugins/github/api/data/GHCommitShort.kt | 4 ++- .../pullrequest/timeline/GHPRMergedEvent.kt | 7 +++-- .../GHPRTimelineEventComponentFactoryImpl.kt | 29 ++++++++++++------- .../timeline/GHPRTimelineMergedStateEvents.kt | 4 +++ .../timeline/GHPRTimelineMergingModelTest.kt | 8 ++--- 9 files changed, 43 insertions(+), 18 deletions(-) diff --git a/plugins/github/resources/graphql/fragment/commitShort.graphql b/plugins/github/resources/graphql/fragment/commitShort.graphql index ce0e3fa49ed0..27e5a0b728a8 100644 --- a/plugins/github/resources/graphql/fragment/commitShort.graphql +++ b/plugins/github/resources/graphql/fragment/commitShort.graphql @@ -1,5 +1,6 @@ fragment commitShort on Commit { ...commitHash + url messageHeadlineHTML author { name diff --git a/plugins/github/resources/graphql/query/pullRequestTimeline.graphql b/plugins/github/resources/graphql/query/pullRequestTimeline.graphql index 64db96d0d634..c52d7d3ec652 100644 --- a/plugins/github/resources/graphql/query/pullRequestTimeline.graphql +++ b/plugins/github/resources/graphql/query/pullRequestTimeline.graphql @@ -59,6 +59,10 @@ fragment mergedEvent on MergedEvent { ...actorInfo } createdAt + commit { + ...commitShort + } + mergeRefName } fragment assignedEvent on AssignedEvent { diff --git a/plugins/github/resources/messages/GithubBundle.properties b/plugins/github/resources/messages/GithubBundle.properties index 2b8b4f584c6a..5f3d805c05f2 100644 --- a/plugins/github/resources/messages/GithubBundle.properties +++ b/plugins/github/resources/messages/GithubBundle.properties @@ -322,6 +322,7 @@ pull.request.timeline.renamed=renamed this from {0} to {1} 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 diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommit.kt b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommit.kt index ff60a678d9ee..843dff195ed8 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommit.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommit.kt @@ -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) - : GHCommitShort(id, oid, abbreviatedOid, messageHeadlineHTML, author) { + : GHCommitShort(id, oid, abbreviatedOid, url, messageHeadlineHTML, author) { val parents = parents.nodes } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommitShort.kt b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommitShort.kt index 51a134e42435..40d19619766e 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommitShort.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/data/GHCommitShort.kt @@ -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) { +} diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRMergedEvent.kt b/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRMergedEvent.kt index e200f6bcbdc9..7606e5bfa230 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRMergedEvent.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/data/pullrequest/timeline/GHPRMergedEvent.kt @@ -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 } \ No newline at end of file diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineEventComponentFactoryImpl.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineEventComponentFactoryImpl.kt index 28536a7d2a61..ebcee57cc6b4 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineEventComponentFactoryImpl.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineEventComponentFactoryImpl.kt @@ -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 = """${mergeEvent.commit.abbreviatedOid}""" + 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 """ -  $name """ - } } private inner class ComplexEventComponentFactory : EventComponentFactory() { @@ -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 """ +  $name """ + } + private fun StringBuilder.appendParagraph(text: String): StringBuilder { if (text.isNotEmpty()) this.append("

").append(text).append("

") return this diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergedStateEvents.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergedStateEvents.kt index 743060e8b3a5..2e5ebddfbd0f 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergedStateEvents.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergedStateEvents.kt @@ -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 } } diff --git a/plugins/github/test/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergingModelTest.kt b/plugins/github/test/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergingModelTest.kt index a6539e71872f..9f232fc8814b 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergingModelTest.kt +++ b/plugins/github/test/org/jetbrains/plugins/github/pullrequest/ui/timeline/GHPRTimelineMergingModelTest.kt @@ -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) }