Skip to content

Commit

Permalink
Add a failing test for extracting the resolving issue from a pull req…
Browse files Browse the repository at this point in the history
…uest body
  • Loading branch information
AvdLee committed Jan 10, 2020
1 parent 6309548 commit 550cd89
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Sources/ChangelogProducerCore/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ extension String {
func pullRequestIDs() -> [Int] {
return []
}

/// Extracts the resolved issue from a Pull Request body.
func resolvingIssue() -> Int? {
return nil
}
}
47 changes: 40 additions & 7 deletions Tests/ChangelogProducerTests/ChangelogProducerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
final class ChangelogProducerTests: XCTestCase {

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

/// It should extract pull request from merge commits.
func testPullRequestIDsFromMergeCommits() throws {
let gitLogOutput = """
* Merge pull request #65 from BalestraPatrick/profiles-devices-endpoints via Antoine van der Lee
* Merge pull request #62 from hexagons/issue/42 via Antoine van der Lee
"""
XCTAssertEqual(gitLogOutput.pullRequestIDs(), [62, 65])
func testPullRequestIDsFromMergeCommits() {
let gitLogOutput = """
* Merge pull request #65 from BalestraPatrick/profiles-devices-endpoints via Antoine van der Lee
* Merge pull request #62 from hexagons/issue/42 via Antoine van der Lee
"""
XCTAssertEqual(gitLogOutput.pullRequestIDs(), [62, 65])
}

/// It should extract the fixed issue from the Pull Request body.
func testResolvingReferencedIssue() {
// See this code as an example: https://github.com/fastlane/issue-bot/blob/457348717d99e5ffde34ca1619e7253ed51ec172/bot.rb#L456

let issueClosingKeywords = [
"close",
"Closes",
"closed",
"fix",
"fixes",
"Fixed",
"resolve",
"Resolves",
"resolved"
]

issueClosingKeywords.forEach { (closingKeyword) in
let description = examplePullRequestDescriptionUsing(closingKeyword: closingKeyword)
XCTAssertEqual(description.resolvingIssue(), 4343)
}
}

static var allTests = [
("testPullRequestIDsFromSquashCommits", testPullRequestIDsFromSquashCommits),
("testPullRequestIDsFromMergeCommits", testPullRequestIDsFromMergeCommits)
]
}

extension ChangelogProducerTests {
func examplePullRequestDescriptionUsing(closingKeyword: String) -> String {
return """
This PR does a lot of awesome stuff.
\(closingKeyword) #4343
"""

}
}

0 comments on commit 550cd89

Please sign in to comment.