Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 7975653

Browse files
committed
add commitcomment event
1 parent 91e9724 commit 7975653

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

Sources/Swoctokit/SwoctokitWebhookClient.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ public protocol PullRequestEventListener: class {
1717

1818
}
1919

20+
public protocol CommitCommentEventListener: class {
21+
22+
func commitCommentEventReceived(_ commitCommentEvent: CommitCommentEvent)
23+
24+
}
25+
2026
public class SwoctokitWebhookClient {
2127

2228
private let application: Application
2329

2430
private var pullRequestEventListeners = [PullRequestEventListener]()
25-
31+
private var commitCommentEventListeners = [CommitCommentEventListener]()
2632

2733
public init(_ application: Application) throws {
2834
self.application = application
@@ -41,6 +47,10 @@ public class SwoctokitWebhookClient {
4147
pullRequestEventListeners.append(listener)
4248
}
4349

50+
public func addCommitCommentEventListener(_ listener: CommitCommentEventListener) {
51+
commitCommentEventListeners.append(listener)
52+
}
53+
4454
}
4555

4656
extension SwoctokitWebhookClient: WebhookControllerDelegate {
@@ -49,6 +59,8 @@ extension SwoctokitWebhookClient: WebhookControllerDelegate {
4959
switch event {
5060
case let event as PullRequestEvent:
5161
pullRequestEventReceived(event)
62+
case let event as CommitCommentEvent:
63+
commitCommentEventReceived(event)
5264
default:
5365
break
5466
}
@@ -58,4 +70,8 @@ extension SwoctokitWebhookClient: WebhookControllerDelegate {
5870
pullRequestEventListeners.forEach { $0.pullRequestEventReceived(event) }
5971
}
6072

73+
func commitCommentEventReceived(_ event: CommitCommentEvent) {
74+
commitCommentEventListeners.forEach { $0.commitCommentEventReceived(event) }
75+
}
76+
6177
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// CommitCommentEvent.swift
3+
// Swoctokit
4+
//
5+
// Created by Franz Busch on 14.11.18.
6+
//
7+
8+
public struct CommitCommentEvent: Decodable, WebhookEvent {
9+
10+
public let action: String
11+
public let comment: CommitComment
12+
13+
}
14+
15+
public struct CommitComment: Decodable {
16+
17+
public let id: Int
18+
public let url: String
19+
public let body: String
20+
public let commitId: String
21+
22+
private enum CodingKeys: String, CodingKey {
23+
case id
24+
case url
25+
case body
26+
case commitId = "commit_id"
27+
}
28+
29+
}

Sources/Swoctokit/Webhook/EventTypes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ import Foundation
1313

1414
public enum EventType: String {
1515
case pullRequest = "pull_request"
16+
case commitComment = "commit_comment"
1617
}

Sources/Swoctokit/Webhook/WebhookController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ final class WebhookController: RouteCollection {
4646
if let pullRequestEvent = try? req.content.syncDecode(PullRequestEvent.self) {
4747
delegate?.didReceive(event: pullRequestEvent)
4848
}
49+
case .commitComment:
50+
if let commitCommentEvent = try? req.content.syncDecode(CommitCommentEvent.self) {
51+
delegate?.didReceive(event: commitCommentEvent)
52+
}
4953
}
5054

5155
return .ok

0 commit comments

Comments
 (0)