Skip to content

Commit ce3d861

Browse files
committed
attempt to fix #298, and add logging for these sync response paths
1 parent 6e83746 commit ce3d861

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

Sources/GitHubAPI/GitHub.Repo.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ extension GitHub.Repo:JSONObjectDecodable
139139
public
140140
init(json:JSON.ObjectDecoder<CodingKey>) throws
141141
{
142+
// Note: GitHub often returns explicit `null` values for fields that are missing.
143+
// This means we need to be careful when mapping optional fields, particularly through
144+
// the use `as:`.
142145
self.init(id: try json[.id].decode(),
143146
owner: try json[.owner].decode(),
144147
name: try json[.name].decode(),
@@ -152,10 +155,20 @@ extension GitHub.Repo:JSONObjectDecodable
152155
archived: try json[.archived].decode(),
153156
disabled: try json[.disabled].decode(),
154157
fork: try json[.fork].decode(),
155-
homepage: try json[.homepage]?.decode(as: String.self) { $0.isEmpty ? nil : $0 },
156-
about: try json[.about]?.decode(as: String.self) { $0.isEmpty ? nil : $0 },
158+
homepage: try json[.homepage]?.decode(),
159+
about: try json[.about]?.decode(),
157160
created: try json[.created].decode(),
158161
updated: try json[.updated].decode(),
159162
pushed: try json[.pushed].decode())
163+
164+
// String field normalization.
165+
if case true? = self.homepage?.isEmpty
166+
{
167+
self.homepage = nil
168+
}
169+
if case true? = self.about?.isEmpty
170+
{
171+
self.about = nil
172+
}
160173
}
161174
}

Sources/HTTP/HTTP.Resource.Content.Body.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ extension HTTP.Resource.Content.Body
1818
.binary(bytes[...])
1919
}
2020
}
21+
extension HTTP.Resource.Content.Body:CustomStringConvertible
22+
{
23+
@inlinable public
24+
var description:String
25+
{
26+
switch self
27+
{
28+
case .binary(let self): .init(decoding: self, as: Unicode.UTF8.self)
29+
case .buffer(let self): .init(decoding: self.readableBytesView, as: Unicode.UTF8.self)
30+
case .string(let self): self
31+
}
32+
}
33+
}
2134
extension HTTP.Resource.Content.Body
2235
{
2336
/// The size of the content to be transferred, in bytes. Unlike ``length``, this property

Sources/UnidocServer/Requests/Unidoc.Router.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,9 @@ extension Unidoc.Router
723723
}
724724
catch let error
725725
{
726-
return .sync(error: "Rejected webhook event: \(error)")
726+
// This is considered a server error, so we want to flag it as such for the
727+
// logging system to pick up.
728+
return .sync(error: "Rejected webhook event: \(error)", status: 500)
727729
}
728730

729731
default:

Sources/UnidocServer/Server/Unidoc.Server.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,13 @@ extension Unidoc.Server
193193
return await self.submit(update: procedural)
194194

195195
case .sync(let response):
196+
self.logger?.log(request: request.incoming, with: response, time: .zero)
196197
return response
197198

198199
case .syncHTML(let renderable):
199-
return renderable.response(format: self.format)
200+
let response:HTTP.ServerResponse = renderable.response(format: self.format)
201+
self.logger?.log(request: request.incoming, with: response, time: .zero)
202+
return response
200203

201204
case .syncLoad(let request):
202205
guard case .development(let cache, _) = self.options.mode

0 commit comments

Comments
 (0)