[github] Make changesComputationState an internal-API function

(cherry picked from commit ddf495030801429d9bbcc8977468e0129e4787eb)


(cherry picked from commit 8553adf7d89bc793125e90a7fbf60d91beaec11d)

IJ-CR-148445

GitOrigin-RevId: 49a1e4ea9971ff0a3d871eacbe1cad9516a0f7c1
This commit is contained in:
Chris Lemaire
2024-10-22 13:38:12 +02:00
committed by intellij-monorepo-bot
parent 9b6b287618
commit 401e8f31e5
6 changed files with 12 additions and 9 deletions

View File

@@ -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<List<GHCommit>>
}
internal val GHPRChangesDataProvider.changesComputationState: Flow<ComputedResult<GitBranchComparisonResult>>
get() = computationStateFlow(changesNeedReloadSignal.withInitial(Unit)) { loadChanges() }
@ApiStatus.Internal
fun GHPRChangesDataProvider.changesComputationState(): Flow<ComputedResult<GitBranchComparisonResult>> =
computationStateFlow(changesNeedReloadSignal.withInitial(Unit)) { loadChanges() }

View File

@@ -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)
}

View File

@@ -59,7 +59,7 @@ internal class GHPRReviewNewCommentEditorViewModelImpl(
private val settings = GithubPullRequestsProjectUISettings.getInstance(project)
private val reviewDataProvider = dataProvider.reviewData
private val changesState: StateFlow<ComputedResult<GitBranchComparisonResult>> =
dataProvider.changesData.changesComputationState.stateInNow(cs, ComputedResult.loading())
dataProvider.changesData.changesComputationState().stateInNow(cs, ComputedResult.loading())
private val pendingReviewState: StateFlow<ComputedResult<GHPullRequestPendingReview?>> =
reviewDataProvider.pendingReviewComputationFlow.stateInNow(cs, ComputedResult.loading())

View File

@@ -42,7 +42,7 @@ internal class GHPRBranchWidgetViewModelImpl(
override val updateRequired: StateFlow<Boolean> = sharedBranchVm.updateRequired
override val dataLoadingState: StateFlow<ComputedResult<Any>> =
dataProvider.changesData.changesComputationState.stateInNow(cs, ComputedResult.loading())
dataProvider.changesData.changesComputationState().stateInNow(cs, ComputedResult.loading())
override val editorReviewEnabled: StateFlow<Boolean> = settings.editorReviewEnabledState

View File

@@ -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<Boolean> = _repliesFolded.asStateFlow()
private val currentChanges = dataProvider.changesData.changesComputationState
private val currentChanges = dataProvider.changesData.changesComputationState()
.mapNotNull { it.getOrNull() }
.stateIn(cs, SharingStarted.Eagerly, null)

View File

@@ -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)) {