Skip to content

Commit 550cd89

Browse files
committed
Add a failing test for extracting the resolving issue from a pull request body
1 parent 6309548 commit 550cd89

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

Sources/ChangelogProducerCore/StringExtensions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ extension String {
1414
func pullRequestIDs() -> [Int] {
1515
return []
1616
}
17+
18+
/// Extracts the resolved issue from a Pull Request body.
19+
func resolvingIssue() -> Int? {
20+
return nil
21+
}
1722
}

Tests/ChangelogProducerTests/ChangelogProducerTests.swift

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import XCTest
44
final class ChangelogProducerTests: XCTestCase {
55

66
/// It should extract pull request IDs from squash merges.
7-
func testPullRequestIDsFromSquashCommits() throws {
7+
func testPullRequestIDsFromSquashCommits() {
88
let gitLogOutput = """
99
* Fix bucket deeplinking after adding content (#5130) via Antoine van der Lee
1010
* Fix CI for Coyote #trivial (#5114) via Antoine van der Lee
@@ -14,16 +14,49 @@ final class ChangelogProducerTests: XCTestCase {
1414
}
1515

1616
/// It should extract pull request from merge commits.
17-
func testPullRequestIDsFromMergeCommits() throws {
18-
let gitLogOutput = """
19-
* Merge pull request #65 from BalestraPatrick/profiles-devices-endpoints via Antoine van der Lee
20-
* Merge pull request #62 from hexagons/issue/42 via Antoine van der Lee
21-
"""
22-
XCTAssertEqual(gitLogOutput.pullRequestIDs(), [62, 65])
17+
func testPullRequestIDsFromMergeCommits() {
18+
let gitLogOutput = """
19+
* Merge pull request #65 from BalestraPatrick/profiles-devices-endpoints via Antoine van der Lee
20+
* Merge pull request #62 from hexagons/issue/42 via Antoine van der Lee
21+
"""
22+
XCTAssertEqual(gitLogOutput.pullRequestIDs(), [62, 65])
23+
}
24+
25+
/// It should extract the fixed issue from the Pull Request body.
26+
func testResolvingReferencedIssue() {
27+
// See this code as an example: https://github.com/fastlane/issue-bot/blob/457348717d99e5ffde34ca1619e7253ed51ec172/bot.rb#L456
28+
29+
let issueClosingKeywords = [
30+
"close",
31+
"Closes",
32+
"closed",
33+
"fix",
34+
"fixes",
35+
"Fixed",
36+
"resolve",
37+
"Resolves",
38+
"resolved"
39+
]
40+
41+
issueClosingKeywords.forEach { (closingKeyword) in
42+
let description = examplePullRequestDescriptionUsing(closingKeyword: closingKeyword)
43+
XCTAssertEqual(description.resolvingIssue(), 4343)
2344
}
45+
}
2446

2547
static var allTests = [
2648
("testPullRequestIDsFromSquashCommits", testPullRequestIDsFromSquashCommits),
2749
("testPullRequestIDsFromMergeCommits", testPullRequestIDsFromMergeCommits)
2850
]
2951
}
52+
53+
extension ChangelogProducerTests {
54+
func examplePullRequestDescriptionUsing(closingKeyword: String) -> String {
55+
return """
56+
This PR does a lot of awesome stuff.
57+
58+
\(closingKeyword) #4343
59+
"""
60+
61+
}
62+
}

0 commit comments

Comments
 (0)