Skip to content

Commit d370689

Browse files
committed
Add release notes endpoint
1 parent 3d0fea9 commit d370689

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

OctoKit/Releases.swift

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public struct Release: Codable {
4747
}
4848
}
4949

50+
public struct ReleaseNotes: Codable {
51+
public let name: String
52+
public let body: String
53+
}
54+
5055
// MARK: request
5156

5257
public extension Octokit {
@@ -161,6 +166,44 @@ public extension Octokit {
161166
let router = ReleaseRouter.deleteRelease(configuration, owner, repository, releaseId)
162167
return router.load(session, completion: completion)
163168
}
169+
170+
/// Generates release notes.
171+
/// - Parameters:
172+
/// - session: RequestKitURLSession, defaults to URLSession.shared()
173+
/// - owner: The user or organization that owns the repositories.
174+
/// - repo: The repository on which the release needs to be deleted.
175+
/// - releaseId: The ID of the release to delete.
176+
/// - completion: Callback for the outcome of the deletion.
177+
@discardableResult
178+
/// Generates release notes.
179+
/// - Parameters:
180+
/// - session: RequestKitURLSession, defaults to URLSession.shared()
181+
/// - owner: The user or organization that owns the repositories.
182+
/// - repo: The repository on which the release needs to be deleted.
183+
/// - tagName: The tag name for the release. This can be an existing tag or a new one.
184+
/// - targetCommitish: Specifies the commitish value that will be the target for the release's tag. Required if the supplied tag_name does not reference an existing tag. Ignored if the tagName already exists.
185+
/// - previousTagName: The name of the previous tag to use as the starting point for the release notes. Use to manually specify the range for the set of changes considered as part this release.
186+
/// - completion: Callback for the outcome of the generation.
187+
func generateReleaseNotes(_ session: RequestKitURLSession = URLSession.shared,
188+
owner: String,
189+
repository: String,
190+
tagName: String,
191+
targetCommitish: String,
192+
previousTagName: String,
193+
completion: @escaping (_ response: Result<ReleaseNotes, Error>) -> Void) -> URLSessionDataTaskProtocol?
194+
{
195+
let router = ReleaseRouter.generateNotes(configuration, owner, repository, tagName, targetCommitish, previousTagName)
196+
197+
return router.post(session, expectedResultType: ReleaseNotes.self) { releaseNotes, error in
198+
if let error = error {
199+
completion(.failure(error))
200+
} else {
201+
if let releaseNotes = releaseNotes {
202+
completion(.success(releaseNotes))
203+
}
204+
}
205+
}
206+
}
164207
}
165208

166209
// MARK: Router
@@ -170,21 +213,23 @@ enum ReleaseRouter: JSONPostRouter {
170213
case getReleaseByTag(Configuration, String, String, String)
171214
case postRelease(Configuration, String, String, String, String?, String?, String?, Bool, Bool, Bool)
172215
case deleteRelease(Configuration, String, String, Int)
216+
case generateNotes(Configuration, String, String, String, String, String)
173217

174218
var configuration: Configuration {
175219
switch self {
176220
case let .listReleases(config, _, _, _): return config
177221
case let .getReleaseByTag(config, _, _, _): return config
178222
case let .postRelease(config, _, _, _, _, _, _, _, _, _): return config
179223
case let .deleteRelease(config, _, _, _): return config
224+
case let .generateNotes(config, _, _, _, _, _): return config
180225
}
181226
}
182227

183228
var method: HTTPMethod {
184229
switch self {
185230
case .listReleases, .getReleaseByTag:
186231
return .GET
187-
case .postRelease:
232+
case .postRelease, .generateNotes:
188233
return .POST
189234
case .deleteRelease:
190235
return .DELETE
@@ -195,7 +240,7 @@ enum ReleaseRouter: JSONPostRouter {
195240
switch self {
196241
case .listReleases, .getReleaseByTag:
197242
return .url
198-
case .postRelease:
243+
case .postRelease, .generateNotes:
199244
return .json
200245
case .deleteRelease:
201246
return .url
@@ -227,6 +272,13 @@ enum ReleaseRouter: JSONPostRouter {
227272
return params
228273
case .deleteRelease:
229274
return [:]
275+
case let .generateNotes(_, _, _, tagName, targetCommitish, previousTagName):
276+
let params: [String: Any] = [
277+
"tag_name": tagName,
278+
"target_commitish": targetCommitish,
279+
"previous_tag_name": previousTagName
280+
]
281+
return params
230282
}
231283
}
232284

@@ -240,6 +292,8 @@ enum ReleaseRouter: JSONPostRouter {
240292
return "repos/\(owner)/\(repo)/releases"
241293
case let .deleteRelease(_, owner, repo, releaseId):
242294
return "repos/\(owner)/\(repo)/releases/\(releaseId)"
295+
case let .generateNotes(_, owner, repo, _, _, _):
296+
return "repos/\(owner)/\(repo)/releases/generate-notes"
243297
}
244298
}
245299
}

0 commit comments

Comments
 (0)