Skip to content

Commit 1f24ffa

Browse files
committed
Fix kotlin weekly issue number parsing.
1 parent 1ca6dbd commit 1f24ffa

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/KotlinWeeklyEntryMapper.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import java.time.ZonedDateTime
66
import java.time.format.DateTimeFormatter
77

88
fun KotlinWeeklyItem.toKotlinWeeklyEntry(): KotlinWeekly {
9+
val issueNumber = linkIssueNumberRegex.find(link)?.groupValues?.get(1)?.toInt()
10+
?: error("Issue number not found in link: $link")
911
return KotlinWeekly(
1012
id = guid,
1113
title = title,
1214
publishTime = ZonedDateTime
1315
.parse(pubDate, DateTimeFormatter.RFC_1123_DATE_TIME)
1416
.toInstant(),
1517
contentUrl = link,
16-
issueNumber = issueNumberRegex.find(title)?.groupValues?.get(1)?.toInt()
17-
?: error("Issue number not found in title: $title")
18+
issueNumber = issueNumber,
1819
)
1920
}
2021

21-
private val issueNumberRegex = Regex("#(\\d+)")
22+
private val linkIssueNumberRegex = Regex("kotlin-weekly-(\\d+)", RegexOption.IGNORE_CASE)

src/test/kotlin/io/github/reactivecircus/kstreamlined/backend/datafetcher/mapper/KotlinWeeklyEntryMapperTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class KotlinWeeklyEntryMapperTest {
2828
}
2929

3030
@Test
31-
fun `toKotlinWeeklyEntry() throws exception when issueNumber not found in title`() {
31+
fun `toKotlinWeeklyEntry() throws exception when issueNumber not found in link`() {
3232
assertFailsWith<IllegalStateException> {
3333
KotlinWeeklyItem(
3434
title = "Kotlin Weekly X",
35-
link = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
36-
guid = "https://mailchi.mp/kotlinweekly/kotlin-weekly-381",
35+
link = "https://mailchi.mp/kotlinweekly/random-newsletter",
36+
guid = "https://mailchi.mp/kotlinweekly/random-newsletter",
3737
pubDate = "Sun, 19 Nov 2023 09:13:00 +0000",
3838
).toKotlinWeeklyEntry()
3939
}

0 commit comments

Comments
 (0)