Commit 9374390d authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Merge remote-tracking branch...

Merge remote-tracking branch 'remotes/origin/feature/project_file_code_highlight' into feature/project_file_code_highlight_basic

# Conflicts:
#	app/src/main/java/ru/terrakok/gitlabclient/model/interactor/project/ProjectInteractor.kt
#	app/src/main/java/ru/terrakok/gitlabclient/presentation/file/ProjectFilePresenter.kt
#	app/src/main/java/ru/terrakok/gitlabclient/presentation/mergerequest/changes/MergeRequestChangesPresenter.kt
parents 57a23049 fa08ac61
......@@ -243,9 +243,9 @@ object Screens {
data class ProjectFile(
val projectId: Long,
val filePath: String,
val branchName: String
val fileReference: String
) : SupportAppScreen() {
override fun getFragment() = ProjectFileFragment.create(projectId, filePath, branchName)
override fun getFragment() = ProjectFileFragment.create(projectId, filePath, fileReference)
}
data class ExternalBrowserFlow(
......
......@@ -3,8 +3,8 @@ package ru.terrakok.gitlabclient.entity.mergerequest
import com.google.gson.annotations.SerializedName
import org.threeten.bp.LocalDateTime
import ru.terrakok.gitlabclient.entity.Author
import ru.terrakok.gitlabclient.entity.milestone.Milestone
import ru.terrakok.gitlabclient.entity.User
import ru.terrakok.gitlabclient.entity.milestone.Milestone
data class MergeRequest(
@SerializedName("id") val id: Long,
......@@ -27,7 +27,7 @@ data class MergeRequest(
@SerializedName("milestone") val milestone: Milestone?,
@SerializedName("merge_when_pipeline_succeeds") val mergeWhenPipelineSucceeds: Boolean,
@SerializedName("merge_status") val mergeStatus: String?,
@SerializedName("sha") val sha: String?,
@SerializedName("sha") val sha: String,
@SerializedName("merge_commit_sha") val mergeCommitSha: String?,
@SerializedName("user_notes_count") val userNotesCount: Int,
@SerializedName("should_remove_source_branch") val shouldRemoveSourceBranch: Boolean,
......
......@@ -57,7 +57,7 @@ interface GitlabApi {
fun getFile(
@Path("id") id: Long,
@Path("file_path") filePath: String,
@Query("ref") branchName: String
@Query("ref") ref: String
): Single<File>
@GET("$API_PATH/projects/{id}/repository/tree")
......
......@@ -43,8 +43,8 @@ class ProjectInteractor @Inject constructor(
fun getProject(id: Long) = projectRepository.getProject(id)
fun getProjectFileRawCode(projectId: Long, path: String, branchName: String): Single<String> =
projectRepository.getBlobFile(projectId, path, branchName)
fun getProjectFileRawCode(projectId: Long, path: String, fileReference: String): Single<String> =
projectRepository.getProjectFile(projectId, path, fileReference)
.observeOn(schedulers.computation())
.map { file -> base64Tools.decode(file.content) }
.observeOn(schedulers.ui())
......@@ -56,7 +56,7 @@ class ProjectInteractor @Inject constructor(
val readmePath = project.readmeUrl.substringAfter(
"${project.webUrl}/blob/${project.defaultBranch}/"
)
projectRepository.getBlobFile(project.id, readmePath, project.defaultBranch)
projectRepository.getProjectFile(project.id, readmePath, project.defaultBranch)
} else {
Single.error(ReadmeNotFound())
}
......
......@@ -56,12 +56,12 @@ class ProjectRepository @Inject constructor(
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
fun getBlobFile(
fun getProjectFile(
projectId: Long,
path: String,
branchName: String
fileReference: String
) = api
.getFile(projectId, path, branchName)
.getFile(projectId, path, fileReference)
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
......
......@@ -7,8 +7,8 @@ import ru.terrakok.gitlabclient.model.interactor.project.ProjectInteractor
import ru.terrakok.gitlabclient.presentation.global.BasePresenter
import ru.terrakok.gitlabclient.presentation.global.ErrorHandler
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
import ru.terrakok.gitlabclient.toothpick.qualifier.BranchName
import ru.terrakok.gitlabclient.toothpick.qualifier.FilePath
import ru.terrakok.gitlabclient.toothpick.qualifier.FileReference
import ru.terrakok.gitlabclient.toothpick.qualifier.ProjectId
import javax.inject.Inject
......@@ -19,7 +19,7 @@ import javax.inject.Inject
class ProjectFilePresenter @Inject constructor(
@ProjectId projectIdWrapper: PrimitiveWrapper<Long>,
@FilePath private val filePath: String,
@BranchName private val branchName: String,
@FileReference private val fileReference: String,
private val projectInteractor: ProjectInteractor,
private val errorHandler: ErrorHandler,
private val router: Router
......@@ -30,7 +30,7 @@ class ProjectFilePresenter @Inject constructor(
override fun onFirstViewAttach() {
super.onFirstViewAttach()
viewState.setTitle(filePath.extractFileNameFromPath())
projectInteractor.getProjectFileRawCode(projectId, filePath, branchName)
projectInteractor.getProjectFileRawCode(projectId, filePath, fileReference)
.doOnSubscribe { viewState.showEmptyProgress(true) }
.doAfterTerminate { viewState.showEmptyProgress(false) }
.subscribe(
......
......@@ -115,8 +115,7 @@ class MergeRequestChangesPresenter @Inject constructor(
.doOnSubscribe { viewState.showFullscreenProgress(true) }
.doAfterTerminate { viewState.showFullscreenProgress(false) }
.subscribe(
// TODO: code highlight (At this time request for file is not working with response 404).
{ flowRouter.startFlow(Screens.ProjectFile(projectId, item.newPath, it.sourceBranch)) },
{ flowRouter.startFlow(Screens.ProjectFile(projectId, item.newPath, it.sha)) },
{ errorHandler.proceed(it, { viewState.showMessage(it) }) }
)
.connect()
......
......@@ -46,4 +46,4 @@ annotation class WithErrorHandler
annotation class FilePath
@Qualifier
annotation class BranchName
\ No newline at end of file
annotation class FileReference
\ No newline at end of file
......@@ -12,8 +12,8 @@ import ru.terrakok.gitlabclient.presentation.file.ProjectFilePresenter
import ru.terrakok.gitlabclient.presentation.file.ProjectFileView
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
import ru.terrakok.gitlabclient.toothpick.qualifier.BranchName
import ru.terrakok.gitlabclient.toothpick.qualifier.FilePath
import ru.terrakok.gitlabclient.toothpick.qualifier.FileReference
import ru.terrakok.gitlabclient.toothpick.qualifier.ProjectId
import ru.terrakok.gitlabclient.ui.global.BaseFragment
import toothpick.Scope
......@@ -26,7 +26,7 @@ class ProjectFileFragment : BaseFragment(), ProjectFileView {
private val projectId by argument(ARG_PROJECT_ID, 0L)
private val filePath by argument<String>(ARG_FILE_PATH, null)
private val branchName by argument<String>(ARG_BRANCH_NAME, null)
private val fileReference by argument<String>(ARG_FILE_REFERENCE, null)
override val layoutRes = R.layout.fragment_project_file
......@@ -43,8 +43,8 @@ class ProjectFileFragment : BaseFragment(), ProjectFileView {
.withName(FilePath::class.java)
.toInstance(filePath)
bind(String::class.java)
.withName(BranchName::class.java)
.toInstance(branchName)
.withName(FileReference::class.java)
.toInstance(fileReference)
}
}
)
......@@ -85,14 +85,14 @@ class ProjectFileFragment : BaseFragment(), ProjectFileView {
companion object {
private const val ARG_PROJECT_ID = "arg_project_id"
private const val ARG_FILE_PATH = "arg_file_path"
private const val ARG_BRANCH_NAME = "arg_branch_name"
private const val ARG_FILE_REFERENCE = "arg_file_reference"
fun create(projectId: Long, filePath: String, branchName: String) =
fun create(projectId: Long, filePath: String, fileReference: String) =
ProjectFileFragment().apply {
arguments = Bundle().apply {
putLong(ARG_PROJECT_ID, projectId)
putString(ARG_FILE_PATH, filePath)
putString(ARG_BRANCH_NAME, branchName)
putString(ARG_FILE_REFERENCE, fileReference)
}
}
}
......
......@@ -103,7 +103,7 @@ class ProjectInteractorTest {
val testFile = File("", "", 0L, "", testFileContent, testProject.defaultBranch, "", "", "")
val repo = mock(ProjectRepository::class.java)
`when`(repo.getBlobFile(anyLong(), anyString(), anyString())).thenReturn(Single.just(testFile))
`when`(repo.getProjectFile(anyLong(), anyString(), anyString())).thenReturn(Single.just(testFile))
val base64 = mock(Base64Tools::class.java)
`when`(base64.decode(anyString())).thenReturn(raw)
......@@ -113,7 +113,7 @@ class ProjectInteractorTest {
val testObserver: TestObserver<String> = interactor.getProjectReadme(testProject).test()
testObserver.awaitTerminalEvent()
verify(repo, times(1)).getBlobFile(projectId, "README.md", branchName)
verify(repo, times(1)).getProjectFile(projectId, "README.md", branchName)
verify(base64, times(1)).decode(testFileContent)
testObserver
.assertValueCount(1)
......@@ -126,7 +126,7 @@ class ProjectInteractorTest {
val error = RuntimeException("test error")
val repo = mock(ProjectRepository::class.java)
`when`(repo.getBlobFile(anyLong(), anyString(), anyString())).thenReturn(Single.error(error))
`when`(repo.getProjectFile(anyLong(), anyString(), anyString())).thenReturn(Single.error(error))
val mdConverter = mock(MarkDownConverter::class.java)
val base64 = mock(Base64Tools::class.java)
......@@ -136,7 +136,7 @@ class ProjectInteractorTest {
val testObserver: TestObserver<String> = interactor.getProjectReadme(testProject).test()
testObserver.awaitTerminalEvent()
verify(repo, times(1)).getBlobFile(projectId, "README.md", branchName)
verify(repo, times(1)).getProjectFile(projectId, "README.md", branchName)
verifyZeroInteractions(base64)
verifyZeroInteractions(mdConverter)
testObserver
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment