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

Fix the format and nullable of startDate and dueDate, introducing assignees property to GitLab #381

Merged
merged 14 commits into from
Oct 9, 2020

Conversation

vc7
Copy link
Contributor

@vc7 vc7 commented Oct 6, 2020

startDate and dueDate property

Make them optional

GitLab may produce null value on those two properties.

The date format

The format of dueDate has become yyyy-MM-dd and which cause this error:

ERROR: Failed to parse JSON: dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "danger", intValue: nil), CodingKeys(stringValue: "gitlab", intValue: nil), CodingKeys(stringValue: "mr", intValue: nil), CodingKeys(stringValue: "milestone", intValue: nil), CodingKeys(stringValue: "due_date", intValue: nil)], debugDescription: "Date string does not match format expected by formatter.", underlyingError: nil))

assignees property

The assignees array is exist in the JSON but we don't have a property for that. It is not convenient if some team need to add some rules while they are able to set multiple assignees on merge request.

Reference

@vc7 vc7 changed the title Fix dueDate of MergeRequest and Add assignees property to GitLab Fix dueDate of MergeRequest and introducing assignees property to GitLab Oct 6, 2020
Add tests for the formatter.
Adjust the test related to the format and nullable changes.
@vc7 vc7 changed the title Fix dueDate of MergeRequest and introducing assignees property to GitLab Fix the format and nullable of startDate and dueDate, introducing assignees property to GitLab Oct 6, 2020
@vc7
Copy link
Contributor Author

vc7 commented Oct 6, 2020

@417-72KI Hi, thanks for viewing my pull request. Btw, I have noticed that CI failed due to this change SwiftDocOrg/swift-doc@dc1cac9#diff-37ca2dd15ca0f6b1b49e78db084ef5b9R1 , shall we pump up the the swift tools version or just keep it as it?

@417-72KI
Copy link
Member

417-72KI commented Oct 6, 2020

@vc7
I'm sorry but I can't judge it.
But, I think it should be keeped because of Swift 5.1 compatibility.

@f-meloni
Can I get your opinion?

@f-meloni
Copy link
Member

f-meloni commented Oct 6, 2020

👋
If you merge master in the branch it should solve the problem :)

@vc7
Copy link
Contributor Author

vc7 commented Oct 7, 2020

@f-meloni Hi :)
I just made the branch from the newest master so I was not able to merge the newest master to my branch.
Please let me know if I missed something

@f-meloni
Copy link
Member

f-meloni commented Oct 7, 2020

Let me see if I can merge it for you :)

@f-meloni
Copy link
Member

f-meloni commented Oct 7, 2020

My bad I though I merged fc2e5b2 to master, but is still on an open PR, sorry

Copy link
Member

@f-meloni f-meloni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR, thank you, I have just few minor comments :)

Sources/Danger/Extensions/DateFormatterExtensions.swift Outdated Show resolved Hide resolved
Tests/DangerTests/DateFormatterHandlerTests.swift Outdated Show resolved Hide resolved
Tests/DangerTests/DateFormatterHandlerTests.swift Outdated Show resolved Hide resolved
- Update the Package.resoved (updated by swift build)
@vc7
Copy link
Contributor Author

vc7 commented Oct 8, 2020

(Resolved)

Thanks for the advice!

For the upgrade of the library, it works great on Xcode 12, but the KeyPath syntax seems causing build failures both on my local machine's Xcode 11.0 and couple of CI tasks. Do you have this kind of issue on your side?

And after upgrade the library, I am running into and trying to solve some unexpected test failures related to DiffParser and not able to push right now. The commit d01f6f6

The failure message is as following.

Test case testParsesDiff()
XCTAssertEqual failed: ("[@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+   version = "1.0">
+   <FileRef
+      location = "self:">
+   </FileRef>
+</Workspace>, , @@ -1,7 +0,0 @@-# frozen_string_literal: true
-
-source "https://rubygems.org"
-
-git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
-
-gem "xcpretty-json-formatter", @@ -20,7 +20,8 @@ extension ReportSection {
     init(fromSPM spm: SPMCoverage, fileManager: FileManager) {
         titleText = nil
-        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent) } }
+        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent)
+        } }
     }
 }, @@ -1,8 +1,11 @@ import Foundation
+
+
+
+
 protocol SPMCoverageParsing {
-    static func coverage(spmCoverageFolder: String, files: [String]) throws -> Report
-}
+    static func coverage(spmCoverageFolder: String, files: [String]) throws -> Re
 enum SPMCoverageParser: SPMCoverageParsing {
     enum Errors: Error {
@@ -22,6 +25,10 @@         let coverage = try JSONDecoder().decode(SPMCoverage.self, from: data)
         let filteredCoverage = coverage.filteringFiles(notOn: files)
-        return Report(messages: [], sections: [ReportSection(fromSPM: filteredCoverage, fileManager: fileManager)])
+        if filteredCoverage.data.contains(where: { !$0.files.isEmpty }) {
+            return Report(messages: [], sections: [ReportSection(fromSPM: filteredCoverage, fileManager: fileManager)])
+        } else {
+            return Report(messages: [], sections: [])
+        }
     }
 }, @@ -3,6 +3,8 @@ protocol ShellOutExecuting {
     func execute(command: String) throws -> Data
+
+
 }
 struct ShellOutExecutor: ShellOutExecuting {]") is not equal to ("[@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+   version = "1.0">
+   <FileRef
+      location = "self:">
+   </FileRef>
+</Workspace>, , @@ -1,7 +0,0 @@-# frozen_string_literal: true
-
-source "https://rubygems.org"
-
-git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
-
-gem "xcpretty-json-formatter", @@ -20,7 +20,8 @@ extension ReportSection {
     init(fromSPM spm: SPMCoverage, fileManager: FileManager) {
         titleText = nil
-        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent) } }
+        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent)
+        } }
     }
 }
 , @@ -1,8 +1,11 @@ import Foundation
 
