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