From 767931e48c684e113fd216bb3a07c26b8fd29837 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 23 Jan 2020 14:51:12 +0100 Subject: [PATCH] [IOSP-543] Fix MergeBot deployment (#51) * Made IDLE_BRANCH_QUEUE_CLEANUP_DELAY env optional * Improve documentation * Apply suggestions from code review * Since they are optional, shouldn't throw anymore --- .../Extensions/EnvironmentProperties.swift | 25 +++++++++++++------ Sources/App/configure.swift | 4 +-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Sources/App/Extensions/EnvironmentProperties.swift b/Sources/App/Extensions/EnvironmentProperties.swift index 4606689..ffb98e2 100644 --- a/Sources/App/Extensions/EnvironmentProperties.swift +++ b/Sources/App/Extensions/EnvironmentProperties.swift @@ -3,22 +3,28 @@ import Bot extension Environment { + /// GitHub Webhook secret static func gitHubWebhookSecret() throws -> String { return try Environment.get("GITHUB_WEBHOOK_SECRET") } + /// GitHub Token static func gitHubToken() throws -> String { return try Environment.get("GITHUB_TOKEN") } + /// GitHub Organisation name (as seen in the github.com//* urls) static func gitHubOrganization() throws -> String { return try Environment.get("GITHUB_ORGANIZATION") } + /// URL of GitHub Repository to run the MergeBot on static func gitHubRepository() throws -> String { return try Environment.get("GITHUB_REPOSITORY") } + /// If set to YES/1/TRUE, the Merge Bot will require all GitHub status checks to pass before accepting to merge + /// Otherwise, only the GitHub status checks that are marked as "required" in the GitHub settings to pass static func requiresAllGitHubStatusChecks() throws -> Bool { guard let stringValue: String = Environment.get("REQUIRES_ALL_STATUS_CHECKS") else { return false // defaults to only consider required checks @@ -26,21 +32,26 @@ extension Environment { return ["yes", "1", "true"].contains(stringValue.lowercased()) } - static func statusChecksTimeout() throws -> TimeInterval? { - let value: String = try Environment.get("STATUS_CHECKS_TIMEOUT") - return TimeInterval(value) + /// Maximum time (in seconds) to wait for a status check to finish running and report a red/green status + /// Defaults to 5400 (90 minutes) + static func statusChecksTimeout() -> TimeInterval? { + let value: String? = Environment.get("STATUS_CHECKS_TIMEOUT") + return value.flatMap(TimeInterval.init) } - /// Delay to wait after a MergeService is back in idle state before destroying it - static func idleMergeServiceCleanupDelay() throws -> TimeInterval? { - let value: String = try Environment.get("IDLE_BRANCH_QUEUE_CLEANUP_DELAY") - return TimeInterval(value) + /// Delay (in seconds) to wait after a MergeService is back in idle state before killing it. + /// Defaults to 300 seconds (5 minutes) + static func idleMergeServiceCleanupDelay() -> TimeInterval? { + let value: String? = Environment.get("IDLE_BRANCH_QUEUE_CLEANUP_DELAY") + return value.flatMap(TimeInterval.init) } + /// The text of the GitHub label that you want to use to trigger the MergeBot and add a PR to the queue static func mergeLabel() throws -> PullRequest.Label { return PullRequest.Label(name: try Environment.get("MERGE_LABEL")) } + /// Comma-separated list of GitHub label names that you want to use to bump a PR's priority – and make it jump to the front of the queue static func topPriorityLabels() throws -> [PullRequest.Label] { let labelsList: String = try Environment.get("TOP_PRIORITY_LABELS") return labelsList.split(separator: ",").map { name in diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 97afdc5..d26f77b 100644 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -46,8 +46,8 @@ private func makeDispatchService(with logger: LoggerProtocol, _ gitHubEventsServ integrationLabel: try Environment.mergeLabel(), topPriorityLabels: try Environment.topPriorityLabels(), requiresAllStatusChecks: try Environment.requiresAllGitHubStatusChecks(), - statusChecksTimeout: try Environment.statusChecksTimeout() ?? 90.minutes, - idleMergeServiceCleanupDelay: try Environment.idleMergeServiceCleanupDelay() ?? 5.minutes, + statusChecksTimeout: Environment.statusChecksTimeout() ?? 90.minutes, + idleMergeServiceCleanupDelay: Environment.idleMergeServiceCleanupDelay() ?? 5.minutes, logger: logger, gitHubAPI: gitHubAPI, gitHubEvents: gitHubEventsService