-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add commits API * Add reporting led time logic * Add reporting ledd time logic * dd reporting of the message
- Loading branch information
Showing
12 changed files
with
503 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
plugins/src/main/java/com/jraska/github/client/release/Release.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
package com.jraska.github.client.release | ||
|
||
import okhttp3.HttpUrl | ||
import java.time.Instant | ||
|
||
class Release( | ||
val releaseName: String, | ||
val releaseUrl: HttpUrl | ||
val releaseUrl: HttpUrl, | ||
val timestamp: Instant | ||
) | ||
|
||
class PullRequest( | ||
val number: Int, | ||
val title: String | ||
) | ||
|
||
class Commit( | ||
val sha: String, | ||
val time: Instant, | ||
val author: String, | ||
val message: String, | ||
val prNumber: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
plugins/src/main/java/com/jraska/github/client/release/ReleaseMarksPRs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
plugins/src/main/java/com/jraska/github/client/release/data/LeadTimeReporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.jraska.github.client.release.data | ||
|
||
import com.jraska.analytics.AnalyticsEvent | ||
import com.jraska.analytics.AnalyticsReporter | ||
import com.jraska.github.client.release.Commit | ||
import com.jraska.github.client.release.GitHubApi | ||
import com.jraska.github.client.release.PullRequest | ||
import com.jraska.github.client.release.Release | ||
import java.time.Duration | ||
|
||
class LeadTimeReporter( | ||
private val api: GitHubApi, | ||
private val release: Release, | ||
private val reporter: AnalyticsReporter | ||
) { | ||
fun reportLeadTime(pulls: List<PullRequest>) { | ||
val events = pulls.flatMap { api.prCommits(it.number) } | ||
.map { toEvent(it) } | ||
|
||
reporter.report(*events.toTypedArray()) | ||
} | ||
|
||
private fun toEvent(commit: Commit): AnalyticsEvent { | ||
return AnalyticsEvent( | ||
"Commit Released", | ||
mapOf( | ||
"leadTimeSec" to Duration.between(commit.time, release.timestamp).seconds, | ||
"gitCommit" to commit.sha, | ||
"author" to commit.author, | ||
"prNumber" to commit.prNumber, | ||
"releaseName" to release.releaseName, | ||
"message" to commit.message | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
plugins/src/test/kotlin/com/jraska/github/client/release/data/LeadTimeReporterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.jraska.github.client.release.data | ||
|
||
import com.jraska.analytics.AnalyticsEvent | ||
import com.jraska.analytics.AnalyticsReporter | ||
import com.jraska.github.client.release.Environment | ||
import com.jraska.github.client.release.PullRequest | ||
import com.jraska.github.client.release.Release | ||
import com.jraska.github.client.release.enqueue | ||
import okhttp3.HttpUrl.Companion.toHttpUrl | ||
import okhttp3.mockwebserver.MockWebServer | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.time.Instant | ||
|
||
class LeadTimeReporterTest { | ||
private lateinit var leadTimeReporter: LeadTimeReporter | ||
lateinit var analyticsReporter: RecordingAnalyticsReporter | ||
|
||
@get:Rule | ||
val mockWebServer = MockWebServer() | ||
|
||
@Before | ||
fun setUp() { | ||
analyticsReporter = RecordingAnalyticsReporter() | ||
val environment = Environment("fakeToken", mockWebServer.url("/")) | ||
val gitHubApi = GitHubApiFactory.create(environment) | ||
|
||
val release = Release("testRelease", "https://jrasks.com".toHttpUrl(), Instant.parse("2021-04-10T12:00:00Z")) | ||
leadTimeReporter = LeadTimeReporter(gitHubApi, release, analyticsReporter) | ||
} | ||
|
||
@Test | ||
fun testReportsLeadTimeProperly() { | ||
mockWebServer.enqueue("response/commits_pr472.json") | ||
mockWebServer.enqueue("response/commits_pr460.json") | ||
|
||
leadTimeReporter.reportLeadTime(listOf(PullRequest(472, "First PR"), PullRequest(460, "Second PR"))) | ||
|
||
assertThat(mockWebServer.requestCount).isEqualTo(2) | ||
|
||
val reportedEvents = analyticsReporter.events() | ||
assertThat(reportedEvents).hasSize(3) | ||
|
||
assertThat(reportedEvents).allMatch { it.name == "Commit Released" } | ||
assertThat(reportedEvents).allMatch { it.properties["releaseName"] == "testRelease" } | ||
|
||
val first = reportedEvents.first() | ||
assertThat(first.properties["leadTimeSec"]).isEqualTo(13 * 3600 + 24 * 60 + 53L) | ||
assertThat(first.properties["author"]).isEqualTo("jraska") | ||
assertThat(first.properties["gitCommit"]).isEqualTo("859ffe735dc185336cbcad09e692d45dcf8c3361") | ||
assertThat(first.properties["message"]).isEqualTo("un composite build tests on CI") | ||
|
||
val second = reportedEvents[1] | ||
assertThat(second.properties["leadTimeSec"]).isEqualTo(13 * 3600 + 22 * 60 + 27L) | ||
assertThat(second.properties["author"]).isEqualTo("jraska") | ||
assertThat(second.properties["gitCommit"]).isEqualTo("65910afb3de84bb52283fbc8cb0c4be0988d4343") | ||
assertThat(second.properties["message"]).isEqualTo("Delete test which isn't needed anymore") | ||
|
||
val third = reportedEvents[2] | ||
assertThat(third.properties["leadTimeSec"]).isEqualTo(11 * 24 * 3600 + 23 * 3600 + 24 * 60 + 0L) | ||
assertThat(third.properties["author"]).isEqualTo("dependabot[bot]") | ||
assertThat(third.properties["gitCommit"]).isEqualTo("70e59ee5f812506651b10effbb00657d8e7ca4b2") | ||
} | ||
} | ||
|
||
class RecordingAnalyticsReporter : AnalyticsReporter { | ||
private val recorder: MutableList<AnalyticsEvent> = mutableListOf() | ||
|
||
fun events(): List<AnalyticsEvent> = recorder | ||
|
||
override fun report(vararg events: AnalyticsEvent) { | ||
recorder.addAll(events) | ||
} | ||
} |
Oops, something went wrong.