Skip to content

Commit 670350b

Browse files
authored
chore(shared-internal): add detekt linter (#1890)
Motivated by ability to detect redundant `suspend` modifier: https://detekt.dev/docs/rules/coroutines/#redundantsuspendmodifier, see https://github.com/typesafegithub/github-workflows-kt/pull/1889/files#r2030503149.
1 parent 396d61b commit 670350b

5 files changed

Lines changed: 14 additions & 3 deletions

File tree

shared-internal/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
buildsrc.convention.publishing
44

55
kotlin("plugin.serialization")
6+
id("io.gitlab.arturbosch.detekt")
67
}
78

89
group = rootProject.group

shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GitHubApp.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private val logger = logger { }
2828
* Returns an installation access token for the GitHub app, usable with API call to GitHub.
2929
* If `null` is returned, it means that the environment wasn't configured to generate the token.
3030
*/
31+
@Suppress("ReturnCount")
3132
suspend fun getInstallationAccessToken(): String? {
3233
if (cachedAccessToken?.isExpired() == false) return cachedAccessToken!!.token
3334
val jwtToken = generateJWTToken() ?: return null
@@ -44,6 +45,7 @@ suspend fun getInstallationAccessToken(): String? {
4445

4546
private var cachedAccessToken: Token? = null
4647

48+
@Suppress("ConstructorParameterNaming")
4749
@Serializable
4850
private data class Token(
4951
val token: String,
@@ -76,6 +78,7 @@ private val httpClient =
7678
}
7779
}
7880

81+
@Suppress("ReturnCount", "MagicNumber")
7982
private fun generateJWTToken(): String? {
8083
val key = loadRsaKey() ?: return null
8184
val appClientId = System.getenv("APP_CLIENT_ID") ?: return null
@@ -102,6 +105,8 @@ private fun loadRsaKey(): RSAPrivateKey? {
102105
return keyFactory.generatePrivate(keySpec) as RSAPrivateKey
103106
}
104107

108+
@Suppress("MagicNumber")
105109
private fun Instant.minusMinutes(minutes: Long): Instant = minusSeconds(minutes * 60)
106110

111+
@Suppress("MagicNumber")
107112
private fun Instant.plusMinutes(minutes: Long): Instant = plusSeconds(minutes * 60)

shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GithubApi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ private suspend fun fetchGithubRefs(
7979
}
8080
}
8181
ensure(response.status.isSuccess()) {
82-
"Unexpected response when fetching refs from $url. Status: ${response.status}, response: ${response.bodyAsText()}"
82+
"Unexpected response when fetching refs from $url. " +
83+
"Status: ${response.status}, response: ${response.bodyAsText()}"
8384
}
8485
response.body()
8586
}

shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GithubUtils.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ private val logger = logger { }
1414
fun getGithubAuthTokenOrNull(): String? =
1515
runBlocking {
1616
runCatching { getInstallationAccessToken() }
17-
.onFailure { logger.warn(it) { "Failed to get GitHub App Installation token, falling back to GITHUB_TOKEN." } }
18-
.getOrNull() ?: System.getenv("GITHUB_TOKEN")
17+
.onFailure {
18+
logger.warn(it) {
19+
"Failed to get GitHub App Installation token, falling back to GITHUB_TOKEN."
20+
}
21+
}.getOrNull() ?: System.getenv("GITHUB_TOKEN")
1922
}.also { if (it == null) logger.warn { ERROR_NO_CONFIGURATION } }
2023

2124
/**

shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/model/Version.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ data class Version(
1212
val minor: Int = versionIntParts.getOrNull(1) ?: 0
1313
val patch: Int = versionIntParts.getOrNull(2) ?: 0
1414

15+
@Suppress("ReturnCount")
1516
override fun compareTo(other: Version): Int {
1617
versionParts.forEachIndexed { i, part ->
1718
val otherPart = other.versionParts.getOrNull(i)

0 commit comments

Comments
 (0)