summaryrefslogtreecommitdiff
path: root/Hutch/Extensions/SRHTWebURL.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-03-17 23:19:43 -0500
committerChristian Cleberg <[email protected]>2026-03-17 23:19:43 -0500
commit32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5 (patch)
treeee36d421d704e508d5617d803b4c8cbdb4804fe1 /Hutch/Extensions/SRHTWebURL.swift
parent8f2057c53e9009c2529c9c4849c914666c0e4b40 (diff)
downloadhutch-32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5.tar.gz
hutch-32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5.tar.bz2
hutch-32ad6cab8d58d99ebd8a28e8fa6e6f4e587cb1e5.zip
v1.0
Diffstat (limited to 'Hutch/Extensions/SRHTWebURL.swift')
-rw-r--r--Hutch/Extensions/SRHTWebURL.swift50
1 files changed, 49 insertions, 1 deletions
diff --git a/Hutch/Extensions/SRHTWebURL.swift b/Hutch/Extensions/SRHTWebURL.swift
index 53556de..f63352b 100644
--- a/Hutch/Extensions/SRHTWebURL.swift
+++ b/Hutch/Extensions/SRHTWebURL.swift
@@ -9,6 +9,41 @@ enum SRHTWebURL {
)
}
+ static func commit(repository: RepositorySummary, commitId: String) -> URL? {
+ userScopedURL(
+ host: "\(repository.service.rawValue).sr.ht",
+ ownerCanonicalName: repository.owner.canonicalName,
+ pathComponents: [repository.name, commitPathComponent(for: repository.service), commitId]
+ )
+ }
+
+ static func file(repository: RepositorySummary, revspec: String, path: String) -> URL? {
+ switch repository.service {
+ case .git:
+ return userScopedURL(
+ host: "git.sr.ht",
+ ownerCanonicalName: repository.owner.canonicalName,
+ pathComponents: [repository.name, "tree", revspec, "item"] + pathComponents(from: path)
+ )
+ case .hg:
+ var components = URLComponents()
+ components.scheme = "https"
+ components.host = "hg.sr.ht"
+
+ let ownerUsername = username(from: repository.owner.canonicalName)
+ let encodedRepository = repository.name.addingPercentEncoding(withAllowedCharacters: pathComponentCharacterSet) ?? repository.name
+ let encodedPath = path.split(separator: "/").map {
+ String($0).addingPercentEncoding(withAllowedCharacters: pathComponentCharacterSet) ?? String($0)
+ }.joined(separator: "/")
+
+ components.percentEncodedPath = "/~\(ownerUsername)/\(encodedRepository)/browse/\(encodedPath)"
+ components.queryItems = [URLQueryItem(name: "rev", value: revspec)]
+ return components.url
+ default:
+ return nil
+ }
+ }
+
static func build(jobId: Int, ownerCanonicalName: String) -> URL? {
userScopedURL(
host: "builds.sr.ht",
@@ -35,7 +70,7 @@ enum SRHTWebURL {
static func profile(canonicalName: String) -> URL? {
userScopedURL(
- host: "meta.sr.ht",
+ host: "sr.ht",
ownerCanonicalName: canonicalName,
pathComponents: []
)
@@ -76,9 +111,22 @@ enum SRHTWebURL {
return canonicalName
}
+ private static func commitPathComponent(for service: SRHTService) -> String {
+ switch service {
+ case .hg:
+ return "rev"
+ default:
+ return "commit"
+ }
+ }
+
private static let pathComponentCharacterSet: CharacterSet = {
var characterSet = CharacterSet.urlPathAllowed
characterSet.remove(charactersIn: "/")
return characterSet
}()
+
+ private static func pathComponents(from path: String) -> [String] {
+ path.split(separator: "/").map(String.init)
+ }
}