Skip to content

Commit

Permalink
[IOSP-543] Fix MergeBot deployment (#51)
Browse files Browse the repository at this point in the history
* Made IDLE_BRANCH_QUEUE_CLEANUP_DELAY env optional

* Improve documentation

* Apply suggestions from code review

* Since they are optional, shouldn't throw anymore
  • Loading branch information
Olivier Halligon authored Jan 23, 2020
1 parent 2b8af89 commit 767931e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions Sources/App/Extensions/EnvironmentProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,55 @@ 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/<orgname>/* 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
}
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
Expand Down
4 changes: 2 additions & 2 deletions Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 767931e

Please sign in to comment.