Skip to content

Commit 3579076

Browse files
committed
round out the GitHub API definitions
1 parent c27c5fb commit 3579076

17 files changed

+306
-70
lines changed

Sources/GitHubAPI/GitHub.App.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ extension GitHub
66
{
77
/// The app id number. This is different from the client id.
88
public
9-
let id:Int?
9+
let id:Int32?
1010

1111
public
1212
let client:String
1313
public
1414
let secret:String
1515

1616
@inlinable public
17-
init(_ id:Int?, client:String, secret:String)
17+
init(_ id:Int32?, client:String, secret:String)
1818
{
1919
self.id = id
2020
self.client = client

Sources/GitHubAPI/GitHub.Installation.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ extension GitHub
77
{
88
public
99
let id:Int32
10+
public
11+
let app:Int32
12+
public
13+
let account:UserInvite
1014

1115
@inlinable public
12-
init(id:Int32)
16+
init(id:Int32, app:Int32, account:UserInvite)
1317
{
1418
self.id = id
19+
self.app = app
20+
self.account = account
1521
}
1622
}
1723
}
@@ -22,13 +28,17 @@ extension GitHub.Installation
2228
enum CodingKey:String, Sendable
2329
{
2430
case id
31+
case app_id
32+
case account
2533
}
2634
}
2735
extension GitHub.Installation:JSONObjectDecodable
2836
{
2937
public
3038
init(json:JSON.ObjectDecoder<CodingKey>) throws
3139
{
32-
self.init(id: try json[.id].decode())
40+
self.init(id: try json[.id].decode(),
41+
app: try json[.app_id].decode(),
42+
account: try json[.account].decode())
3343
}
3444
}

