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

Move report logic on a separate file #111

Merged
merged 2 commits into from Nov 20, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@

## Master

Move report logic on a separate file [#111](https://github.com/danger/danger-swift/pull/111) by [@f-meloni][]

## 0.7.0

* Suggestions support [#110](https://github.com/danger/danger-swift/pull/110) by [@f-meloni][]
Expand Down
165 changes: 2 additions & 163 deletions Sources/Danger/Danger.swift
Expand Up @@ -9,8 +9,8 @@ import Logger

// MARK: - DangerRunner

private final class DangerRunner {
fileprivate static let shared = DangerRunner()
final class DangerRunner {
static let shared = DangerRunner()

let logger: Logger
let dsl: DangerDSL
Expand Down Expand Up @@ -68,167 +68,6 @@ public func Danger() -> DangerDSL {
return DangerRunner.shared.dsl
}

extension DangerDSL {
/// Fails on the Danger report
public var fails: [Violation] {
return DangerRunner.shared.results.fails
}

/// Warnings on the Danger report
public var warnings: [Violation] {
return DangerRunner.shared.results.warnings
}

/// Messages on the Danger report
public var messages: [Violation] {
return DangerRunner.shared.results.messages
}

/// Markdowns on the Danger report
public var markdowns: [Violation] {
return DangerRunner.shared.results.markdowns
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func warn(_ message: String) {
DangerRunner.shared.results.warnings.append(Violation(message: message))
}

/// Adds an inline warning message to the Danger report
public func warn(message: String, file: String, line: Int) {
DangerRunner.shared.results.warnings.append(Violation(message: message, file: file, line: line))
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func fail(_ message: String) {
DangerRunner.shared.results.fails.append(Violation(message: message))
}

/// Adds an inline fail message to the Danger report
public func fail(message: String, file: String, line: Int) {
DangerRunner.shared.results.fails.append(Violation(message: message, file: file, line: line))
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func message(_ message: String) {
DangerRunner.shared.results.messages.append(Violation(message: message))
}

/// Adds an inline message to the Danger report
public func message(message: String, file: String, line: Int) {
DangerRunner.shared.results.messages.append(Violation(message: message, file: file, line: line))
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func markdown(_ message: String) {
DangerRunner.shared.results.markdowns.append(Violation(message: message))
}

/// Adds an inline message to the Danger report
public func markdown(message: String, file: String, line: Int) {
DangerRunner.shared.results.markdowns.append(Violation(message: message, file: file, line: line))
}

/// Adds an inline suggestion to the Danger report (sends a normal message if suggestions are not supported)
public func suggestion(code: String, file: String, line: Int) {
let message: String

if DangerRunner.shared.dsl.supportsSuggestions {
message = """
```suggestion
\(code)
```
"""
} else {
message = code
}

DangerRunner.shared.results.markdowns.append(Violation(message: message, file: file, line: line))
}

}

/// Fails on the Danger report
public var fails: [Violation] {
return DangerRunner.shared.dsl.fails
}

/// Warnings on the Danger report
public var warnings: [Violation] {
return DangerRunner.shared.dsl.warnings
}

/// Messages on the Danger report
public var messages: [Violation] {
return DangerRunner.shared.dsl.messages
}

/// Markdowns on the Danger report
public var markdowns: [Violation] {
return DangerRunner.shared.dsl.markdowns
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func warn(_ message: String) {
DangerRunner.shared.dsl.warn(message)
}

/// Adds an inline warning message to the Danger report
public func warn(message: String, file: String, line: Int) {
DangerRunner.shared.dsl.warn(message: message, file: file, line: line)
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func fail(_ message: String) {
DangerRunner.shared.dsl.fail(message)
}

/// Adds an inline fail message to the Danger report
public func fail(message: String, file: String, line: Int) {
DangerRunner.shared.dsl.fail(message: message, file: file, line: line)
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func message(_ message: String) {
DangerRunner.shared.dsl.message(message)
}

/// Adds an inline message to the Danger report
public func message(message: String, file: String, line: Int) {
DangerRunner.shared.dsl.message(message: message, file: file, line: line)
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func markdown(_ message: String) {
DangerRunner.shared.dsl.markdown(message)
}

/// Adds an inline message to the Danger report
public func markdown(message: String, file: String, line: Int) {
DangerRunner.shared.dsl.markdown(message: message, file: file, line: line)
}

/// Adds an inline suggestion to the Danger report (sends a normal message if suggestions are not supported)
public func suggestion(code: String, file: String, line: Int) {
DangerRunner.shared.dsl.suggestion(code: code, file: file, line: line)
}

// MARK: - Private Functions

private var dumpInfo: (danger: DangerRunner, path: String)?
Expand Down
171 changes: 171 additions & 0 deletions Sources/Danger/Report.swift
@@ -0,0 +1,171 @@
//
// Report.swift
// Danger
//
// Created by Franco Meloni on 19/11/2018.
//

private var dangerRunner: DangerRunner {
return DangerRunner.shared
}

extension DangerDSL {
/// Fails on the Danger report
public var fails: [Violation] {
return dangerRunner.results.fails
}

/// Warnings on the Danger report
public var warnings: [Violation] {
return dangerRunner.results.warnings
}

/// Messages on the Danger report
public var messages: [Violation] {
return dangerRunner.results.messages
}

/// Markdowns on the Danger report
public var markdowns: [Violation] {
return dangerRunner.results.markdowns
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func warn(_ message: String) {
dangerRunner.results.warnings.append(Violation(message: message))
}

/// Adds an inline warning message to the Danger report
public func warn(message: String, file: String, line: Int) {
dangerRunner.results.warnings.append(Violation(message: message, file: file, line: line))
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func fail(_ message: String) {
dangerRunner.results.fails.append(Violation(message: message))
}

/// Adds an inline fail message to the Danger report
public func fail(message: String, file: String, line: Int) {
dangerRunner.results.fails.append(Violation(message: message, file: file, line: line))
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func message(_ message: String) {
dangerRunner.results.messages.append(Violation(message: message))
}

/// Adds an inline message to the Danger report
public func message(message: String, file: String, line: Int) {
dangerRunner.results.messages.append(Violation(message: message, file: file, line: line))
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func markdown(_ message: String) {
dangerRunner.results.markdowns.append(Violation(message: message))
}

/// Adds an inline message to the Danger report
public func markdown(message: String, file: String, line: Int) {
dangerRunner.results.markdowns.append(Violation(message: message, file: file, line: line))
}

/// Adds an inline suggestion to the Danger report (sends a normal message if suggestions are not supported)
public func suggestion(code: String, file: String, line: Int) {
let message: String

if dangerRunner.dsl.supportsSuggestions {
message = """
```suggestion
\(code)
```
"""
} else {
message = code
}

dangerRunner.results.markdowns.append(Violation(message: message, file: file, line: line))
}

}

/// Fails on the Danger report
public var fails: [Violation] {
return dangerRunner.dsl.fails
}

/// Warnings on the Danger report
public var warnings: [Violation] {
return dangerRunner.dsl.warnings
}

/// Messages on the Danger report
public var messages: [Violation] {
return dangerRunner.dsl.messages
}

/// Markdowns on the Danger report
public var markdowns: [Violation] {
return dangerRunner.dsl.markdowns
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func warn(_ message: String) {
dangerRunner.dsl.warn(message)
}

/// Adds an inline warning message to the Danger report
public func warn(message: String, file: String, line: Int) {
dangerRunner.dsl.warn(message: message, file: file, line: line)
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func fail(_ message: String) {
dangerRunner.dsl.fail(message)
}

/// Adds an inline fail message to the Danger report
public func fail(message: String, file: String, line: Int) {
dangerRunner.dsl.fail(message: message, file: file, line: line)
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func message(_ message: String) {
dangerRunner.dsl.message(message)
}

/// Adds an inline message to the Danger report
public func message(message: String, file: String, line: Int) {
dangerRunner.dsl.message(message: message, file: file, line: line)
}

/// Adds a warning message to the Danger report
///
/// - Parameter message: A markdown-ish
public func markdown(_ message: String) {
dangerRunner.dsl.markdown(message)
}

/// Adds an inline message to the Danger report
public func markdown(message: String, file: String, line: Int) {
dangerRunner.dsl.markdown(message: message, file: file, line: line)
}

/// Adds an inline suggestion to the Danger report (sends a normal message if suggestions are not supported)
public func suggestion(code: String, file: String, line: Int) {
dangerRunner.dsl.suggestion(code: code, file: file, line: line)
}