Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message when danger js is not installed #295

Merged
merged 2 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

## Master

- Add error message when danger js is not installed [@f-meloni][] - [#288](https://github.com/danger/swift/pull/295)
- Read standard error when the shell executor fails [@f-meloni][] - [#288](https://github.com/danger/swift/pull/288)
- Add --version support [@f-meloni][] - [#287](https://github.com/danger/swift/pull/287)

Expand Down
10 changes: 8 additions & 2 deletions Sources/Runner/Commands/RunDangerJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import Logger
import RunnerLib

func runDangerJSCommandToRunDangerSwift(_ command: DangerCommand, logger: Logger) throws -> Int32 {
let dangerJS = try getDangerCommandPath(logger: logger)
let dangerJSVersion = try DangerJSVersionFinder.findDangerJSVersion(dangerJSPath: dangerJS)
guard let dangerJS = try? getDangerCommandPath(logger: logger) else {
logger.logError("Danger JS was not found on the system",
"Please install it with npm or brew",
separator: "\n")
exit(1)
}

let dangerJSVersion = DangerJSVersionFinder.findDangerJSVersion(dangerJSPath: dangerJS)

guard dangerJSVersion.compare(MinimumDangerJSVersion, options: .numeric) != .orderedAscending else {
logger.logError("The installed danger-js version is below the minimum supported version",
Expand Down
6 changes: 3 additions & 3 deletions Sources/RunnerLib/DangerJSVersionFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import DangerShellExecutor
import Logger

public final class DangerJSVersionFinder {
public static func findDangerJSVersion(dangerJSPath: String) throws -> String {
return try findDangerJSVersion(dangerJSPath: dangerJSPath, executor: ShellExecutor())
public static func findDangerJSVersion(dangerJSPath: String) -> String {
return findDangerJSVersion(dangerJSPath: dangerJSPath, executor: ShellExecutor())
}

static func findDangerJSVersion(dangerJSPath: String, executor: ShellExecuting) throws -> String {
static func findDangerJSVersion(dangerJSPath: String, executor: ShellExecuting) -> String {
Logger().debug("Finding danger-js version")

return executor.execute(dangerJSPath, arguments: ["--version"])
Expand Down