Sources/GitHubAPI/GitHub.Repo.Owner.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ extension GitHub.Repo
1818
}
1919
}
2020
}
21+
extension GitHub.Repo.Owner:CustomStringConvertible
22+
{
23+
/// This conformance witnessed to idiot-proof string interpolation mistakes, as this type
24+
/// sometimes appears in an `owner` field that is otherwise a ``String``. Prefer
25+
/// interpolating ``login`` directly!
26+
@inlinable public
27+
var description:String { self.login }
28+
}
2129
extension GitHub.Repo.Owner:JSONObjectDecodable
2230
{
2331
public

Sources/GitHubAPI/GitHub.Repo.Visibility.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/GitHubAPI/GitHub.Repo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extension GitHub
5252
/// The repo’s visibility on GitHub. Some queries return only public repositories and so
5353
/// omit this field.
5454
public
55-
var visibility:Visibility?
55+
var visibility:RepoVisibility?
5656
/// The repo’s dominant language, if GitHub was able to detect one.
5757
public
5858
var language:String?
@@ -90,7 +90,7 @@ extension GitHub
9090
archived:Bool,
9191
disabled:Bool,
9292
fork:Bool,
93-
visibility:Visibility? = nil,
93+
visibility:RepoVisibility? = nil,
9494
language:String? = nil,
9595
homepage:String? = nil,
9696
about:String? = nil,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import JSON
2+
3+
extension GitHub
4+
{
5+
@frozen public
6+
struct RepoInvite:Identifiable, Equatable, Sendable
7+
{
8+
public
9+
let id:Int32
10+
public
11+
let name:String
12+
public
13+
let node:Node
14+
public
15+
let visibility:RepoVisibility
16+
17+
@inlinable public
18+
init(id:Int32, name:String, node:Node, visibility:RepoVisibility)
19+
{
20+
self.id = id
21+
self.name = name
22+
self.node = node
23+
self.visibility = visibility
24+
}
25+
}
26+
}
27+
extension GitHub.RepoInvite:JSONObjectDecodable
28+
{
29+
public
30+
enum CodingKey:String, Sendable
31+
{
32+
case id
33+
case node_id
34+
case name
35+
case `private`
36+
}
37+
38+
public
39+
init(json:JSON.ObjectDecoder<CodingKey>) throws
40+
{
41+
self.init(id: try json[.id].decode(),
42+
name: try json[.name].decode(),
43+
node: try json[.node_id].decode(),
44+
visibility: try json[.private].decode(to: Bool.self) ? .private : .public)
45+
}
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import JSON
2+
3+
extension GitHub
4+
{
5+
@frozen public
6+
enum RepoVisibility:String, JSONEncodable, JSONDecodable, Equatable, Sendable
7+
{
8+
case `public`
9+
case `private`
10+
}
11+
}

Sources/GitHubAPI/GitHub.User.Profile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension GitHub.User
1111
var icon:String
1212
/// The user’s node id. This is GitHub’s analogue of a Unidoc scalar.
1313
public
14-
var node:String
14+
var node:GitHub.Node
1515

1616
/// The user’s location, if set.
1717
public
@@ -55,7 +55,7 @@ extension GitHub.User
5555
init(
5656
login:String,
5757
icon:String,
58-
node:String,
58+
node:GitHub.Node,
5959
location:String?,
6060
hireable:Bool?,
6161
company:String?,

Sources/GitHubAPI/GitHub.User.swift

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ extension GitHub.User
2424
enum CodingKey:String, Sendable
2525
{
2626
case id
27-
case profile_login = "login"
28-
case profile_icon = "avatar_url"
29-
case profile_node = "node_id"
30-
case profile_location = "location"
31-
case profile_hireable = "hireable"
32-
case profile_company = "company"
33-
case profile_email = "email"
34-
case profile_name = "name"
35-
case profile_blog = "blog"
36-
case profile_bio = "bio"
37-
case profile_x = "twitter_username"
38-
case profile_publicRepos = "public_repos"
39-
case profile_publicGists = "public_gists"
40-
case profile_followers = "followers"
41-
case profile_following = "following"
42-
case profile_created = "created_at"
43-
case profile_updated = "updated_at"
27+
case login
28+
case avatar_url
29+
case node_id
30+
case location
31+
case hireable
32+
case company
33+
case email
34+
case name
35+
case blog
36+
case bio
37+
case twitter_username
38+
case public_repos
39+
case public_gists
40+
case followers
41+
case following
42+
case created_at
43+
case updated_at
4444
}
4545
}
4646
extension GitHub.User:JSONObjectDecodable, JSONDecodable
@@ -49,22 +49,22 @@ extension GitHub.User:JSONObjectDecodable, JSONDecodable
4949
init(json:JSON.ObjectDecoder<CodingKey>) throws
5050
{
5151
self.init(id: try json[.id].decode(), profile: .init(
52-
login: try json[.profile_login].decode(),
53-
icon: try json[.profile_icon].decode(),
54-
node: try json[.profile_node].decode(),
55-
location: try json[.profile_location]?.decode(),
56-
hireable: try json[.profile_hireable]?.decode(),
57-
company: try json[.profile_company]?.decode(),
58-
email: try json[.profile_email]?.decode(),
59-
name: try json[.profile_name]?.decode(),
60-
blog: try json[.profile_blog]?.decode(),
61-
bio: try json[.profile_bio]?.decode(),
62-
x: try json[.profile_x]?.decode(),
63-
publicRepos: try json[.profile_publicRepos].decode(),
64-
publicGists: try json[.profile_publicGists].decode(),
65-
followers: try json[.profile_followers].decode(),
66-
following: try json[.profile_following].decode(),
67-
created: try json[.profile_created].decode(),
68-
updated: try json[.profile_updated].decode()))
52+
login: try json[.login].decode(),
53+
icon: try json[.avatar_url].decode(),
54+
node: try json[.node_id].decode(),
55+
location: try json[.location]?.decode(),
56+
hireable: try json[.hireable]?.decode(),
57+
company: try json[.company]?.decode(),
58+
email: try json[.email]?.decode(),
59+
name: try json[.name]?.decode(),
60+
blog: try json[.blog]?.decode(),
61+
bio: try json[.bio]?.decode(),
62+
x: try json[.twitter_username]?.decode(),
63+
publicRepos: try json[.public_repos].decode(),
64+
publicGists: try json[.public_gists].decode(),
65+
followers: try json[.followers].decode(),
66+
following: try json[.following].decode(),
67+
created: try json[.created_at].decode(),
68+
updated: try json[.updated_at].decode()))
6969
}
7070
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import JSON
2+
3+
extension GitHub
4+
{
5+
@frozen public
6+
struct UserInvite:Identifiable, Equatable, Sendable
7+
{
8+
public
9+
let id:UInt32
10+
/// The user’s @-name.
11+
public
12+
var login:String
13+
/// The user’s icon URL.
14+
public
15+
var icon:String
16+
/// The user’s node id within the GraphQL API.
17+
public
18+
var node:Node
19+
20+
@inlinable public
21+
init(id:UInt32, login:String, icon:String, node:Node)
22+
{
23+
self.id = id
24+
self.login = login
25+
self.icon = icon
26+
self.node = node
27+
}
28+
}
29+
}
30+
extension GitHub.UserInvite:JSONObjectDecodable
31+
{
32+
public
33+
init(json:JSON.ObjectDecoder<GitHub.User.CodingKey>) throws
34+
{
35+
self.init(id: try json[.id].decode(),
36+
login: try json[.login].decode(),
37+
icon: try json[.avatar_url].decode(),
38+
node: try json[.node_id].decode())
39+
}
40+
}

0 commit comments

Comments
 (0)