Commit 5c7aeb4f authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Fixed bug associated with getting not full Issue/MergeRequest notes.

parent 9a7a7292
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
data class Discussion(
@SerializedName("id") val id: String,
@SerializedName("individual_note") val isIndividualNote: Boolean,
@SerializedName("notes") val notes: List<Note>
)
\ No newline at end of file
...@@ -6,7 +6,14 @@ import io.reactivex.functions.BiFunction ...@@ -6,7 +6,14 @@ import io.reactivex.functions.BiFunction
import ru.terrakok.gitlabclient.entity.OrderBy import ru.terrakok.gitlabclient.entity.OrderBy
import ru.terrakok.gitlabclient.entity.Project import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.Sort import ru.terrakok.gitlabclient.entity.Sort
import ru.terrakok.gitlabclient.entity.app.target.* import ru.terrakok.gitlabclient.entity.app.target.AppTarget
import ru.terrakok.gitlabclient.entity.app.target.TargetBadge
import ru.terrakok.gitlabclient.entity.app.target.TargetBadgeIcon
import ru.terrakok.gitlabclient.entity.app.target.TargetBadgeStatus
import ru.terrakok.gitlabclient.entity.app.target.TargetHeader
import ru.terrakok.gitlabclient.entity.app.target.TargetHeaderIcon
import ru.terrakok.gitlabclient.entity.app.target.TargetHeaderTitle
import ru.terrakok.gitlabclient.entity.app.target.TargetInternal
import ru.terrakok.gitlabclient.entity.event.EventAction import ru.terrakok.gitlabclient.entity.event.EventAction
import ru.terrakok.gitlabclient.entity.issue.Issue import ru.terrakok.gitlabclient.entity.issue.Issue
import ru.terrakok.gitlabclient.entity.issue.IssueScope import ru.terrakok.gitlabclient.entity.issue.IssueScope
...@@ -21,32 +28,44 @@ import javax.inject.Inject ...@@ -21,32 +28,44 @@ import javax.inject.Inject
* @author Konstantin Tskhovrebov (aka terrakok) on 14.06.17. * @author Konstantin Tskhovrebov (aka terrakok) on 14.06.17.
*/ */
class IssueRepository @Inject constructor( class IssueRepository @Inject constructor(
private val api: GitlabApi, private val api: GitlabApi,
private val schedulers: SchedulersProvider, private val schedulers: SchedulersProvider,
@DefaultPageSize private val defaultPageSizeWrapper: PrimitiveWrapper<Int> @DefaultPageSize private val defaultPageSizeWrapper: PrimitiveWrapper<Int>
) { ) {
private val defaultPageSize = defaultPageSizeWrapper.value private val defaultPageSize = defaultPageSizeWrapper.value
fun getMyIssues( fun getMyIssues(
scope: IssueScope? = null, scope: IssueScope? = null,
state: IssueState? = null, state: IssueState? = null,
labels: String? = null, labels: String? = null,
milestone: String? = null, milestone: String? = null,
iids: Array<Long>? = null, iids: Array<Long>? = null,
orderBy: OrderBy? = null, orderBy: OrderBy? = null,
sort: Sort? = null, sort: Sort? = null,
search: String? = null, search: String? = null,
page: Int, page: Int,
pageSize: Int = defaultPageSize pageSize: Int = defaultPageSize
) = api ) = api
.getMyIssues(scope, state, labels, milestone, iids, orderBy, sort, search, page, pageSize) .getMyIssues(
scope,
state,
labels,
milestone,
iids,
orderBy,
sort,
search,
page,
pageSize
)
.flatMap { issues -> .flatMap { issues ->
Single.zip( Single.zip(
Single.just(issues), Single.just(issues),
getDistinctProjects(issues), getDistinctProjects(issues),
BiFunction<List<Issue>, Map<Long, Project>, List<TargetHeader>> { sourceIssues, projects -> BiFunction<List<Issue>, Map<Long, Project>, List<TargetHeader>> { sourceIssues, projects ->
sourceIssues.map { getTargetHeader(it, projects[it.projectId]!!) } sourceIssues.map { getTargetHeader(it, projects[it.projectId]!!) }
} }
) )
} }
.subscribeOn(schedulers.io()) .subscribeOn(schedulers.io())
...@@ -61,10 +80,14 @@ class IssueRepository @Inject constructor( ...@@ -61,10 +80,14 @@ class IssueRepository @Inject constructor(
private fun getTargetHeader(issue: Issue, project: Project): TargetHeader { private fun getTargetHeader(issue: Issue, project: Project): TargetHeader {
val badges = mutableListOf<TargetBadge>() val badges = mutableListOf<TargetBadge>()
badges.add(TargetBadge.Status(when(issue.state) { badges.add(
IssueState.OPENED -> TargetBadgeStatus.OPENED TargetBadge.Status(
IssueState.CLOSED -> TargetBadgeStatus.CLOSED when (issue.state) {
})) IssueState.OPENED -> TargetBadgeStatus.OPENED
IssueState.CLOSED -> TargetBadgeStatus.CLOSED
}
)
)
badges.add(TargetBadge.Text(project.name, AppTarget.PROJECT, project.id)) badges.add(TargetBadge.Text(project.name, AppTarget.PROJECT, project.id))
badges.add(TargetBadge.Text(issue.author.username, AppTarget.USER, issue.author.id)) badges.add(TargetBadge.Text(issue.author.username, AppTarget.USER, issue.author.id))
badges.add(TargetBadge.Icon(TargetBadgeIcon.COMMENTS, issue.userNotesCount)) badges.add(TargetBadge.Icon(TargetBadgeIcon.COMMENTS, issue.userNotesCount))
...@@ -73,38 +96,39 @@ class IssueRepository @Inject constructor( ...@@ -73,38 +96,39 @@ class IssueRepository @Inject constructor(
issue.labels.forEach { label -> badges.add(TargetBadge.Text(label)) } issue.labels.forEach { label -> badges.add(TargetBadge.Text(label)) }
return TargetHeader( return TargetHeader(
issue.author, issue.author,
TargetHeaderIcon.NONE, TargetHeaderIcon.NONE,
TargetHeaderTitle.Event( TargetHeaderTitle.Event(
issue.author.name, issue.author.name,
EventAction.CREATED, EventAction.CREATED,
"${AppTarget.ISSUE} #${issue.iid}", "${AppTarget.ISSUE} #${issue.iid}",
project.name project.name
), ),
issue.title ?: "", issue.title ?: "",
issue.createdAt, issue.createdAt,
AppTarget.ISSUE, AppTarget.ISSUE,
issue.id, issue.id,
TargetInternal(issue.projectId, issue.iid), TargetInternal(issue.projectId, issue.iid),
badges badges
) )
} }
fun getIssue( fun getIssue(
projectId: Long, projectId: Long,
issueId: Long issueId: Long
) = api ) = api
.getIssue(projectId, issueId) .getIssue(projectId, issueId)
.subscribeOn(schedulers.io()) .subscribeOn(schedulers.io())
.observeOn(schedulers.ui()) .observeOn(schedulers.ui())
fun getIssueNotes( fun getIssueNotes(
projectId: Long, projectId: Long,
issueId: Long, issueId: Long
orderBy: OrderBy? = null,
sort: Sort? = Sort.ASC
) = api ) = api
.getIssueNotes(projectId, issueId, orderBy, sort) .getIssueDiscussions(projectId, issueId)
.flattenAsObservable { it }
.concatMap { discussion -> Observable.fromIterable(discussion.notes) }
.toList()
.subscribeOn(schedulers.io()) .subscribeOn(schedulers.io())
.observeOn(schedulers.ui()) .observeOn(schedulers.ui())
} }
\ No newline at end of file
...@@ -7,7 +7,14 @@ import org.threeten.bp.LocalDateTime ...@@ -7,7 +7,14 @@ import org.threeten.bp.LocalDateTime
import ru.terrakok.gitlabclient.entity.OrderBy import ru.terrakok.gitlabclient.entity.OrderBy
import ru.terrakok.gitlabclient.entity.Project import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.Sort import ru.terrakok.gitlabclient.entity.Sort
import ru.terrakok.gitlabclient.entity.app.target.* import ru.terrakok.gitlabclient.entity.app.target.AppTarget
import ru.terrakok.gitlabclient.entity.app.target.TargetBadge
import ru.terrakok.gitlabclient.entity.app.target.TargetBadgeIcon
import ru.terrakok.gitlabclient.entity.app.target.TargetBadgeStatus
import ru.terrakok.gitlabclient.entity.app.target.TargetHeader
import ru.terrakok.gitlabclient.entity.app.target.TargetHeaderIcon
import ru.terrakok.gitlabclient.entity.app.target.TargetHeaderTitle
import ru.terrakok.gitlabclient.entity.app.target.TargetInternal
import ru.terrakok.gitlabclient.entity.event.EventAction import ru.terrakok.gitlabclient.entity.event.EventAction
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequest import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequest
import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestScope import ru.terrakok.gitlabclient.entity.mergerequest.MergeRequestScope
...@@ -20,39 +27,40 @@ import ru.terrakok.gitlabclient.toothpick.qualifier.DefaultPageSize ...@@ -20,39 +27,40 @@ import ru.terrakok.gitlabclient.toothpick.qualifier.DefaultPageSize
import javax.inject.Inject import javax.inject.Inject
class MergeRequestRepository @Inject constructor( class MergeRequestRepository @Inject constructor(
private val api: GitlabApi, private val api: GitlabApi,
private val schedulers: SchedulersProvider, private val schedulers: SchedulersProvider,
@DefaultPageSize private val defaultPageSizeWrapper: PrimitiveWrapper<Int> @DefaultPageSize private val defaultPageSizeWrapper: PrimitiveWrapper<Int>
) { ) {
private val defaultPageSize = defaultPageSizeWrapper.value private val defaultPageSize = defaultPageSizeWrapper.value
fun getMergeRequests( fun getMergeRequests(
state: MergeRequestState? = null, state: MergeRequestState? = null,
milestone: String? = null, milestone: String? = null,
viewType: MergeRequestViewType? = null, viewType: MergeRequestViewType? = null,
labels: String? = null, labels: String? = null,
createdBefore: LocalDateTime? = null, createdBefore: LocalDateTime? = null,
createdAfter: LocalDateTime? = null, createdAfter: LocalDateTime? = null,
scope: MergeRequestScope? = null, scope: MergeRequestScope? = null,
authorId: Int? = null, authorId: Int? = null,
assigneeId: Int? = null, assigneeId: Int? = null,
meReactionEmoji: String? = null, meReactionEmoji: String? = null,
orderBy: OrderBy? = null, orderBy: OrderBy? = null,
sort: Sort? = null, sort: Sort? = null,
page: Int, page: Int,
pageSize: Int = defaultPageSize pageSize: Int = defaultPageSize
) = api ) = api
.getMergeRequests( .getMergeRequests(
state, milestone, viewType, labels, createdBefore, createdAfter, scope, state, milestone, viewType, labels, createdBefore, createdAfter, scope,
authorId, assigneeId, meReactionEmoji, orderBy, sort, page, pageSize authorId, assigneeId, meReactionEmoji, orderBy, sort, page, pageSize
) )
.flatMap { mrs -> .flatMap { mrs ->
Single.zip( Single.zip(
Single.just(mrs), Single.just(mrs),
getDistinctProjects(mrs), getDistinctProjects(mrs),
BiFunction<List<MergeRequest>, Map<Long, Project>, List<TargetHeader>> { sourceMrs, projects -> BiFunction<List<MergeRequest>, Map<Long, Project>, List<TargetHeader>> { sourceMrs, projects ->
sourceMrs.map { getTargetHeader(it, projects[it.projectId]!!) } sourceMrs.map { getTargetHeader(it, projects[it.projectId]!!) }
} }
) )
} }
.subscribeOn(schedulers.io()) .subscribeOn(schedulers.io())
...@@ -67,11 +75,15 @@ class MergeRequestRepository @Inject constructor( ...@@ -67,11 +75,15 @@ class MergeRequestRepository @Inject constructor(
private fun getTargetHeader(mr: MergeRequest, project: Project): TargetHeader { private fun getTargetHeader(mr: MergeRequest, project: Project): TargetHeader {
val badges = mutableListOf<TargetBadge>() val badges = mutableListOf<TargetBadge>()
badges.add(TargetBadge.Status(when(mr.state) { badges.add(
MergeRequestState.OPENED -> TargetBadgeStatus.OPENED TargetBadge.Status(
MergeRequestState.CLOSED -> TargetBadgeStatus.CLOSED when (mr.state) {
MergeRequestState.MERGED -> TargetBadgeStatus.MERGED MergeRequestState.OPENED -> TargetBadgeStatus.OPENED
})) MergeRequestState.CLOSED -> TargetBadgeStatus.CLOSED
MergeRequestState.MERGED -> TargetBadgeStatus.MERGED
}
)
)
badges.add(TargetBadge.Text(project.name, AppTarget.PROJECT, project.id)) badges.add(TargetBadge.Text(project.name, AppTarget.PROJECT, project.id))
badges.add(TargetBadge.Text(mr.author.username, AppTarget.USER, mr.author.id)) badges.add(TargetBadge.Text(mr.author.username, AppTarget.USER, mr.author.id))
badges.add(TargetBadge.Icon(TargetBadgeIcon.COMMENTS, mr.userNotesCount)) badges.add(TargetBadge.Icon(TargetBadgeIcon.COMMENTS, mr.userNotesCount))
...@@ -80,38 +92,39 @@ class MergeRequestRepository @Inject constructor( ...@@ -80,38 +92,39 @@ class MergeRequestRepository @Inject constructor(
mr.labels.forEach { label -> badges.add(TargetBadge.Text(label)) } mr.labels.forEach { label -> badges.add(TargetBadge.Text(label)) }
return TargetHeader( return TargetHeader(
mr.author, mr.author,
TargetHeaderIcon.NONE, TargetHeaderIcon.NONE,
TargetHeaderTitle.Event( TargetHeaderTitle.Event(
mr.author.name, mr.author.name,
EventAction.CREATED, EventAction.CREATED,
"${AppTarget.MERGE_REQUEST} !${mr.iid}", "${AppTarget.MERGE_REQUEST} !${mr.iid}",
project.name project.name
), ),
mr.title ?: "", mr.title ?: "",
mr.createdAt, mr.createdAt,
AppTarget.MERGE_REQUEST, AppTarget.MERGE_REQUEST,
mr.id, mr.id,
TargetInternal(mr.projectId, mr.iid), TargetInternal(mr.projectId, mr.iid),
badges badges
) )
} }
fun getMergeRequest( fun getMergeRequest(
projectId: Long, projectId: Long,
mergeRequestId: Long mergeRequestId: Long
) = api ) = api
.getMergeRequest(projectId, mergeRequestId) .getMergeRequest(projectId, mergeRequestId)
.subscribeOn(schedulers.io()) .subscribeOn(schedulers.io())
.observeOn(schedulers.ui()) .observeOn(schedulers.ui())
fun getMergeRequestNotes( fun getMergeRequestNotes(
projectId: Long, projectId: Long,
mergeRequestId: Long, mergeRequestId: Long
orderBy: OrderBy? = null,
sort: Sort? = Sort.ASC
) = api ) = api
.getMergeRequestNotes(projectId, mergeRequestId, orderBy, sort) .getMergeRequestDiscussions(projectId, mergeRequestId)
.flattenAsObservable { it }
.concatMap { discussion -> Observable.fromIterable(discussion.notes) }
.toList()
.subscribeOn(schedulers.io()) .subscribeOn(schedulers.io())
.observeOn(schedulers.ui()) .observeOn(schedulers.ui())
} }
\ No newline at end of file
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