Skip to content

Commit bc284d5

Browse files
committed
optionally decode repo visibility and language
1 parent ce3d861 commit bc284d5

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed
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.Repo
4+
{
5+
@frozen public
6+
enum Visibility:String, JSONEncodable, JSONDecodable, Equatable, Sendable
7+
{
8+
case `public`
9+
case `private`
10+
}
11+
}

Sources/GitHubAPI/GitHub.Repo.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ extension GitHub
4646
public
4747
var fork:Bool
4848

49+
/// The repo’s visibility on GitHub. Some queries return only public repositories and so
50+
/// omit this field.
51+
public
52+
var visibility:Visibility?
53+
/// The repo’s dominant language, if GitHub was able to detect one.
54+
public
55+
var language:String?
4956
/// The repo’s homepage URL, if set.
5057
public
5158
var homepage:String?
@@ -79,6 +86,8 @@ extension GitHub
7986
archived:Bool,
8087
disabled:Bool,
8188
fork:Bool,
89+
visibility:Visibility? = nil,
90+
language:String? = nil,
8291
homepage:String? = nil,
8392
about:String? = nil,
8493
created:String,
@@ -98,6 +107,8 @@ extension GitHub
98107
self.archived = archived
99108
self.disabled = disabled
100109
self.fork = fork
110+
self.visibility = visibility
111+
self.language = language
101112
self.homepage = homepage
102113
self.about = about
103114
self.created = created
@@ -125,11 +136,13 @@ extension GitHub.Repo:JSONObjectDecodable
125136
case watchers = "subscribers_count"
126137
case forks = "forks_count"
127138
case stars = "stargazers_count"
128-
case size = "size"
129-
case archived = "archived"
130-
case disabled = "disabled"
131-
case fork = "fork"
132-
case homepage = "homepage"
139+
case size
140+
case archived
141+
case disabled
142+
case fork
143+
case visibility
144+
case language
145+
case homepage
133146
case about = "description"
134147
case created = "created_at"
135148
case updated = "updated_at"
@@ -155,6 +168,8 @@ extension GitHub.Repo:JSONObjectDecodable
155168
archived: try json[.archived].decode(),
156169
disabled: try json[.disabled].decode(),
157170
fork: try json[.fork].decode(),
171+
visibility: try json[.visibility]?.decode(),
172+
language: try json[.language]?.decode(),
158173
homepage: try json[.homepage]?.decode(),
159174
about: try json[.about]?.decode(),
160175
created: try json[.created].decode(),

Sources/GitHubAPI/GitHub.WebhookCreate.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ extension GitHub
1414
public
1515
let refType:RefType
1616

17+
public
18+
let installation:UInt?
19+
1720
@inlinable public
18-
init(repo:Repo, ref:String, refType:RefType)
21+
init(repo:Repo, ref:String, refType:RefType, installation:UInt?)
1922
{
2023
self.repo = repo
2124
self.ref = ref
2225
self.refType = refType
26+
self.installation = installation
2327
}
2428
}
2529
}
@@ -31,6 +35,12 @@ extension GitHub.WebhookCreate:JSONObjectDecodable
3135
case repository
3236
case ref
3337
case ref_type
38+
39+
case installation
40+
enum Installation:String, Sendable
41+
{
42+
case id
43+
}
3444
}
3545

3646
public
@@ -39,6 +49,10 @@ extension GitHub.WebhookCreate:JSONObjectDecodable
3949
self.init(
4050
repo: try json[.repository].decode(),
4151
ref: try json[.ref].decode(),
42-
refType: try json[.ref_type].decode())
52+
refType: try json[.ref_type].decode(),
53+
installation: try json[.installation]?.decode(using: CodingKey.Installation.self)
54+
{
55+
try $0[.id].decode()
56+
})
4357
}
4458
}

0 commit comments

Comments
 (0)