Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fixes|Closes matching for issue link, too #21

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ dependencies {
testImplementation("io.projectreactor:reactor-test")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
testImplementation("org.skyscreamer:jsonassert")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
}
6 changes: 4 additions & 2 deletions src/main/kotlin/io/spring/github/event/PushEvent.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@ import io.spring.github.api.RepositoryRef

/**
* @author Rob Winch
* @author Artem Bilan
*/
class PushEvent(val ref : String, val repository : Repository, val pusher : Pusher, val commits : List<Commit> = listOf()) {
fun getFixCommits() : List<Commit> {
Expand Down Expand Up @@ -63,7 +64,8 @@ class PushEvent(val ref : String, val repository : Repository, val pusher : Push


data class Commit(val id : String, val message : String) {
val r = """.*?(Fixes|Closes):?\s+(gh\-|#)(?<id>\d+)(\r?\n)*""".toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.DOT_MATCHES_ALL))
val r = """.*?(Fixes|Closes):?\s+(gh-|#|(https://github.com/.*/.*/(issues|pull))/)(?<id>\d+)(\r?\n)*"""
.toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.DOT_MATCHES_ALL))

fun getFixIssueId() : Int? {
return r.find(message)?.groups?.get("id")?.value?.toInt()
Expand Down
16 changes: 15 additions & 1 deletion src/test/kotlin/io/spring/github/event/PushEventTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,10 @@ import org.junit.Test

/**
* @author Rob Winch
* @author Artem Bilan
*/
class PushEventTest {

@Test
fun getFixedIssueIdsWhenOnlyFixesThenFindValue() {
val e = pushEvent("Fixes: gh-123")
Expand Down Expand Up @@ -106,6 +108,18 @@ class PushEventTest {
assertThat(e.getFixCommits().map { c -> c.getFixIssueId() }).containsOnly(22261)
}

@Test
fun getFixedIssueIdWhenSubjectAndIssueLinkThenFindValues() {
val e = pushEvent("Subject\n\nFixes: https://github.com/some-org/some-project/issues/123")
assertThat(e.getFixCommits().map { c -> c.getFixIssueId() }).containsOnly(123)
}

@Test
fun getFixedIssueIdWhenSubjectAndPullRequestLinkThenFindValues() {
val e = pushEvent("Subject\n\nFixes: https://github.com/some-org/some-project/pull/123")
assertThat(e.getFixCommits().map { c -> c.getFixIssueId() }).containsOnly(123)
}

fun pushEvent(commitMessage : String) : PushEvent {
val commits = listOf(PushEvent.Commit("sha", commitMessage))
return PushEvent("main", PushEvent.Repository("spring-projects/spring-security"), PushEvent.Pusher("rwinch"), commits)
Expand Down