Skip to content

Commit 3ce672d

Browse files
committed
factor nio-dependent parts of GitHubIntegration into GitHubClient
1 parent f07a313 commit 3ce672d

File tree

7 files changed

+42
-13
lines changed

7 files changed

+42
-13
lines changed

Package.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,15 @@ let package:Package = .init(
123123

124124
.target(name: "FNV1"),
125125

126+
.target(name: "GitHubClient", dependencies:
127+
[
128+
.target(name: "GitHubIntegration"),
129+
.target(name: "HTTPClient"),
130+
]),
131+
126132
.target(name: "GitHubIntegration", dependencies:
127133
[
128134
.target(name: "JSON"),
129-
.target(name: "HTTPClient"),
130135
]),
131136

132137
.target(name: "HTML", dependencies:
@@ -360,6 +365,7 @@ let package:Package = .init(
360365

361366
.target(name: "UnidocDatabase", dependencies:
362367
[
368+
.target(name: "GitHubIntegration"),
363369
.target(name: "UnidocAnalysis"),
364370
.target(name: "UnidocLinker"),
365371
.product(name: "MongoDB", package: "swift-mongodb"),
@@ -427,6 +433,7 @@ let package:Package = .init(
427433

428434
.executableTarget(name: "UnidocServer", dependencies:
429435
[
436+
.target(name: "GitHubClient"),
430437
.target(name: "Multiparts"),
431438
.target(name: "System"),
432439
.target(name: "UnidocPages"),

Sources/GitHubIntegration/GitHubApplication.Client.swift renamed to Sources/GitHubClient/GitHubApplication.Client.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import GitHubIntegration
12
import HTTPClient
23
import JSON
34
import NIOCore
@@ -10,6 +11,7 @@ extension GitHubApplication
1011
{
1112
private
1213
let http2:ClientInterface
14+
1315
public
1416
let app:GitHubApplication
1517

@@ -21,6 +23,14 @@ extension GitHubApplication
2123
}
2224
}
2325
}
26+
extension GitHubApplication.Client:Identifiable
27+
{
28+
@inlinable public
29+
var id:String { self.app.client }
30+
31+
@inlinable public
32+
var secret:String { self.app.secret }
33+
}
2434
extension GitHubApplication.Client
2535
{
2636
public
@@ -33,7 +43,7 @@ extension GitHubApplication.Client
3343
":authority": "github.com",
3444
":path": """
3545
/login/oauth/access_token?\
36-
client_id=\(self.app.id)&client_secret=\(self.app.secret)&code=\(code)
46+
client_id=\(self.id)&client_secret=\(self.secret)&code=\(code)
3747
""",
3848

3949
"accept": "application/vnd.github+json",

Sources/GitHubClient/exports.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@_exported import struct GitHubIntegration.GitHubApplication
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import HTTPClient
2-
import JSON
3-
import NIOCore
4-
import NIOHPACK
5-
61
@frozen public
72
struct GitHubApplication:Identifiable, Equatable, Hashable, Sendable
83
{
94
public
10-
let secret:String
5+
let id:Int
6+
117
public
12-
let id:String
8+
let client:String
9+
public
10+
let secret:String
1311

1412
@inlinable public
15-
init(_ id:String, secret:String = "3a892428d6381dbcfdafab55ad2fbec6d4847430")
13+
init(_ id:Int, client:String, secret:String)
1614
{
1715
self.id = id
16+
self.client = client
1817
self.secret = secret
1918
}
2019
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@frozen public
2+
struct User
3+
{
4+
public
5+
let id:Int
6+
}

Sources/UnidocPages/Templates/Site.Login.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ extension Site.Login:AdministrativePage
5555
}
5656
content:
5757
{
58-
$0[.input] { $0.type = "hidden" ; $0.name = "client_id" ; $0.value = self.app.id }
58+
$0[.input]
59+
{
60+
$0.type = "hidden"
61+
$0.name = "client_id"
62+
$0.value = self.app.client
63+
}
5964
$0[.input] { $0.type = "hidden" ; $0.name = "scope" ; $0.value = "repo" }
6065

6166
$0[.input] { $0.type = "submit" ; $0.value = "Log in with GitHub" }

Sources/UnidocServer/Server/Server.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import GitHubIntegration
1+
import GitHubClient
22
import HTTPClient
33
import HTTPServer
44
import MongoDB
@@ -57,7 +57,8 @@ extension Server
5757
http2: .init(threads: threads,
5858
niossl: niossl,
5959
remote: "github.com"),
60-
app: .init("Iv1.dba609d35c70bf57",
60+
app: .init(383005,
61+
client: "Iv1.dba609d35c70bf57",
6162
secret: secret))
6263
}
6364
else

0 commit comments

Comments
 (0)