Skip to content

Commit 776f54a

Browse files
authored
Merge pull request #12 from tayloraswift/package-db
Package db
2 parents 5deb90a + e86ddf5 commit 776f54a

File tree

202 files changed

+4168
-2227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+4168
-2227
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ let package:Package = .init(
5555

5656
.library(name: "Unidoc", targets: ["Unidoc"]),
5757
.library(name: "UnidocAnalysis", targets: ["UnidocAnalysis"]),
58-
.library(name: "UnidocDatabase", targets: ["UnidocDatabase"]),
58+
.library(name: "UnidocDB", targets: ["UnidocDB"]),
5959
.library(name: "UnidocDiagnostics", targets: ["UnidocDiagnostics"]),
6060
.library(name: "UnidocLinker", targets: ["UnidocLinker"]),
6161
.library(name: "UnidocPages", targets: ["UnidocPages"]),
@@ -73,7 +73,7 @@ let package:Package = .init(
7373
.package(url: "https://github.com/tayloraswift/swift-grammar", .upToNextMinor(
7474
from: "0.3.2")),
7575
.package(url: "https://github.com/tayloraswift/swift-mongodb", .upToNextMinor(
76-
from: "0.7.2")),
76+
from: "0.8.1")),
7777

7878
.package(url: "https://github.com/swift-server/swift-backtrace", .upToNextMinor(
7979
from: "1.3.4")),
@@ -372,7 +372,7 @@ let package:Package = .init(
372372
.target(name: "UnidocSelectors"),
373373
]),
374374