+
+
+
+
 protocol SPMCoverageParsing {
-    static func coverage(spmCoverageFolder: String, files: [String]) throws -> Report
-}
+    static func coverage(spmCoverageFolder: String, files: [String]) throws -> Re
 
 enum SPMCoverageParser: SPMCoverageParsing {
     enum Errors: Error {
@@ -22,6 +25,10 @@         let coverage = try JSONDecoder().decode(SPMCoverage.self, from: data)
         let filteredCoverage = coverage.filteringFiles(notOn: files)
 
-        return Report(messages: [], sections: [ReportSection(fromSPM: filteredCoverage, fileManager: fileManager)])
+        if filteredCoverage.data.contains(where: { !$0.files.isEmpty }) {
+            return Report(messages: [], sections: [ReportSection(fromSPM: filteredCoverage, fileManager: fileManager)])
+        } else {
+            return Report(messages: [], sections: [])
+        }
     }
 }, @@ -3,6 +3,8 @@ 
 protocol ShellOutExecuting {
     func execute(command: String) throws -> Data
+
+
 }
 
 struct ShellOutExecutor: ShellOutExecuting {]")
Test case testChangeTypeForModified()
XCTAssertEqual failed: ("modified(hunks: [@@ -20,7 +20,8 @@ extension ReportSection {
     init(fromSPM spm: SPMCoverage, fileManager: FileManager) {
         titleText = nil
-        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent) } }
+        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent)
+        } }
     }
 }])") is not equal to ("modified(hunks: [@@ -20,7 +20,8 @@ extension ReportSection {
     init(fromSPM spm: SPMCoverage, fileManager: FileManager) {
         titleText = nil
-        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent) } }
+        items = spm.data.flatMap { $0.files.map { ReportFile(fileName: $0.filename.deletingPrefix(fileManager.currentDirectoryPath + "/"), coverage: $0.summary.percent)
+        } }
     }
 }
 ])")
Test case testChangeTypeForRenamed()
XCTAssertEqual failed: ("renamed(oldPath: "Sources/DangerSwiftCoverage/ShellOutExecutor.swift", hunks: [@@ -3,6 +3,8 @@ protocol ShellOutExecuting {
     func execute(command: String) throws -> Data
+
+
 }
 struct ShellOutExecutor: ShellOutExecuting {])") is not equal to ("renamed(oldPath: "Sources/DangerSwiftCoverage/ShellOutExecutor.swift", hunks: [@@ -3,6 +3,8 @@ 
 protocol ShellOutExecuting {
     func execute(command: String) throws -> Data
+
+
 }
 
 struct ShellOutExecutor: ShellOutExecuting {])")

Update

It seems some empty lines are omitted by accident during parseHunks(_:) 's isEmpty filtering

let lines = changes.components(separatedBy: "\n").dropFirst().filter { !$0.isEmpty }.map(parseLine)

But still wonder why this is just came out from no where 🤔 I will keep dig into this see what I can do for this.

Please share your idea if you guys have any 😃

Update

After the investigation, I have find out that swiftformat is cleaning up the trailing whitespacing for us and that causes the test data producing empty lines and leads to the failure of the tests.

@@ -143,6 +143,8 @@ final class GitDiffTests: XCTestCase {
]))
}

// swiftlint:disable all
// swiftformat:disable all
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// swiftlint:disable trailing_whitespace
// swiftformat:disable trimwhitespace

I could't get any effect by using this set of disable so I turn to use all instead in the end.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a look at this separately, probably will just use a swiftformat config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you are right, that might be the better way to solve this kind of issues!

@vc7 vc7 requested review from 417-72KI and f-meloni October 8, 2020 07:03
Copy link
Member

@417-72KI 417-72KI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

waiting for @f-meloni

@vc7
Copy link
Contributor Author

vc7 commented Oct 9, 2020

No code changes at a4fd57f , two link references fixed at CHANGELOG.

@@ -143,6 +143,8 @@ final class GitDiffTests: XCTestCase {
]))
}

// swiftlint:disable all
// swiftformat:disable all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a look at this separately, probably will just use a swiftformat config

@f-meloni f-meloni merged commit 340023c into danger:master Oct 9, 2020
@vc7
Copy link
Contributor Author

vc7 commented Oct 12, 2020

Many thank you guys for the reviews, I have found there are still some issues related to GitLab and I will filing pull requests later on :)

@vc7 vc7 deleted the hotfix/optional_due_date branch October 19, 2020 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants