Skip to content

Commit

Permalink
fix: convert GitHub issue and PR links to #number (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellbanks authored Feb 20, 2023
1 parent 6c1cce0 commit 8eae66e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/detection/github/GitHubExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object GitHubExtensions {
.replace(Regex("""\*+([^*]+)\*+"""), "$1")
.replace("`", "")
.replace(Regex("\\[([^]]+)]\\([^)]+\\)"), "$1")
.replace(Regex("https?://github.com/\\w+/\\w+/(pull|issues)/(\\d+)")) { "#${it.groupValues[2]}" }
}
return buildString {
lines?.forEachIndexed { index, line ->
Expand Down
40 changes: 40 additions & 0 deletions src/test/kotlin/GitHubTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,45 @@ class GitHubTests : FunSpec({
}
getFormattedReleaseNotes(ghRelease) shouldBe null
}

test("pull request links are converted to their pull request number") {
val ghRelease: GHRelease = mockk {
every { body } returns "- New feature in https://github.com/user/repository/pull/1234"
}
getFormattedReleaseNotes(ghRelease) shouldBe "- New feature in #1234"
}

test("issue links are converted to their issue number") {
val ghRelease: GHRelease = mockk {
every { body } returns "- Issue reported in https://github.com/user/repository/issues/4321"
}
getFormattedReleaseNotes(ghRelease) shouldBe "- Issue reported in #4321"
}

test("multiple pull request or issue links in a string are converted to their pull request numbers") {
val ghRelease: GHRelease = mockk {
every { body } returns buildString {
append("- New features in ")
append("https://github.com/user/repository/issues/1234")
append(" and ")
append("https://github.com/user/repository/pull/4321")
}
}
getFormattedReleaseNotes(ghRelease) shouldBe "- New features in #1234 and #4321"
}

test("pull requests without a number don't get converted") {
val ghRelease: GHRelease = mockk {
every { body } returns "- https://github.com/user/repository/pull"
}
getFormattedReleaseNotes(ghRelease) shouldBe "- https://github.com/user/repository/pull"
}

test("issues without a number don't get converted") {
val ghRelease: GHRelease = mockk {
every { body } returns "- https://github.com/user/repository/issues"
}
getFormattedReleaseNotes(ghRelease) shouldBe "- https://github.com/user/repository/issues"
}
}
})

0 comments on commit 8eae66e

Please sign in to comment.