375-
.target(name: "UnidocDatabase", dependencies:
375+
.target(name: "UnidocDB", dependencies:
376376
[
377377
.target(name: "GitHubIntegration"),
378378
.target(name: "UnidocAnalysis"),
@@ -407,7 +407,7 @@ let package:Package = .init(
407407

408408
.target(name: "UnidocQueries", dependencies:
409409
[
410-
.target(name: "UnidocDatabase"),
410+
.target(name: "UnidocDB"),
411411
.target(name: "UnidocSelectors"),
412412
]),
413413

@@ -423,6 +423,11 @@ let package:Package = .init(
423423
.target(name: "URI"),
424424
]),
425425

426+
.target(name: "UnixTime", dependencies:
427+
[
428+
.product(name: "BSON", package: "swift-mongodb"),
429+
]),
430+
426431
.target(name: "URI", dependencies:
427432
[
428433
.product(name: "Grammar", package: "swift-grammar"),
@@ -557,9 +562,10 @@ let package:Package = .init(
557562
.product(name: "BSONTesting", package: "swift-mongodb"),
558563
]),
559564

560-
.executableTarget(name: "UnidocDatabaseTests", dependencies:
565+
.executableTarget(name: "UnidocDBTests", dependencies:
561566
[
562-
.target(name: "UnidocDatabase"),
567+
.target(name: "UnidocDB"),
568+
.target(name: "GitHubClient"),
563569
.target(name: "SymbolGraphBuilder"),
564570
.target(name: "SymbolGraphTesting"),
565571
.product(name: "MongoTesting", package: "swift-mongodb"),

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22

3-
<strong><em><code>unidoc</code></em></strong><br><small><code>0.1.5</code></small>
3+
<strong><em><code>unidoc</code></em></strong><br><small><code>0.2.0</code></small>
44

55
[![ci build status](https://github.com/kelvin13/swift-unidoc/actions/workflows/build.yml/badge.svg)](https://github.com/kelvin13/swift-unidoc/actions/workflows/build.yml)
66

Sources/GitHubClient/GitHubClient.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,10 @@ extension GitHubClient
105105
}
106106
extension GitHubClient<GitHubAPI>
107107
{
108-
public
109-
func user(with token:String) async throws -> GitHubAPI.User
110-
{
111-
try await self.get(from: "/user", with: token)
112-
}
113-
114108
@inlinable public
115109
func get<Response>(_:Response.Type = Response.self,
116110
from endpoint:String,
117-
with token:String? = nil) async throws -> Response where Response:JSONObjectDecodable
111+
with token:String? = nil) async throws -> Response where Response:JSONDecodable
118112
{
119113
var request:HPACKHeaders =
120114
[
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import JSON
2+
3+
extension GitHubAPI.Repo
4+
{
5+
@frozen public
6+
struct License:Identifiable, Equatable, Sendable
7+
{
8+
/// The SPDX identifier of the license.
9+
public
10+
var id:String
11+
/// The full name of the license.
12+
public
13+
var name:String
14+
15+
@inlinable public
16+
init(id:String, name:String)
17+
{
18+
self.id = id
19+
self.name = name
20+
}
21+
}
22+
}
23+
extension GitHubAPI.Repo.License:JSONObjectDecodable
24+
{
25+
public
26+
enum CodingKey:String
27+
{
28+
case id = "spdx_id"
29+
case name
30+
}
31+
32+
public
33+
init(json:JSON.ObjectDecoder<CodingKey>) throws
34+
{
35+
self.init(id: try json[.id].decode(),
36+
name: try json[.name].decode())
37+
}
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import JSON
2+
3+
extension GitHubAPI.Repo
4+
{
5+
@frozen public
6+
struct Owner:Identifiable, Equatable, Sendable
7+
{
8+
public
9+
let id:Int32
10+
public
11+
var login:String
12+
public
13+
var node:String
14+
15+
@inlinable public
16+
init(id:Int32, login:String, node:String)
17+
{
18+
self.id = id
19+
self.login = login
20+
self.node = node
21+
}
22+
}
23+
}
24+
extension GitHubAPI.Repo.Owner:JSONObjectDecodable
25+
{
26+
public
27+
enum CodingKey:String
28+
{
29+
case id
30+
case login
31+
case node = "node_id"
32+
}
33+
34+
public
35+
init(json:JSON.ObjectDecoder<CodingKey>) throws
36+
{
37+
self.init(id: try json[.id].decode(),
38+
login: try json[.login].decode(),
39+
node: try json[.node].decode())
40+
}
41+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import JSON
2+
3+
extension GitHubAPI
4+
{
5+
@frozen public
6+
struct Repo:Identifiable, Equatable, Sendable
7+
{
8+
public
9+
let id:Int32
10+
public
11+
var owner:Owner
12+
public
13+
var name:String
14+
public
15+
var node:String
16+
17+
/// The repo’s license, if GitHub was able to detect it.
18+
public
19+
var license:License?
20+
/// The repo’s topic tags.
21+
public
22+
var topics:[String]
23+
/// The name of the repo’s default branch.
24+
public
25+
var master:String
26+
27+
/// The number of subscribers this repo has.
28+
public
29+
var watchers:Int
30+
/// The number of forks this repo has.
31+
public
32+
var forks:Int
33+
/// The number of stargazers this repo has.
34+
public
35+
var stars:Int
36+
/// The approximate size of the repo, in kilobytes.
37+
public
38+
var size:Int
39+
40+
/// Indicates if the repo is archived.
41+
public
42+
var archived:Bool
43+
/// Indicates if the repo is disabled.
44+
public
45+
var disabled:Bool
46+
/// Indicates if the repo is a fork.
47+
public
48+
var fork:Bool
49+
50+
/// The repo’s homepage URL, if set.
51+
public
52+
var homepage:String?
53+
/// The repo’s description, if set.
54+
public
55+
var about:String?
56+
57+
/// When the repository was first created.
58+
public
59+
var created:String
60+
/// When the repository itself (as opposed to its content) was last updated.
61+
/// This is usually different from ``pushed``.
62+
public
63+
var updated:String
64+
/// When the repository content (as opposed to its metadata) was last pushed to.
65+
/// This is usually different from ``updated``.
66+
public
67+
var pushed:String
68+
69+
@inlinable public
70+
init(id:Int32,
71+
owner:Owner,
72+
name:String,
73+
node:String,
74+
license:License? = nil,
75+
topics:[String] = [],
76+
master:String,
77+
watchers:Int,
78+
forks:Int,
79+
stars:Int,
80+
size:Int,
81+
archived:Bool,
82+
disabled:Bool,
83+
fork:Bool,
84+
homepage:String? = nil,
85+
about:String? = nil,
86+
created:String,
87+
updated:String,
88+
pushed:String)
89+
{
90+
self.id = id
91+
self.owner = owner
92+
self.name = name
93+
self.node = node
94+
self.license = license
95+
self.topics = topics
96+
self.master = master
97+
self.watchers = watchers
98+
self.forks = forks
99+
self.stars = stars
100+
self.size = size
101+
self.archived = archived
102+
self.disabled = disabled
103+
self.fork = fork
104+
self.homepage = homepage
105+
self.about = about
106+
self.created = created
107+
self.updated = updated
108+
self.pushed = pushed
109+
}
110+
}
111+
}
112+
extension GitHubAPI.Repo:JSONObjectDecodable
113+
{
114+
public
115+
enum CodingKey:String
116+
{
117+
case id
118+
case owner
119+
case name
120+
case node = "node_id"
121+
case license
122+
case topics
123+
case master = "default_branch"
124+
// not `watchers_count`, which is just stargazers
125+
case watchers = "subscribers_count"
126+
case forks = "forks_count"
127+
case stars = "stargazers_count"
128+
case size = "size"
129+
case archived = "archived"
130+
case disabled = "disabled"
131+
case fork = "fork"
132+
case homepage = "homepage"
133+
case about = "description"
134+
case created = "created_at"
135+
case updated = "updated_at"
136+
case pushed = "pushed_at"
137+
}
138+
139+
public
140+
init(json:JSON.ObjectDecoder<CodingKey>) throws
141+
{
142+
self.init(id: try json[.id].decode(),
143+
owner: try json[.owner].decode(),
144+
name: try json[.name].decode(),
145+
node: try json[.node].decode(),
146+
license: try json[.license]?.decode(),
147+
topics: try json[.topics]?.decode() ?? [],
148+
master: try json[.master].decode(),
149+
watchers: try json[.watchers].decode(),
150+
forks: try json[.forks].decode(),
151+
stars: try json[.stars].decode(),
152+
size: try json[.size].decode(),
153+
archived: try json[.archived].decode(),
154+
disabled: try json[.disabled].decode(),
155+
fork: try json[.fork].decode(),
156+
homepage: try json[.homepage]?.decode(as: String.self) { $0.isEmpty ? nil : $0 },
157+
about: try json[.about]?.decode(as: String.self) { $0.isEmpty ? nil : $0 },
158+
created: try json[.created].decode(),
159+
updated: try json[.updated].decode(),
160+
pushed: try json[.pushed].decode())
161+
}
162+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import JSON
2+
import SHA1
3+
4+
extension GitHubAPI.Tag
5+
{
6+
struct Commit
7+
{
8+
let sha:SHA1
9+
10+
init(sha:SHA1)
11+
{
12+
self.sha = sha
13+
}
14+
}
15+
}
16+
extension GitHubAPI.Tag.Commit:JSONObjectDecodable
17+
{
18+
enum CodingKey:String
19+
{
20+
case sha
21+
}
22+
23+
init(json:JSON.ObjectDecoder<CodingKey>) throws
24+
{
25+
self.init(sha: try json[.sha].decode())
26+
}
27+
}

0 commit comments

Comments
 (0)