Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit a530ce9

Browse files
authored
add API for URL fragments (#2457)
1 parent 61fdc28 commit a530ce9

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Classes/Issues/Comments/IssueCommentSectionController.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ final class IssueCommentSectionController: ListBindingSectionController<IssueCom
8585
// MARK: Private API
8686

8787
func shareAction(sender: UIView) -> UIAlertAction? {
88-
let attribute = object?.asReviewComment == true ? "#discussion_r" : "#issuecomment-"
88+
let attribute = object?.asReviewComment == true ? "discussion_r" : "issuecomment-"
8989
guard let number = object?.number,
90-
let url = URLBuilder.github().add(
91-
paths: [model.owner, model.repo, "issues", model.number, attribute, number]
92-
).url
90+
let url = URLBuilder.github()
91+
.add(paths: [model.owner, model.repo, "issues", model.number])
92+
.set(fragment: "\(attribute)\(number)")
93+
.url
9394
else { return nil }
9495
weak var weakSelf = self
9596

Classes/Utility/URLBuilder.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ final class URLBuilder {
4646
return self
4747
}
4848

49+
@discardableResult
50+
func set(fragment: String) -> URLBuilder {
51+
components.fragment = fragment
52+
return self
53+
}
54+
4955
var url: URL? {
5056
var components = self.components
5157
if !pathComponents.isEmpty {

FreetimeTests/URLBuilderTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ class URLBuilderTests: XCTestCase {
6767
)
6868
}
6969

70+
func test_withAnchorSymbol() {
71+
let builder = URLBuilder.github()
72+
.add(paths: ["githawkapp", "githawk", "issues", "42"])
73+
.set(fragment: "issuecomment-1234")
74+
XCTAssertEqual(
75+
builder.url!.absoluteString,
76+
"https://github.com/githawkapp/githawk/issues/42#issuecomment-1234"
77+
)
78+
}
79+
7080
}

0 commit comments

Comments
 (0)