-
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 #1 from yumemi/feature/initial
Feature/initial
- Loading branch information
Showing
9 changed files
with
504 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,52 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Logger", | ||
"repositoryURL": "https://github.com/shibapm/Logger", | ||
"state": { | ||
"branch": null, | ||
"revision": "53c3ecca5abe8cf46697e33901ee774236d94cce", | ||
"version": "0.2.3" | ||
} | ||
}, | ||
{ | ||
"package": "OctoKit", | ||
"repositoryURL": "https://github.com/nerdishbynature/octokit.swift", | ||
"state": { | ||
"branch": null, | ||
"revision": "9521cdff919053868ab13cd08a228f7bc1bde2a9", | ||
"version": "0.11.0" | ||
} | ||
}, | ||
{ | ||
"package": "RequestKit", | ||
"repositoryURL": "https://github.com/nerdishbynature/RequestKit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "fd5e9e99aada7432170366c9e95967011ce13bad", | ||
"version": "2.4.0" | ||
} | ||
}, | ||
{ | ||
"package": "danger-swift", | ||
"repositoryURL": "https://github.com/danger/swift.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "15819a13a5e8e154acdc2eeec5f94ed37369d7cc", | ||
"version": "3.12.2" | ||
} | ||
}, | ||
{ | ||
"package": "Version", | ||
"repositoryURL": "https://github.com/mxcl/Version", | ||
"state": { | ||
"branch": null, | ||
"revision": "200046c93f6d5d78a6d72bfd9c0b27a95e9c0a2b", | ||
"version": "1.2.0" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
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,29 @@ | ||
// swift-tools-version:5.3 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "DangerSwiftShoki", | ||
products: [ | ||
// Products define the executables and libraries produced by a package, and make them visible to other packages. | ||
.library( | ||
name: "DangerSwiftShoki", | ||
targets: ["DangerSwiftShoki"]), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
.package(name: "danger-swift", url: "https://github.com/danger/swift.git", from: "3.0.0"), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages which this package depends on. | ||
.target( | ||
name: "DangerSwiftShoki", | ||
dependencies: [.product(name: "Danger", package: "danger-swift")]), | ||
.testTarget( | ||
name: "DangerSwiftShokiTests", | ||
dependencies: ["DangerSwiftShoki"]), | ||
] | ||
) |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# DangerSwiftYUMEMI | ||
社内向けDangerSwift用のプラグイン | ||
# DangerSwiftShoki | ||
|
||
A danger-swift plug-in to describe danger checking results with markdown style |
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,103 @@ | ||
// | ||
// CheckResult.swift | ||
// | ||
// | ||
// Created by 史 翔新 on 2020/07/11. | ||
// | ||
|
||
public struct CheckResult { | ||
|
||
public enum Result { | ||
|
||
case good | ||
case acceptable | ||
case rejected | ||
|
||
var markdownSymbol: String { | ||
switch self { | ||
case .good: | ||
return ":tada:" | ||
|
||
case .acceptable: | ||
return ":thinking:" | ||
|
||
case .rejected: | ||
return ":no_good:" | ||
} | ||
} | ||
|
||
} | ||
|
||
typealias Message = (content: String, result: Result) | ||
|
||
public let title: String | ||
|
||
private var messages: [Message] = [] | ||
|
||
private var todos: [String] = [] | ||
|
||
public var warningsCount: Int { | ||
messages.filter({ $0.result == .acceptable }).count | ||
} | ||
|
||
public var errorsCount: Int { | ||
messages.filter({ $0.result == .rejected }).count | ||
} | ||
|
||
public init(title: String) { | ||
self.title = title | ||
} | ||
|
||
public mutating func askReviewer(to taskToDo: String) { | ||
|
||
todos.append(taskToDo) | ||
|
||
} | ||
|
||
public mutating func check(_ item: String, execution: () -> Result) { | ||
|
||
let result = execution() | ||
messages.append((item, result)) | ||
|
||
} | ||
|
||
public var markdownTitle: String { | ||
|
||
"## " + title | ||
|
||
} | ||
|
||
public var markdownMessage: String { | ||
|
||
guard !messages.isEmpty else { | ||
return "" | ||
} | ||
|
||
let chartHeader = """ | ||
Checking Item | Result | ||
| ---| --- | | ||
""" | ||
let chartContent = messages.map { | ||
"\($0.content) | \($0.result.markdownSymbol)" | ||
} .joined(separator: "\n") | ||
|
||
return chartHeader + chartContent | ||
|
||
} | ||
|
||
public var markdownTodos: String { | ||
|
||
guard !todos.isEmpty else { | ||
return "" | ||
} | ||
|
||
let todoContent = todos.map { | ||
"- [ ] \($0)" | ||
} | ||
|
||
return todoContent.joined(separator: "\n") | ||
|
||
} | ||
|
||
} |
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,17 @@ | ||
// | ||
// DangerDSL+.swift | ||
// | ||
// | ||
// Created by 史 翔新 on 2021/11/13. | ||
// | ||
|
||
import Danger | ||
|
||
extension DangerDSL { | ||
|
||
public var shoki: Shoki { | ||
return .init(markdownExecutor: { markdown($0) }, | ||
messageExecutor: { message($0) }) | ||
} | ||
|
||
} |
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,58 @@ | ||
// | ||
// Shoki.swift | ||
// | ||
// | ||
// Created by 史 翔新 on 2021/11/16. | ||
// | ||
|
||
import Danger | ||
|
||
public struct Shoki { | ||
|
||
private let markdownExecutor: (String) -> Void | ||
private let messageExecutor: (String) -> Void | ||
|
||
init( | ||
markdownExecutor: @escaping (String) -> Void, | ||
messageExecutor: @escaping (String) -> Void | ||
) { | ||
self.markdownExecutor = markdownExecutor | ||
self.messageExecutor = messageExecutor | ||
} | ||
|
||
} | ||
|
||
extension Shoki { | ||
|
||
func markdown(_ message: String) { | ||
markdownExecutor(message) | ||
} | ||
|
||
func message(_ message: String) { | ||
messageExecutor(message) | ||
} | ||
|
||
} | ||
|
||
extension Shoki { | ||
|
||
public func report(_ result: CheckResult) { | ||
|
||
markdown(result.markdownTitle) | ||
|
||
if !result.markdownMessage.isEmpty { | ||
markdown(result.markdownMessage) | ||
|
||
} | ||
|
||
if !result.markdownTodos.isEmpty { | ||
markdown(result.markdownTodos) | ||
} | ||
|
||
if result.warningsCount == 0 && result.errorsCount == 0 { | ||
message("Good Job :white_flower:") | ||
} | ||
|
||
} | ||
|
||
} |
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,108 @@ | ||
import XCTest | ||
@testable import DangerSwiftShoki | ||
|
||
final class CheckResultTests: XCTestCase { | ||
|
||
func test_checkResultLife() { | ||
|
||
var checkResult = CheckResult(title: "Test Check") | ||
|
||
XCTContext.runActivity(named: "Initialize CheckResult") { _ in | ||
XCTAssertEqual(checkResult.title, "Test Check") | ||
XCTAssertEqual(checkResult.warningsCount, 0) | ||
XCTAssertEqual(checkResult.errorsCount, 0) | ||
XCTAssertEqual(checkResult.markdownTitle, "## Test Check") | ||
XCTAssertEqual(checkResult.markdownMessage, """ | ||
""") | ||
XCTAssertEqual(checkResult.markdownTodos, """ | ||
""") | ||
} | ||
|
||
XCTContext.runActivity(named: "Add Check Item with Good Result") { _ in | ||
checkResult.check("Good Check", execution: { .good }) | ||
XCTAssertEqual(checkResult.title, "Test Check") | ||
XCTAssertEqual(checkResult.warningsCount, 0) | ||
XCTAssertEqual(checkResult.errorsCount, 0) | ||
XCTAssertEqual(checkResult.markdownTitle, "## Test Check") | ||
XCTAssertEqual(checkResult.markdownMessage, """ | ||
Checking Item | Result | ||
| ---| --- | | ||
Good Check | :tada: | ||
""") | ||
XCTAssertEqual(checkResult.markdownTodos, """ | ||
""") | ||
} | ||
|
||
XCTContext.runActivity(named: "Add Check Item with Acceptable Result") { _ in | ||
checkResult.check("Acceptable Check", execution: { .acceptable }) | ||
XCTAssertEqual(checkResult.title, "Test Check") | ||
XCTAssertEqual(checkResult.warningsCount, 1) | ||
XCTAssertEqual(checkResult.errorsCount, 0) | ||
XCTAssertEqual(checkResult.markdownTitle, "## Test Check") | ||
XCTAssertEqual(checkResult.markdownMessage, """ | ||
Checking Item | Result | ||
| ---| --- | | ||
Good Check | :tada: | ||
Acceptable Check | :thinking: | ||
""") | ||
XCTAssertEqual(checkResult.markdownTodos, """ | ||
""") | ||
} | ||
|
||
XCTContext.runActivity(named: "Add Check Item with Rejected Result") { _ in | ||
checkResult.check("Rejected Check", execution: { .rejected }) | ||
XCTAssertEqual(checkResult.title, "Test Check") | ||
XCTAssertEqual(checkResult.warningsCount, 1) | ||
XCTAssertEqual(checkResult.errorsCount, 1) | ||
XCTAssertEqual(checkResult.markdownTitle, "## Test Check") | ||
XCTAssertEqual(checkResult.markdownMessage, """ | ||
Checking Item | Result | ||
| ---| --- | | ||
Good Check | :tada: | ||
Acceptable Check | :thinking: | ||
Rejected Check | :no_good: | ||
""") | ||
XCTAssertEqual(checkResult.markdownTodos, """ | ||
""") | ||
} | ||
|
||
XCTContext.runActivity(named: "Add A Todo Item") { _ in | ||
checkResult.askReviewer(to: "Do Something") | ||
XCTAssertEqual(checkResult.title, "Test Check") | ||
XCTAssertEqual(checkResult.warningsCount, 1) | ||
XCTAssertEqual(checkResult.errorsCount, 1) | ||
XCTAssertEqual(checkResult.markdownTitle, "## Test Check") | ||
XCTAssertEqual(checkResult.markdownMessage, """ | ||
Checking Item | Result | ||
| ---| --- | | ||
Good Check | :tada: | ||
Acceptable Check | :thinking: | ||
Rejected Check | :no_good: | ||
""") | ||
XCTAssertEqual(checkResult.markdownTodos, """ | ||
- [ ] Do Something | ||
""") | ||
} | ||
|
||
XCTContext.runActivity(named: "Add Another Todo Item") { _ in | ||
checkResult.askReviewer(to: "Do Another Thing") | ||
XCTAssertEqual(checkResult.title, "Test Check") | ||
XCTAssertEqual(checkResult.warningsCount, 1) | ||
XCTAssertEqual(checkResult.errorsCount, 1) | ||
XCTAssertEqual(checkResult.markdownTitle, "## Test Check") | ||
XCTAssertEqual(checkResult.markdownMessage, """ | ||
Checking Item | Result | ||
| ---| --- | | ||
Good Check | :tada: | ||
Acceptable Check | :thinking: | ||
Rejected Check | :no_good: | ||
""") | ||
XCTAssertEqual(checkResult.markdownTodos, """ | ||
- [ ] Do Something | ||
- [ ] Do Another Thing | ||
""") | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.