From 485cbf820acbcb07c66f1f727ad576c2dd49499f Mon Sep 17 00:00:00 2001 From: David Rodrigues Date: Wed, 6 Nov 2019 10:08:03 +0000 Subject: [PATCH] Include a route to inform about the current state of the bot (#36) --- Sources/App/routes.swift | 4 ++++ Sources/Bot/Services/MergeService.swift | 26 ++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Sources/App/routes.swift b/Sources/App/routes.swift index 5c8f753..10578bd 100644 --- a/Sources/App/routes.swift +++ b/Sources/App/routes.swift @@ -8,6 +8,10 @@ public func routes( gitHubEventsService: GitHubEventsService ) throws { + router.get("/") { request -> String in + return String(describing: mergeService.state.value) + } + router.get("health") { request -> HTTPResponse in switch mergeService.healthcheck.status.value { case .ok: return HTTPResponse(status: .ok) diff --git a/Sources/Bot/Services/MergeService.swift b/Sources/Bot/Services/MergeService.swift index 7d16918..652bc3c 100644 --- a/Sources/Bot/Services/MergeService.swift +++ b/Sources/Bot/Services/MergeService.swift @@ -4,7 +4,7 @@ import ReactiveSwift import ReactiveFeedback public final class MergeService { - let state: Property + public let state: Property private let logger: LoggerProtocol private let gitHubAPI: GitHubAPIProtocol @@ -483,7 +483,7 @@ extension MergeService { extension MergeService { - enum FailureReason: Equatable { + public enum FailureReason: Equatable { case conflicts case mergeFailed case synchronizationFailed @@ -493,9 +493,9 @@ extension MergeService { case unknown } - struct State: Equatable { + public struct State: Equatable { - enum Status: Equatable { + public enum Status: Equatable { case starting case idle case ready @@ -503,7 +503,7 @@ extension MergeService { case runningStatusChecks(PullRequestMetadata) case integrationFailed(PullRequestMetadata, FailureReason) - var integrationMetadata: PullRequestMetadata? { + internal var integrationMetadata: PullRequestMetadata? { switch self { case let .integrating(metadata): return metadata @@ -512,7 +512,7 @@ extension MergeService { } } - var statusChecksMetadata: PullRequestMetadata? { + internal var statusChecksMetadata: PullRequestMetadata? { switch self { case let .runningStatusChecks(metadata): return metadata @@ -522,11 +522,11 @@ extension MergeService { } } - let integrationLabel: PullRequest.Label - let topPriorityLabels: [PullRequest.Label] - let statusChecksTimeout: TimeInterval - let pullRequests: [PullRequest] - let status: Status + internal let integrationLabel: PullRequest.Label + internal let topPriorityLabels: [PullRequest.Label] + internal let statusChecksTimeout: TimeInterval + public let pullRequests: [PullRequest] + public let status: Status var isIntegrationOngoing: Bool { switch status { @@ -730,7 +730,7 @@ private extension PullRequest { } } -extension MergeService.State: CustomDebugStringConvertible { +extension MergeService.State: CustomStringConvertible { private var queueDescription: String { guard pullRequests.isEmpty == false else { return "[]" } @@ -745,7 +745,7 @@ extension MergeService.State: CustomDebugStringConvertible { return "\(pullRequestsSeparator)\(pullRequestsRepresentation)" } - var debugDescription: String { + public var description: String { return "State(\n - status: \(status),\n - queue: \(queueDescription)\n)" } }