Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] Extract code block into function #243

Merged
merged 4 commits into from
Jan 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,7 @@ class PullRequestStatsRepoImpl(
val initialResponseTime = mutableMapOf<UserId, Duration>()

prReviewers.forEach { reviewer ->
val firstReviewedEvent: ReviewedEvent = prTimelineEvents.filterTo(ReviewedEvent::class)
// Finds first event (TODO: Check if the result is sorted, if not sort it)
.find { reviewedEvent ->
reviewedEvent.user == reviewer &&
listOf(
ReviewState.APPROVED,
ReviewState.CHANGE_REQUESTED,
ReviewState.COMMENTED
).any { it == reviewedEvent.state }
} ?: return@forEach
val firstReviewedEvent: ReviewedEvent = firstReviewedEvent(prTimelineEvents, reviewer) ?: return@forEach

val prReviewerUserId = reviewer.login
val prReadyForReviewOn = evaluatePrReadyForReviewByUser(reviewer, prAvailableForReviewOn, prTimelineEvents)
Expand Down Expand Up @@ -359,4 +350,21 @@ class PullRequestStatsRepoImpl(

return prCreatedOn
}

/**
* Finds the first reviewed event by the [reviewer] to know when user has finished reviewing the PR.
*/
private fun firstReviewedEvent(
prTimelineEvents: List<TimelineEvent>,
reviewer: User
) = prTimelineEvents.filterTo(ReviewedEvent::class)
// Finds first event (TODO: Check if the result is sorted, if not sort it)
.find { reviewedEvent ->
reviewedEvent.user == reviewer &&
listOf(
ReviewState.APPROVED,
ReviewState.CHANGE_REQUESTED,
ReviewState.COMMENTED
).any { it == reviewedEvent.state }
}
}