Skip to content

Commit 2654dd2

Browse files
committed
handle GitHub repo not found
1 parent f5b725d commit 2654dd2

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

Sources/SwiftinitServer/Endpoints/Interactive/Swiftinit.PackageIndexEndpoint.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ extension Swiftinit.PackageIndexEndpoint:RestrictedEndpoint
4040
}
4141

4242
// Discard the tags for now, we want them to get indexed by the crawler.
43-
let repo:GitHub.Repo = (consume response).repo
43+
guard
44+
let repo:GitHub.Repo = response.repo
45+
else
46+
{
47+
return .notFound("No such repo.")
48+
}
4449

4550
guard repo.owner.login.allSatisfy({ $0 != "." })
4651
else

Sources/SwiftinitServer/Plugins/GitHubPlugin.RepoMonitor.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import BSON
22
import GitHubAPI
33
import GitHubClient
4+
import HTTPServer
45
import MongoDB
56
import SemanticVersions
67
import UnidocDB
@@ -109,9 +110,17 @@ extension GitHubPlugin.RepoMonitor:GitHubCrawler
109110
ordering: .relaxed)
110111
}
111112

112-
package.repo = try .github(response.repo)
113113
package.crawled = now
114114

115+
if let repo:GitHub.Repo = response.repo
116+
{
117+
package.repo = try .github(repo)
118+
}
119+
else
120+
{
121+
Log[.warning] = "(crawler) returned null for repo '\(package.symbol)'"
122+
}
123+
115124
switch try await server.db.packages.update(metadata: package, with: session)
116125
{
117126
case nil:

Sources/SwiftinitServer/Plugins/GitHubPlugin.RepoMonitorResponse.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ extension GitHubPlugin
66
/// Models a GraphQL repo monitor response.
77
struct RepoMonitorResponse
88
{
9-
var repo:GitHub.Repo
9+
var repo:GitHub.Repo?
1010
var tags:[GitHub.Tag]
1111

12-
init(repo:GitHub.Repo, tags:[GitHub.Tag])
12+
init(repo:GitHub.Repo?, tags:[GitHub.Tag])
1313
{
1414
self.repo = repo
1515
self.tags = tags
@@ -25,6 +25,12 @@ extension GitHubPlugin.RepoMonitorResponse:JSONObjectDecodable
2525

2626
init(json:JSON.ObjectDecoder<CodingKey>) throws
2727
{
28+
if case .null = json[.repository].value ?? .null
29+
{
30+
self.init(repo: nil, tags: [])
31+
return
32+
}
33+
2834
self = try json[.repository].decode(using: GitHub.RepoNode.CodingKey.self)
2935
{
3036
let node:GitHub.RepoNode = try .init(json: $0)

0 commit comments

Comments
 (0)