From a89601fa2cb473fedc520046f2b4d775fa70ab76 Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Mon, 1 Jan 2024 10:28:28 -0500 Subject: [PATCH 1/2] [REFACTOR] Extract code block into function --- .../repository/PullRequestStatsRepoImpl.kt | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt b/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt index 1e16986..5406e01 100644 --- a/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt +++ b/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt @@ -179,16 +179,7 @@ class PullRequestStatsRepoImpl( val initialResponseTime = mutableMapOf() 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) @@ -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, + 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 } + } } From 566ae0c499b411d2a921e6221edc8666d3a572bc Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Mon, 1 Jan 2024 10:30:20 -0500 Subject: [PATCH 2/2] [FIXED] Lint --- .../githubstats/repository/PullRequestStatsRepoImpl.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt b/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt index 5406e01..c30ecaa 100644 --- a/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt +++ b/src/main/kotlin/dev/hossain/githubstats/repository/PullRequestStatsRepoImpl.kt @@ -361,10 +361,10 @@ class PullRequestStatsRepoImpl( // 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 } + listOf( + ReviewState.APPROVED, + ReviewState.CHANGE_REQUESTED, + ReviewState.COMMENTED + ).any { it == reviewedEvent.state } } }