From 401e8f31e5404401d08c681be825940894ffe7bf Mon Sep 17 00:00:00 2001 From: Chris Lemaire Date: Tue, 22 Oct 2024 13:38:12 +0200 Subject: [PATCH] [github] Make changesComputationState an internal-API function (cherry picked from commit ddf495030801429d9bbcc8977468e0129e4787eb) (cherry picked from commit 8553adf7d89bc793125e90a7fbf60d91beaec11d) IJ-CR-148445 GitOrigin-RevId: 49a1e4ea9971ff0a3d871eacbe1cad9516a0f7c1 --- .../pullrequest/data/provider/GHPRChangesDataProvider.kt | 6 ++++-- .../pullrequest/ui/editor/GHPRReviewInEditorViewModel.kt | 2 +- .../ui/editor/GHPRReviewNewCommentEditorViewModel.kt | 2 +- .../pullrequest/ui/review/GHPRBranchWidgetViewModel.kt | 2 +- .../ui/timeline/item/GHPRTimelineThreadViewModel.kt | 3 +-- .../data/provider/GHPRChangesDataProviderImplTest.kt | 6 ++++-- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProvider.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProvider.kt index 8342de7ed711..d5f7da0f4dea 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProvider.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProvider.kt @@ -7,6 +7,7 @@ import com.intellij.collaboration.util.ComputedResult import com.intellij.openapi.diff.impl.patch.FilePatch import git4idea.changes.GitBranchComparisonResult import kotlinx.coroutines.flow.Flow +import org.jetbrains.annotations.ApiStatus import org.jetbrains.plugins.github.api.data.GHCommit import java.util.concurrent.CompletableFuture @@ -28,5 +29,6 @@ interface GHPRChangesDataProvider { fun loadCommitsFromApi(): CompletableFuture> } -internal val GHPRChangesDataProvider.changesComputationState: Flow> - get() = computationStateFlow(changesNeedReloadSignal.withInitial(Unit)) { loadChanges() } +@ApiStatus.Internal +fun GHPRChangesDataProvider.changesComputationState(): Flow> = + computationStateFlow(changesNeedReloadSignal.withInitial(Unit)) { loadChanges() } diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewInEditorViewModel.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewInEditorViewModel.kt index 6d5f666a5ffc..dfc0ed92ba56 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewInEditorViewModel.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewInEditorViewModel.kt @@ -47,7 +47,7 @@ internal class GHPRReviewInEditorViewModelImpl( private val repository = dataContext.repositoryDataService.repositoryMapping.gitRepository private val changesComputationState = - dataProvider.changesData.changesComputationState.onEach { + dataProvider.changesData.changesComputationState().onEach { it.onFailure { LOG.warn("Couldn't load changes for PR ${dataProvider.id.number}", it) } diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt index d466fc19d3d0..768a7caa7112 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/editor/GHPRReviewNewCommentEditorViewModel.kt @@ -59,7 +59,7 @@ internal class GHPRReviewNewCommentEditorViewModelImpl( private val settings = GithubPullRequestsProjectUISettings.getInstance(project) private val reviewDataProvider = dataProvider.reviewData private val changesState: StateFlow> = - dataProvider.changesData.changesComputationState.stateInNow(cs, ComputedResult.loading()) + dataProvider.changesData.changesComputationState().stateInNow(cs, ComputedResult.loading()) private val pendingReviewState: StateFlow> = reviewDataProvider.pendingReviewComputationFlow.stateInNow(cs, ComputedResult.loading()) diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/review/GHPRBranchWidgetViewModel.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/review/GHPRBranchWidgetViewModel.kt index fab97c674b31..3b02c15d24f4 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/review/GHPRBranchWidgetViewModel.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/review/GHPRBranchWidgetViewModel.kt @@ -42,7 +42,7 @@ internal class GHPRBranchWidgetViewModelImpl( override val updateRequired: StateFlow = sharedBranchVm.updateRequired override val dataLoadingState: StateFlow> = - dataProvider.changesData.changesComputationState.stateInNow(cs, ComputedResult.loading()) + dataProvider.changesData.changesComputationState().stateInNow(cs, ComputedResult.loading()) override val editorReviewEnabled: StateFlow = settings.editorReviewEnabledState diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/item/GHPRTimelineThreadViewModel.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/item/GHPRTimelineThreadViewModel.kt index 8be457d0efea..9899dc4eba08 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/item/GHPRTimelineThreadViewModel.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/ui/timeline/item/GHPRTimelineThreadViewModel.kt @@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.vcs.actions.VcsContextFactory import com.intellij.platform.util.coroutines.childScope import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.CoroutineName import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.* @@ -131,7 +130,7 @@ class UpdateableGHPRTimelineThreadViewModel internal constructor( private val _repliesFolded = MutableStateFlow(true) override val repliesFolded: StateFlow = _repliesFolded.asStateFlow() - private val currentChanges = dataProvider.changesData.changesComputationState + private val currentChanges = dataProvider.changesData.changesComputationState() .mapNotNull { it.getOrNull() } .stateIn(cs, SharingStarted.Eagerly, null) diff --git a/plugins/github/test/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImplTest.kt b/plugins/github/test/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImplTest.kt index 6ef99418e0e2..6fbd26dda4de 100644 --- a/plugins/github/test/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImplTest.kt +++ b/plugins/github/test/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImplTest.kt @@ -6,7 +6,9 @@ import com.intellij.collaboration.util.ComputedResult import com.intellij.collaboration.util.FlowTestUtil.assertEmits import com.intellij.collaboration.util.MainDispatcherRule import git4idea.changes.GitBranchComparisonResult -import io.mockk.* +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.mockk import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.test.TestScope @@ -80,7 +82,7 @@ class GHPRChangesDataProviderImplTest { } } val inst = createProvider(refs) - inst.changesComputationState.assertEmits(ComputedResult.loading(), + inst.changesComputationState().assertEmits(ComputedResult.loading(), ComputedResult.failure(EXCEPTION), ComputedResult.loading(), ComputedResult.success(result)) {