-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from swiftlane-code/di-container
Introducing DI Container based object assembly and moving away from yaml configs to in-code configs
- Loading branch information
Showing
165 changed files
with
2,786 additions
and
2,761 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Sources/Guardian/Services/MergeRequestReporter/FileMergeRequestReporter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
|
||
import Foundation | ||
import SwiftlaneCore | ||
|
||
public extension FileMergeRequestReporter { | ||
/// Create new `FileMergeRequestReporter` instance. | ||
convenience init( | ||
logger: Logging, | ||
filesManager: FSManaging, | ||
reportFilePath: AbsolutePath | ||
) { | ||
self.init( | ||
logger: logger, | ||
filesManager: filesManager, | ||
reportFactory: MergeRequestReportFactory( | ||
captionProvider: MergeRequestReportCaptionProvider(ciToolName: "Swiftlane") | ||
), | ||
reportFilePath: reportFilePath | ||
) | ||
} | ||
} | ||
|
||
public class FileMergeRequestReporter: MergeRequestReporting { | ||
public enum Errors: Error, Equatable { | ||
case failsReported(reportURL: String) | ||
} | ||
|
||
private let logger: Logging | ||
private let filesManager: FSManaging | ||
private let reportFactory: MergeRequestReportFactoring | ||
private let reportFilePath: AbsolutePath | ||
|
||
private var fails: [String] = [] | ||
private var warns: [String] = [] | ||
private var messages: [String] = [] | ||
private var markdowns: [String] = [] | ||
private var successes: [String] = [] | ||
|
||
private var isEmptyReport: Bool { | ||
[fails, warns, messages, markdowns, successes].allSatisfy(\.isEmpty) | ||
} | ||
|
||
/// Create new `FileMergeRequestReporter` instance. | ||
public init( | ||
logger: Logging, | ||
filesManager: FSManaging, | ||
reportFactory: MergeRequestReportFactoring, | ||
reportFilePath: AbsolutePath | ||
) { | ||
self.logger = logger | ||
self.filesManager = filesManager | ||
self.reportFactory = reportFactory | ||
self.reportFilePath = reportFilePath | ||
} | ||
|
||
public func hasFails() -> Bool { | ||
!fails.isEmpty | ||
} | ||
|
||
public func createOrUpdateReport() throws { | ||
let text = reportFactory.reportBody( | ||
fails: fails, | ||
warns: warns, | ||
messages: messages, | ||
markdowns: markdowns, | ||
successes: successes, | ||
invisibleMark: "invisibleMergeRequestNoteMark", | ||
commitSHA: "fakeCommitSHA" | ||
) | ||
|
||
logger.verbose("Guardian report: \n" + text.addPrefixToAllLines("\t")) | ||
|
||
try filesManager.write(reportFilePath, text: text) | ||
|
||
if hasFails() { | ||
let guardianError = Errors.failsReported(reportURL: reportFilePath.string) | ||
logger.logError(guardianError) | ||
throw guardianError | ||
} else { | ||
logger.success("Reported no fails, report url: \(reportFilePath.string)") | ||
} | ||
} | ||
|
||
public func warn(_ markdown: String) { | ||
warns.append(markdown) | ||
} | ||
|
||
public func fail(_ markdown: String) { | ||
fails.append(markdown) | ||
} | ||
|
||
public func message(_ markdown: String) { | ||
messages.append(markdown) | ||
} | ||
|
||
public func markdown(_ markdown: String) { | ||
markdowns.append(markdown) | ||
} | ||
|
||
public func success(_ markdown: String) { | ||
successes.append(markdown) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Sources/Guardian/Services/MergeRequestReporter/MergeRequestReporting.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
|
||
// sourcery: AutoMockable | ||
public protocol MergeRequestReporting { | ||
func createOrUpdateReport() throws | ||
|
||
func warn(_ markdown: String) | ||
|
||
func fail(_ markdown: String) | ||
|
||
func message(_ markdown: String) | ||
|
||
func markdown(_ markdown: String) | ||
|
||
func success(_ markdown: String) | ||
|
||
func hasFails() -> Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.