Skip to content

Commit ad55773

Browse files
author
Mateusz Zajac
committed
Documentation and slight changes in codebase
1 parent 6fe301c commit ad55773

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

XcodeServerSDK/Server Entities/IntegrationCommits.swift

+23-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class IntegrationCommits: XcodeServerEntity {
1515
public let botTinyID: String
1616
public let botID: String
1717
public let commits: [String: [Commit]]
18-
public let endedTimeDate: NSDate
18+
public let endedTimeDate: NSDate?
1919

2020
public required init(json: NSDictionary) {
2121
self.integration = json.stringForKey("integration")
@@ -27,6 +27,13 @@ public class IntegrationCommits: XcodeServerEntity {
2727
super.init(json: json)
2828
}
2929

30+
/**
31+
Method for populating commits property with data from JSON dictionary.
32+
33+
- parameter json: JSON dictionary with blueprints and commits for each one.
34+
35+
- returns: Dictionary of parsed Commit objects.
36+
*/
3037
class func populateCommits(json: NSDictionary) -> [String: [Commit]] {
3138
var resultsDictionary: [String: [Commit]] = Dictionary()
3239

@@ -42,17 +49,25 @@ public class IntegrationCommits: XcodeServerEntity {
4249
return resultsDictionary
4350
}
4451

45-
class func parseDate(array: NSArray) -> NSDate {
46-
let dateArray = array as! [Int]
52+
/**
53+
Parser for data objects which comes in form of array.
54+
55+
- parameter array: Array with date components.
56+
57+
- returns: Optional parsed date to the format used by Xcode Server.
58+
*/
59+
class func parseDate(array: NSArray) -> NSDate? {
60+
guard let dateArray = array as? [Int] else {
61+
Log.error("Couldn't parse XCS date array")
62+
return nil
63+
}
4764

4865
do {
4966
let stringDate = try dateArray.dateString()
50-
let formatter = NSDateFormatter()
51-
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ"
5267

53-
guard let date = formatter.dateFromString(stringDate) else {
68+
guard let date = NSDate.dateFromXCSString(stringDate) else {
5469
Log.error("Formatter couldn't parse date")
55-
return NSDate()
70+
return nil
5671
}
5772

5873
return date
@@ -62,7 +77,7 @@ public class IntegrationCommits: XcodeServerEntity {
6277
Log.error("Something went wrong while parsing date")
6378
}
6479

65-
return NSDate()
80+
return nil
6681
}
6782

6883
}

XcodeServerSDKTests/IntegrationTests.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class IntegrationTests: XCTestCase {
4545
}
4646

4747
// Casette assertions
48-
XCTAssertEqual(integrationCommits.endedTimeDate, self.expectedDate)
48+
if let expectationDate = integrationCommits.endedTimeDate {
49+
XCTAssertEqual(expectationDate, self.expectedDate)
50+
}
4951

5052
guard let commits = integrationCommits.commits["A36AEFA3F9FF1F738E92F0C497C14977DCE02B97"] else {
5153
XCTFail("Commits dictionary is empty but should have one key")

0 commit comments

Comments
 (0)