Skip to content

Commit

Permalink
Update plugin com.diffplug.spotless to v6.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and nicokosi committed Oct 5, 2023
1 parent 5d205a9 commit c923e50
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id("se.patrikerdes.use-latest-versions") version "0.2.18"
id("com.github.ben-manes.versions") version "0.48.0"
id("com.adarshr.test-logger") version "3.2.0"
id("com.diffplug.spotless") version "6.19.0"
id("com.diffplug.spotless") version "6.22.0"
application
}

Expand Down
22 changes: 13 additions & 9 deletions src/main/kotlin/pullpitok/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ fun main(args: Array<String>) {
.forEach { displayEvents(it, token) }
}

internal fun invalidArguments(args: Array<String>): Boolean =
args.size !in (1..2) || args[0] in setOf("", "-h", "--help")
internal fun invalidArguments(args: Array<String>): Boolean = args.size !in (1..2) || args[0] in setOf("", "-h", "--help")

private fun displayEvents(repo: String, token: String?) {
private fun displayEvents(
repo: String,
token: String?,
) {
val allEvents = mutableListOf<Event>()
for (pageNumber in 1..10) {
val events = EventClient("https", "api.github.com").githubEvents(repo, token, page = pageNumber)
Expand All @@ -44,9 +46,10 @@ private fun displayEvents(repo: String, token: String?) {
)
}

private fun perAuthor(events: List<Event>): Map<String, List<Event>> = events
.filter { it.type in Type.values().map(Type::name) }
.groupBy { it.actor.login }
private fun perAuthor(events: List<Event>): Map<String, List<Event>> =
events
.filter { it.type in Type.values().map(Type::name) }
.groupBy { it.actor.login }

internal fun counters(
eventsPerAuthor: Map<String, List<Event>>,
Expand All @@ -56,9 +59,10 @@ internal fun counters(
var counters = ""
for (events in eventsPerAuthor.entries) {
val author = events.key
val count = events.value
.filter(predicate)
.count()
val count =
events.value
.filter(predicate)
.count()
if (count > 0) {
counters += "\n\t\t$author: $count"
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/pullpitok/github/Event.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package pullpitok.github

data class Actor(val login: String)

data class Payload(val action: String)

data class Event(val id: String, val type: String, val actor: Actor, val payload: Payload)

@Suppress("ktlint:enum-entry-name-case")
@Suppress("ktlint:standard:enum-entry-name-case")
enum class Action {
created,
closed,
opened,
}

enum class Type {
PullRequestEvent,
PullRequestReviewCommentEvent,
Expand Down
16 changes: 10 additions & 6 deletions src/main/kotlin/pullpitok/github/EventClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ import java.net.http.HttpResponse.BodyHandlers
import java.time.Duration

class EventClient(private val protocol: String, private val hostname: String) {

private val client = HttpClient.newBuilder().build()

fun githubEvents(repo: String, token: String?, page: Int): List<Event> {
fun githubEvents(
repo: String,
token: String?,
page: Int,
): List<Event> {
val url = "$protocol://$hostname/repos/$repo/events?page=$page"
val request = HttpRequest.newBuilder()
.timeout(Duration.ofSeconds(30))
.header("Content-Type", "application/json")
.uri(URI.create(url))
val request =
HttpRequest.newBuilder()
.timeout(Duration.ofSeconds(30))
.header("Content-Type", "application/json")
.uri(URI.create(url))
if (token != null) {
request.header("Authorization", "token $token")
}
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/pullpitok/AppTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue

class AppTest {

@Test
fun `no counters`() {
assertEquals(
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/pullpitok/github/EventClientIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.junit.Test
import kotlin.test.assertEquals

class EventClientIT {

@JvmField
@Rule
var wiremock = WireMockRule()
Expand All @@ -31,8 +30,9 @@ class EventClientIT {
),
),
)
val events = EventClient("http", "localhost:${wiremock.port()}")
.githubEvents(repo, "1234", page)
val events =
EventClient("http", "localhost:${wiremock.port()}")
.githubEvents(repo, "1234", page)
assertEquals(
events
.filter { it.type == Type.PullRequestEvent.name }
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/pullpitok/github/EventClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.junit.Test
import kotlin.test.assertEquals

class EventClientTest {

private val eventClient = EventClient("http", "anyHost")

@Test
Expand Down

0 comments on commit c923e50

Please sign in to comment.