Skip to content

Commit

Permalink
Include a route to inform about the current state of the bot (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcrodrigues authored and ilyapuchka committed Nov 6, 2019
1 parent 312c739 commit 485cbf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Sources/App/routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions Sources/Bot/Services/MergeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ReactiveSwift
import ReactiveFeedback

public final class MergeService {
let state: Property<State>
public let state: Property<State>

private let logger: LoggerProtocol
private let gitHubAPI: GitHubAPIProtocol
Expand Down Expand Up @@ -483,7 +483,7 @@ extension MergeService {

extension MergeService {

enum FailureReason: Equatable {
public enum FailureReason: Equatable {
case conflicts
case mergeFailed
case synchronizationFailed
Expand All @@ -493,17 +493,17 @@ extension MergeService {
case unknown
}

struct State: Equatable {
public struct State: Equatable {

enum Status: Equatable {
public enum Status: Equatable {
case starting
case idle
case ready
case integrating(PullRequestMetadata)
case runningStatusChecks(PullRequestMetadata)
case integrationFailed(PullRequestMetadata, FailureReason)

var integrationMetadata: PullRequestMetadata? {
internal var integrationMetadata: PullRequestMetadata? {
switch self {
case let .integrating(metadata):
return metadata
Expand All @@ -512,7 +512,7 @@ extension MergeService {
}
}

var statusChecksMetadata: PullRequestMetadata? {
internal var statusChecksMetadata: PullRequestMetadata? {
switch self {
case let .runningStatusChecks(metadata):
return metadata
Expand All @@ -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 {
Expand Down Expand Up @@ -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 "[]" }
Expand All @@ -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)"
}
}
Expand Down

0 comments on commit 485cbf8

Please sign in to comment.