From 8e8180bc909c5824da11d8d436892abc1b01fdb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Sun, 28 Jun 2015 17:43:17 +0200 Subject: [PATCH 01/11] Add retrieve integration API call --- XcodeServerSDK/XcodeServer.swift | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index d53f72f..39497d2 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -322,6 +322,38 @@ public extension XcodeServer { } } + /** + XCS API call for retrievieng specified Integration. + + - parameter integrationId: ID of integration which is about to be retrieved. + - parameter completion: + - Optional retrieved integration. + - Optional operation error. + */ + public func retrieveIntegration(integrationId: String, completion: (integration: Integration?, error: NSError?) -> ()) { + + let params = [ + "integration": integrationId + ] + + self.sendRequestWithMethod(.GET, endpoint: .Integrations, params: params, query: nil, body: nil) { + (response, body, error) -> () in + + guard error == nil else { + completion(integration: nil, error: error) + return + } + + guard let integrationBody = body as? NSDictionary else { + completion(integration: nil, error: Error.withInfo("Wrong body \(body)")) + return + } + + let integration = Integration(json: integrationBody) + completion(integration: integration, error: nil) + } + } + public func cancelIntegration(integrationId: String, completion: (success: Bool, error: NSError?) -> ()) { let params = [ From 1cc90e93c838926c8f1ec363de43eb529ee7313b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Sun, 28 Jun 2015 18:15:04 +0200 Subject: [PATCH 02/11] Add all integrations fetch API call --- XcodeServerSDK/XcodeServer.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index 39497d2..20f164a 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -371,6 +371,32 @@ public extension XcodeServer { } } + /** + XCS API call for retrievieng all available integrations on server. + + - parameter integrations: Optional array of integrations. + - parameter error: Optional error. + */ + public func getIntegrations(completion: (integrations: [Integration]?, error: NSError?) -> ()) { + + self.sendRequestWithMethod(.GET, endpoint: .Integrations, params: nil, query: nil, body: nil) { + (response, body, error) -> () in + + guard error == nil else { + completion(integrations: nil, error: error) + return + } + + guard let integrationsBody = (body as? NSDictionary)?["results"] as? NSArray else { + completion(integrations: nil, error: Error.withInfo("Wrong body \(body)")) + return + } + + let integrations: [Integration] = XcodeServerArray(integrationsBody) + completion(integrations: integrations, error: nil) + } + } + public func getDevices(completion: (devices: [Device]?, error: NSError?) -> ()) { self.sendRequestWithMethod(.GET, endpoint: .Devices, params: nil, query: nil, body: nil) { (response, body, error) -> () in From fd4b5017e24320472728c56f057c9592b6413916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Sun, 28 Jun 2015 18:18:26 +0200 Subject: [PATCH 03/11] Hot fix - name change --- XcodeServerSDK/XcodeServer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index 20f164a..283733a 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -330,7 +330,7 @@ public extension XcodeServer { - Optional retrieved integration. - Optional operation error. */ - public func retrieveIntegration(integrationId: String, completion: (integration: Integration?, error: NSError?) -> ()) { + public func getIntegration(integrationId: String, completion: (integration: Integration?, error: NSError?) -> ()) { let params = [ "integration": integrationId From 2e39feb1b639bd1d86122ec71bf793275c04f9dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Sun, 28 Jun 2015 18:18:26 +0200 Subject: [PATCH 04/11] Hot fix - name change --- XcodeServerSDK/XcodeServer.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index 20f164a..0340b90 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -273,7 +273,7 @@ public extension XcodeServer { } } - public func getIntegrations(botId: String, query: [String: String], completion: (integrations: [Integration]?, error: NSError?) -> ()) { + public func getBotIntegrations(botId: String, query: [String: String], completion: (integrations: [Integration]?, error: NSError?) -> ()) { let params = [ "bot": botId @@ -330,7 +330,7 @@ public extension XcodeServer { - Optional retrieved integration. - Optional operation error. */ - public func retrieveIntegration(integrationId: String, completion: (integration: Integration?, error: NSError?) -> ()) { + public func getIntegration(integrationId: String, completion: (integration: Integration?, error: NSError?) -> ()) { let params = [ "integration": integrationId From 2e9825babb9fbffaf8f234a6d14136dbd5b08dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Mon, 29 Jun 2015 00:49:36 +0200 Subject: [PATCH 05/11] Create Repository struct --- XcodeServerSDK.xcodeproj/project.pbxproj | 14 +++ .../Server Entities/Repository.swift | 103 ++++++++++++++++++ XcodeServerSDK/XcodeServerEndpoints.swift | 6 + XcodeServerSDKTests/RepositoryTests.swift | 46 ++++++++ 4 files changed, 169 insertions(+) create mode 100644 XcodeServerSDK/Server Entities/Repository.swift create mode 100644 XcodeServerSDKTests/RepositoryTests.swift diff --git a/XcodeServerSDK.xcodeproj/project.pbxproj b/XcodeServerSDK.xcodeproj/project.pbxproj index 285858c..bf3c86c 100644 --- a/XcodeServerSDK.xcodeproj/project.pbxproj +++ b/XcodeServerSDK.xcodeproj/project.pbxproj @@ -106,6 +106,9 @@ 3AA922BA1B3F4666005A0F73 /* DVR.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AA922AC1B3F4630005A0F73 /* DVR.framework */; }; 3ABE68661B3AC3C500FA0A61 /* DeviceSpecification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABE68651B3AC3C500FA0A61 /* DeviceSpecification.swift */; }; 3ABE68671B3AC3C500FA0A61 /* DeviceSpecification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABE68651B3AC3C500FA0A61 /* DeviceSpecification.swift */; }; + 7045917F1B4074CC00BA226C /* Repository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7045917E1B4074CC00BA226C /* Repository.swift */; }; + 704591861B40945700BA226C /* RepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 704591851B40945700BA226C /* RepositoryTests.swift */; }; + 704591871B40945E00BA226C /* RepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 704591851B40945700BA226C /* RepositoryTests.swift */; }; 705D59A11B3AE502002521BA /* HTTPUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D59A01B3AE502002521BA /* HTTPUtilsTests.swift */; }; 707D08961B2C684C003900F3 /* XcodeServerConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 707D08951B2C684C003900F3 /* XcodeServerConfig.swift */; }; 707D08981B2C6954003900F3 /* EmailConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 707D08971B2C6954003900F3 /* EmailConfiguration.swift */; }; @@ -115,6 +118,8 @@ 709ED67C1B35FD3F00A06038 /* XcodeServerEntityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 709ED67B1B35FD3F00A06038 /* XcodeServerEntityTests.swift */; }; 709ED6801B3608FC00A06038 /* XcodeServerConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 709ED67F1B3608FC00A06038 /* XcodeServerConfigTests.swift */; }; 70B21FF81B3AFB1D00EAD4EB /* BotConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B21FF71B3AFB1D00EAD4EB /* BotConfigurationTests.swift */; }; + 70E1413A1B409EA000AC98DB /* Repository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7045917E1B4074CC00BA226C /* Repository.swift */; }; + 70E1413B1B409EA100AC98DB /* Repository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7045917E1B4074CC00BA226C /* Repository.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -226,6 +231,8 @@ 3AA9223D1B3F0E2C005A0F73 /* scm_branches_response_error.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = scm_branches_response_error.json; path = Data/scm_branches_response_error.json; sourceTree = ""; }; 3AA922A31B3F4630005A0F73 /* DVR.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = DVR.xcodeproj; path = Carthage/Checkouts/DVR/DVR.xcodeproj; sourceTree = ""; }; 3ABE68651B3AC3C500FA0A61 /* DeviceSpecification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSpecification.swift; sourceTree = ""; }; + 7045917E1B4074CC00BA226C /* Repository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Repository.swift; sourceTree = ""; }; + 704591851B40945700BA226C /* RepositoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryTests.swift; sourceTree = ""; }; 705D59A01B3AE502002521BA /* HTTPUtilsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPUtilsTests.swift; sourceTree = ""; }; 707D08951B2C684C003900F3 /* XcodeServerConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeServerConfig.swift; sourceTree = ""; }; 707D08971B2C6954003900F3 /* EmailConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailConfiguration.swift; sourceTree = ""; }; @@ -366,6 +373,7 @@ 3A058A921B315BB50077FD47 /* TestUtils.swift */, 705D59A01B3AE502002521BA /* HTTPUtilsTests.swift */, 70B21FF71B3AFB1D00EAD4EB /* BotConfigurationTests.swift */, + 704591851B40945700BA226C /* RepositoryTests.swift */, 3A7B48CA1B2A5AC40077ABEA /* Supporting Files */, ); path = XcodeServerSDKTests; @@ -421,6 +429,7 @@ 3A7B48DB1B2A5ADE0077ABEA /* SourceControlBlueprint.swift */, 707D089B1B2C69C4003900F3 /* Trigger.swift */, 707D089D1B2C6A1F003900F3 /* TriggerConditions.swift */, + 7045917E1B4074CC00BA226C /* Repository.swift */, ); path = "Server Entities"; sourceTree = ""; @@ -741,6 +750,7 @@ 11376BE71B3A2FEB0005A681 /* Errors.swift in Sources */, 11376BE81B3A2FEB0005A681 /* Server.swift in Sources */, 11376BE91B3A2FEB0005A681 /* XcodeServerConstants.swift in Sources */, + 70E1413A1B409EA000AC98DB /* Repository.swift in Sources */, 11376BE01B3A2FE30005A681 /* BotSchedule.swift in Sources */, 11376BE11B3A2FE30005A681 /* Trigger.swift in Sources */, 11376BE21B3A2FE30005A681 /* TriggerConditions.swift in Sources */, @@ -771,6 +781,7 @@ 11FB71A81B34AF2400D57A52 /* BotConfiguration.swift in Sources */, 11FB71A91B34AF2400D57A52 /* EmailConfiguration.swift in Sources */, 11FB71AA1B34AF2400D57A52 /* BotSchedule.swift in Sources */, + 70E1413B1B409EA100AC98DB /* Repository.swift in Sources */, 3ABE68671B3AC3C500FA0A61 /* DeviceSpecification.swift in Sources */, 11FB71AB1B34AF2400D57A52 /* Trigger.swift in Sources */, 11FB71AC1B34AF2400D57A52 /* TriggerConditions.swift in Sources */, @@ -793,6 +804,7 @@ 11FB71B81B34B00000D57A52 /* XcodeServerTests.swift in Sources */, 3A06D5FF1B3C184D00F0A6C5 /* HTTPUtilsTests.swift in Sources */, 3A06D5FD1B3C184400F0A6C5 /* XcodeServerEntityTests.swift in Sources */, + 704591871B40945E00BA226C /* RepositoryTests.swift in Sources */, 11FB71B91B34B00000D57A52 /* BotParsingTests.swift in Sources */, 11FB71BA1B34B00000D57A52 /* TestUtils.swift in Sources */, 3A06D5FE1B3C184700F0A6C5 /* XcodeServerConfigTests.swift in Sources */, @@ -815,6 +827,7 @@ 707D089C1B2C69C4003900F3 /* Trigger.swift in Sources */, 3A7B48E21B2A5ADE0077ABEA /* BotConfiguration.swift in Sources */, 3A7B48EA1B2A5ADE0077ABEA /* XcodeServerEntity.swift in Sources */, + 7045917F1B4074CC00BA226C /* Repository.swift in Sources */, 3ABE68661B3AC3C500FA0A61 /* DeviceSpecification.swift in Sources */, 707D08961B2C684C003900F3 /* XcodeServerConfig.swift in Sources */, 3A7B48EB1B2A5ADE0077ABEA /* XcodeServerFactory.swift in Sources */, @@ -837,6 +850,7 @@ 3A058A8E1B31595A0077FD47 /* BotParsingTests.swift in Sources */, 705D59A11B3AE502002521BA /* HTTPUtilsTests.swift in Sources */, 709ED67C1B35FD3F00A06038 /* XcodeServerEntityTests.swift in Sources */, + 704591861B40945700BA226C /* RepositoryTests.swift in Sources */, 3A058A931B315BB50077FD47 /* TestUtils.swift in Sources */, 3A7B48CD1B2A5AC40077ABEA /* XcodeServerTests.swift in Sources */, 709ED6801B3608FC00A06038 /* XcodeServerConfigTests.swift in Sources */, diff --git a/XcodeServerSDK/Server Entities/Repository.swift b/XcodeServerSDK/Server Entities/Repository.swift new file mode 100644 index 0000000..a374f32 --- /dev/null +++ b/XcodeServerSDK/Server Entities/Repository.swift @@ -0,0 +1,103 @@ +// +// Repository.swift +// XcodeServerSDK +// +// Created by Mateusz Zając on 28.06.2015. +// Copyright © 2015 Honza Dvorsky. All rights reserved. +// + +import Foundation + +public struct Repository { + + /** + Enumeration describing HTTP access to the repository + + - None: No users are not allowed to read or write + - LoggedIn: Logged in users are allowed to read and write + */ + public enum HTTPAccessType: Int { + + case None = 0 + case LoggedIn + + public func toString() -> String { + switch self { + case .None: + return "No users are not allowed to read or write" + case .LoggedIn: + return "Logged in users are allowed to read and write" + } + } + + } + + /** + Enumeration describing HTTPS access to the repository + + - SelectedReadWrite: Only selected users can read and/or write + - LoggedInReadSelectedWrite: Only selected users can write but all logged in can read + - LoggedInReadWrite: All logged in users can read and write + */ + public enum SSHAccessType: Int { + + case SelectedReadWrite = 0 + case LoggedInReadSelectedWrite + case LoggedInReadWrite + + public func toString() -> String { + switch self { + case .SelectedReadWrite: + return "Only selected users can read and/or write" + case .LoggedInReadSelectedWrite: + return "Only selected users can write but all logged in can read" + case .LoggedInReadWrite: + return "All logged in users can read and write" + } + } + + } + + public let name: String + public let httpAccess: HTTPAccessType + public let sshAccess: SSHAccessType + public let writeAccessExternalIds: [String] + public let readAccessExternalIds: [String] + + /** + Designated initializer. + + - parameter name: Name of the repository. + - parameter httpsAccess: HTTPS access type for the users. + - parameter sshAccess: SSH access type for the users. + - parameter writeAccessExternalIds: ID of users allowed to write to the repository. + - parameter readAccessExternalIds: ID of users allowed to read from the repository. + + - returns: Initialized repository struct. + */ + public init(name: String, httpAccess: HTTPAccessType, sshAccess: SSHAccessType, writeAccessExternalIds: [String], readAccessExternalIds: [String]) { + self.name = name + self.httpAccess = httpAccess + self.sshAccess = sshAccess + self.writeAccessExternalIds = writeAccessExternalIds + self.readAccessExternalIds = readAccessExternalIds + } + + /** + Repository constructor from JSON object. + + - parameter json: JSON dictionary representing repository. + + - returns: Initialized repository struct. + */ + public init(json: NSDictionary) { + self.name = json.stringForKey("name") + + self.httpAccess = HTTPAccessType(rawValue: json.intForKey("httpAccessType"))! + self.sshAccess = SSHAccessType(rawValue: json.intForKey("posixPermissions"))! + + self.writeAccessExternalIds = json.arrayForKey("writeAccessExternalIDs") + self.readAccessExternalIds = json.arrayForKey("readAccessExternalIDs") + } + +} \ No newline at end of file diff --git a/XcodeServerSDK/XcodeServerEndpoints.swift b/XcodeServerSDK/XcodeServerEndpoints.swift index 12498e2..fd235a4 100644 --- a/XcodeServerSDK/XcodeServerEndpoints.swift +++ b/XcodeServerSDK/XcodeServerEndpoints.swift @@ -20,6 +20,7 @@ public class XcodeServerEndPoints { case Logout case Platforms case SCM_Branches + case Repositories } let serverConfig: XcodeServerConfig @@ -106,6 +107,11 @@ public class XcodeServerEndPoints { let branches = "\(base)/scm/branches" return branches + case .Repositories: + + let repositories = "\(base)/repositories" + return repositories + } } diff --git a/XcodeServerSDKTests/RepositoryTests.swift b/XcodeServerSDKTests/RepositoryTests.swift new file mode 100644 index 0000000..f143b88 --- /dev/null +++ b/XcodeServerSDKTests/RepositoryTests.swift @@ -0,0 +1,46 @@ +// +// Repository.swift +// XcodeServerSDK +// +// Created by Mateusz Zając on 28.06.2015. +// Copyright © 2015 Honza Dvorsky. All rights reserved. +// + +import XCTest +import XcodeServerSDK + +class RepositoryTests: XCTestCase { + + let json = [ + "readAccessExternalIDs": [], + "writeAccessExternalIDs": [ + "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", + "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" + ], + "name": "Test3", + "posixPermissions": 1, + "httpAccessType": 1 + ] + + // MARK: Initialization + func testInit() { + let repo = Repository(json: json) + + XCTAssertEqual(repo.name, "Test3") + XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.LoggedIn) + XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.LoggedInReadSelectedWrite) + XCTAssertEqual(repo.writeAccessExternalIds, [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ]) + XCTAssertEqual(repo.readAccessExternalIds, []) + } + + func testManualInit() { + let repo = Repository(name: "Test3", httpAccess: .LoggedIn, sshAccess: .LoggedInReadSelectedWrite, writeAccessExternalIds: [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ], readAccessExternalIds: []) + + XCTAssertEqual(repo.name, "Test3") + XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.LoggedIn) + XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.LoggedInReadSelectedWrite) + XCTAssertEqual(repo.writeAccessExternalIds, [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ]) + XCTAssertEqual(repo.readAccessExternalIds, []) + } + +} From 0aa2e8ef0c539cfc7a3548b84d6f26b4b95ef2c9 Mon Sep 17 00:00:00 2001 From: Mateusz Zajac Date: Mon, 29 Jun 2015 08:10:31 +0200 Subject: [PATCH 06/11] Add all repositories fetching method Also, deleted duplication from .pbxproj file --- XcodeServerSDK.xcodeproj/project.pbxproj | 1 - .../Server Entities/Repository.swift | 4 ++-- XcodeServerSDK/XcodeServer.swift | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/XcodeServerSDK.xcodeproj/project.pbxproj b/XcodeServerSDK.xcodeproj/project.pbxproj index bf3c86c..cd748e3 100644 --- a/XcodeServerSDK.xcodeproj/project.pbxproj +++ b/XcodeServerSDK.xcodeproj/project.pbxproj @@ -108,7 +108,6 @@ 3ABE68671B3AC3C500FA0A61 /* DeviceSpecification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABE68651B3AC3C500FA0A61 /* DeviceSpecification.swift */; }; 7045917F1B4074CC00BA226C /* Repository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7045917E1B4074CC00BA226C /* Repository.swift */; }; 704591861B40945700BA226C /* RepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 704591851B40945700BA226C /* RepositoryTests.swift */; }; - 704591871B40945E00BA226C /* RepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 704591851B40945700BA226C /* RepositoryTests.swift */; }; 705D59A11B3AE502002521BA /* HTTPUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705D59A01B3AE502002521BA /* HTTPUtilsTests.swift */; }; 707D08961B2C684C003900F3 /* XcodeServerConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 707D08951B2C684C003900F3 /* XcodeServerConfig.swift */; }; 707D08981B2C6954003900F3 /* EmailConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 707D08971B2C6954003900F3 /* EmailConfiguration.swift */; }; diff --git a/XcodeServerSDK/Server Entities/Repository.swift b/XcodeServerSDK/Server Entities/Repository.swift index a374f32..24901c8 100644 --- a/XcodeServerSDK/Server Entities/Repository.swift +++ b/XcodeServerSDK/Server Entities/Repository.swift @@ -8,7 +8,7 @@ import Foundation -public struct Repository { +public class Repository: XcodeRead { /** Enumeration describing HTTP access to the repository @@ -90,7 +90,7 @@ public struct Repository { - returns: Initialized repository struct. */ - public init(json: NSDictionary) { + public required init(json: NSDictionary) { self.name = json.stringForKey("name") self.httpAccess = HTTPAccessType(rawValue: json.intForKey("httpAccessType"))! diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index 1a6b77a..7b3e2e4 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -530,6 +530,30 @@ public extension XcodeServer { } } + /** + XCS API call for getting all repositories stored on Xcode Server. + + - parameter repositories: Optional array of repositories. + - parameter error: Optional error + */ + public func getRepositories(completion: (repositories: [Repository]?, error: NSError?) -> ()) { + + self.sendRequestWithMethod(.GET, endpoint: .Repositories, params: nil, query: nil, body: nil) { (response, body, error) -> () in + guard error == nil else { + completion(repositories: nil, error: error) + return + } + + guard let repositoriesBody = (body as? NSDictionary)?["results"] as? NSArray else { + completion(repositories: nil, error: Error.withInfo("Wrong body \(body)")) + return + } + + let repos: [Repository] = XcodeServerArray(repositoriesBody) + completion(repositories: repos, error: nil) + } + } + //more advanced /** From 5ee13eec7df469176a304679ed83fe3a102e39a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Mon, 29 Jun 2015 13:45:29 +0200 Subject: [PATCH 07/11] Add convenience initializer and default values --- .../Server Entities/Repository.swift | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/XcodeServerSDK/Server Entities/Repository.swift b/XcodeServerSDK/Server Entities/Repository.swift index 24901c8..704e2c9 100644 --- a/XcodeServerSDK/Server Entities/Repository.swift +++ b/XcodeServerSDK/Server Entities/Repository.swift @@ -59,10 +59,10 @@ public class Repository: XcodeRead { } public let name: String - public let httpAccess: HTTPAccessType - public let sshAccess: SSHAccessType - public let writeAccessExternalIds: [String] - public let readAccessExternalIds: [String] + public var httpAccess: HTTPAccessType = HTTPAccessType.None + public var sshAccess: SSHAccessType = SSHAccessType.SelectedReadWrite + public var writeAccessExternalIds: [String] = [] + public var readAccessExternalIds: [String] = [] /** Designated initializer. @@ -75,12 +75,40 @@ public class Repository: XcodeRead { - returns: Initialized repository struct. */ - public init(name: String, httpAccess: HTTPAccessType, sshAccess: SSHAccessType, writeAccessExternalIds: [String], readAccessExternalIds: [String]) { + public init(name: String, httpAccess: HTTPAccessType?, sshAccess: SSHAccessType?, writeAccessExternalIds: [String]?, readAccessExternalIds: [String]?) { self.name = name - self.httpAccess = httpAccess - self.sshAccess = sshAccess - self.writeAccessExternalIds = writeAccessExternalIds - self.readAccessExternalIds = readAccessExternalIds + + if let httpAccess = httpAccess { + self.httpAccess = httpAccess + } + + if let sshAccess = sshAccess { + self.sshAccess = sshAccess + } + + if let writeIDs = writeAccessExternalIds { + self.writeAccessExternalIds = writeIDs + } + + if let readIDs = readAccessExternalIds { + self.readAccessExternalIds = readIDs + } + } + + /** + Convenience initializer. + This initializer will only allow you to provie name and will create a + deault repository with values set to: + - **HTTP Access** - No user is allowed to read/write to repository + - **SSH Access** - Only selected users are allowed to read/write to repository + - **Empty arrays** of write and rad external IDs + + - parameter name: Name of the repository. + + - returns: Initialized default repository wwith provided name + */ + public convenience init(name: String) { + self.init(name: name, httpAccess: nil, sshAccess: nil, writeAccessExternalIds: nil, readAccessExternalIds: nil) } /** From ca9e64d3fb565f75c2ca6148897f362c84dac4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Mon, 29 Jun 2015 14:49:07 +0200 Subject: [PATCH 08/11] Add API call for creating repo and add test cases --- .../Server Entities/Repository.swift | 17 +++++++ XcodeServerSDK/XcodeServer.swift | 40 +++++++++++++++++ XcodeServerSDKTests/RepositoryTests.swift | 45 +++++++++++++++++-- 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/XcodeServerSDK/Server Entities/Repository.swift b/XcodeServerSDK/Server Entities/Repository.swift index 704e2c9..6c1a9e3 100644 --- a/XcodeServerSDK/Server Entities/Repository.swift +++ b/XcodeServerSDK/Server Entities/Repository.swift @@ -128,4 +128,21 @@ public class Repository: XcodeRead { self.readAccessExternalIds = json.arrayForKey("readAccessExternalIDs") } + /** + Method for returning object in form of Dictionary. + + - returns: Dictionary representing JSON value of Repository object. + */ + public func dictionarify() -> NSMutableDictionary { + let dict = NSMutableDictionary() + + dict["name"] = self.name + dict["httpAccessType"] = self.httpAccess.rawValue + dict["posixPermissions"] = self.sshAccess.rawValue + dict["writeAccessExternalIDs"] = self.writeAccessExternalIds + dict["readAccessExternalIDs"] = self.readAccessExternalIds + + return dict + } + } \ No newline at end of file diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index 7b3e2e4..2f15076 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -554,6 +554,46 @@ public extension XcodeServer { } } + /** + XCS API call for creating new repository on configured Xcode Server. + **HTTP status codes**: + - **200** - corrupted body JSON, repository wasn't created. + - **204** - repository was created. + - **409** - name of repository already exists. + + - parameter repository: Repository object. + - parameter repository: Optional object of created repository. + - parameter error: Optional error. + */ + public func createRepository(repository: Repository, completion: (repository: Repository?, error: NSError?) -> ()) { + let body = repository.dictionarify() + + self.sendRequestWithMethod(.POST, endpoint: .Repositories, params: nil, query: nil, body: body) { (response, body, error) -> () in + guard error != nil else { + completion(repository: nil, error: error) + return + } + + guard let response = response else { + completion(repository: nil, error: Error.withInfo("Nil response")) + return + } + + guard let repositoryBody = body where response.statusCode == 204 else { + if response.statusCode == 409 { + completion(repository: nil, error: Error.withInfo("Repository with this name already exists")) + } else { + completion(repository: nil, error: Error.withInfo("Wrong status code: \(response.statusCode)")) + } + + return + } + + let repository = Repository(json: repositoryBody as! NSDictionary) + completion(repository: repository, error: nil) + } + } + //more advanced /** diff --git a/XcodeServerSDKTests/RepositoryTests.swift b/XcodeServerSDKTests/RepositoryTests.swift index f143b88..6eb1550 100644 --- a/XcodeServerSDKTests/RepositoryTests.swift +++ b/XcodeServerSDKTests/RepositoryTests.swift @@ -17,7 +17,7 @@ class RepositoryTests: XCTestCase { "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ], - "name": "Test3", + "name": "Test", "posixPermissions": 1, "httpAccessType": 1 ] @@ -26,7 +26,7 @@ class RepositoryTests: XCTestCase { func testInit() { let repo = Repository(json: json) - XCTAssertEqual(repo.name, "Test3") + XCTAssertEqual(repo.name, "Test") XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.LoggedIn) XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.LoggedInReadSelectedWrite) XCTAssertEqual(repo.writeAccessExternalIds, [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ]) @@ -34,13 +34,50 @@ class RepositoryTests: XCTestCase { } func testManualInit() { - let repo = Repository(name: "Test3", httpAccess: .LoggedIn, sshAccess: .LoggedInReadSelectedWrite, writeAccessExternalIds: [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ], readAccessExternalIds: []) + let repo = Repository(name: "Test", httpAccess: .LoggedIn, sshAccess: .LoggedInReadSelectedWrite, writeAccessExternalIds: [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ], readAccessExternalIds: []) - XCTAssertEqual(repo.name, "Test3") + XCTAssertEqual(repo.name, "Test") XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.LoggedIn) XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.LoggedInReadSelectedWrite) XCTAssertEqual(repo.writeAccessExternalIds, [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ]) XCTAssertEqual(repo.readAccessExternalIds, []) } + + func testConvenienceInit() { + let repo = Repository(name: "Test") + + XCTAssertEqual(repo.name, "Test") + XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.None) + XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.SelectedReadWrite) + XCTAssertEqual(repo.writeAccessExternalIds, []) + XCTAssertEqual(repo.readAccessExternalIds, []) + } + + // MARK: JSONifying + func testDictionarify() { + let repo = Repository(name: "Test", httpAccess: .LoggedIn, sshAccess: .LoggedInReadSelectedWrite, writeAccessExternalIds: [ "FDF283F5-B9C3-4B43-9000-EF6A54934D4E", "ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000050" ], readAccessExternalIds: []) + + XCTAssertEqual(repo.dictionarify(), json) + } + + // MARK: Enum tests + func testHTTPEnum() { + var httpEnum = Repository.HTTPAccessType.None + XCTAssertEqual(httpEnum.toString(), "No users are not allowed to read or write") + + httpEnum = .LoggedIn + XCTAssertEqual(httpEnum.toString(), "Logged in users are allowed to read and write") + } + + func testSSHEnum() { + var sshEnum = Repository.SSHAccessType.SelectedReadWrite + XCTAssertEqual(sshEnum.toString(), "Only selected users can read and/or write") + + sshEnum = .LoggedInReadSelectedWrite + XCTAssertEqual(sshEnum.toString(), "Only selected users can write but all logged in can read") + + sshEnum = .LoggedInReadWrite + XCTAssertEqual(sshEnum.toString(), "All logged in users can read and write") + } } From 640bccd87841991244fe61409e28e8e91004a33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zaj=C4=85c?= Date: Mon, 29 Jun 2015 20:38:44 +0200 Subject: [PATCH 09/11] Upgrade to suggested changes --- XcodeServerSDK/XcodeServer.swift | 48 ++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index 2f15076..c3ad189 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -554,43 +554,61 @@ public extension XcodeServer { } } + /** + Enum with response from creation of repository. + + - RepositoryAlreadyExists: Repository with this name already exists on OS X Server. + - NilResponse: Self explanatory. + - CorruptedJSON: JSON you've used to create repository. + - WrongStatusCode: Something wrong with HHTP status. + - Error: There was an error during netwotk activity. + - Success: Repository was successfully created 🎉 + */ + public enum CreateRepositoryResponse { + case RepositoryAlreadyExists + case NilResponse + case CorruptedJSON + case WrongStatusCode(Int) + case Error(ErrorType) + case Success(Repository) + } + /** XCS API call for creating new repository on configured Xcode Server. - **HTTP status codes**: - - **200** - corrupted body JSON, repository wasn't created. - - **204** - repository was created. - - **409** - name of repository already exists. - parameter repository: Repository object. - parameter repository: Optional object of created repository. - parameter error: Optional error. */ - public func createRepository(repository: Repository, completion: (repository: Repository?, error: NSError?) -> ()) { + public func createRepository(repository: Repository, completion: (repsponse: CreateRepositoryResponse) -> ()) { let body = repository.dictionarify() self.sendRequestWithMethod(.POST, endpoint: .Repositories, params: nil, query: nil, body: body) { (response, body, error) -> () in - guard error != nil else { - completion(repository: nil, error: error) + if let error = error { + completion(repsponse: XcodeServer.CreateRepositoryResponse.Error(error)) return } guard let response = response else { - completion(repository: nil, error: Error.withInfo("Nil response")) + completion(repsponse: XcodeServer.CreateRepositoryResponse.NilResponse) return } - guard let repositoryBody = body where response.statusCode == 204 else { - if response.statusCode == 409 { - completion(repository: nil, error: Error.withInfo("Repository with this name already exists")) - } else { - completion(repository: nil, error: Error.withInfo("Wrong status code: \(response.statusCode)")) + guard let repositoryBody = body as? NSDictionary where response.statusCode == 204 else { + switch response.statusCode { + case 200: + completion(repsponse: XcodeServer.CreateRepositoryResponse.CorruptedJSON) + case 409: + completion(repsponse: XcodeServer.CreateRepositoryResponse.RepositoryAlreadyExists) + default: + completion(repsponse: XcodeServer.CreateRepositoryResponse.WrongStatusCode(response.statusCode)) } return } - let repository = Repository(json: repositoryBody as! NSDictionary) - completion(repository: repository, error: nil) + let repository = Repository(json: repositoryBody) + completion(repsponse: XcodeServer.CreateRepositoryResponse.Success(repository)) } } From 7eb64182670502bb3e1a4969da905c703d340683 Mon Sep 17 00:00:00 2001 From: Mateusz Zajac Date: Tue, 30 Jun 2015 08:31:32 +0200 Subject: [PATCH 10/11] Batch of fixes --- XcodeServerSDK/Server Entities/Repository.swift | 4 +++- XcodeServerSDK/XcodeServer.swift | 14 +++++++------- XcodeServerSDKTests/RepositoryTests.swift | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/XcodeServerSDK/Server Entities/Repository.swift b/XcodeServerSDK/Server Entities/Repository.swift index 6c1a9e3..922ba03 100644 --- a/XcodeServerSDK/Server Entities/Repository.swift +++ b/XcodeServerSDK/Server Entities/Repository.swift @@ -60,7 +60,9 @@ public class Repository: XcodeRead { public let name: String public var httpAccess: HTTPAccessType = HTTPAccessType.None - public var sshAccess: SSHAccessType = SSHAccessType.SelectedReadWrite + // XCS's defualt if SelectedReadWrite but if you don't provide + // array of IDs, nobody will have access to the repository + public var sshAccess: SSHAccessType = SSHAccessType.LoggedInReadWrite public var writeAccessExternalIds: [String] = [] public var readAccessExternalIds: [String] = [] diff --git a/XcodeServerSDK/XcodeServer.swift b/XcodeServerSDK/XcodeServer.swift index c3ad189..eaec13b 100644 --- a/XcodeServerSDK/XcodeServer.swift +++ b/XcodeServerSDK/XcodeServer.swift @@ -580,35 +580,35 @@ public extension XcodeServer { - parameter repository: Optional object of created repository. - parameter error: Optional error. */ - public func createRepository(repository: Repository, completion: (repsponse: CreateRepositoryResponse) -> ()) { + public func createRepository(repository: Repository, completion: (response: CreateRepositoryResponse) -> ()) { let body = repository.dictionarify() self.sendRequestWithMethod(.POST, endpoint: .Repositories, params: nil, query: nil, body: body) { (response, body, error) -> () in if let error = error { - completion(repsponse: XcodeServer.CreateRepositoryResponse.Error(error)) + completion(response: XcodeServer.CreateRepositoryResponse.Error(error)) return } guard let response = response else { - completion(repsponse: XcodeServer.CreateRepositoryResponse.NilResponse) + completion(response: XcodeServer.CreateRepositoryResponse.NilResponse) return } guard let repositoryBody = body as? NSDictionary where response.statusCode == 204 else { switch response.statusCode { case 200: - completion(repsponse: XcodeServer.CreateRepositoryResponse.CorruptedJSON) + completion(response: XcodeServer.CreateRepositoryResponse.CorruptedJSON) case 409: - completion(repsponse: XcodeServer.CreateRepositoryResponse.RepositoryAlreadyExists) + completion(response: XcodeServer.CreateRepositoryResponse.RepositoryAlreadyExists) default: - completion(repsponse: XcodeServer.CreateRepositoryResponse.WrongStatusCode(response.statusCode)) + completion(response: XcodeServer.CreateRepositoryResponse.WrongStatusCode(response.statusCode)) } return } let repository = Repository(json: repositoryBody) - completion(repsponse: XcodeServer.CreateRepositoryResponse.Success(repository)) + completion(response: XcodeServer.CreateRepositoryResponse.Success(repository)) } } diff --git a/XcodeServerSDKTests/RepositoryTests.swift b/XcodeServerSDKTests/RepositoryTests.swift index 6eb1550..903d402 100644 --- a/XcodeServerSDKTests/RepositoryTests.swift +++ b/XcodeServerSDKTests/RepositoryTests.swift @@ -48,7 +48,7 @@ class RepositoryTests: XCTestCase { XCTAssertEqual(repo.name, "Test") XCTAssertEqual(repo.httpAccess, Repository.HTTPAccessType.None) - XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.SelectedReadWrite) + XCTAssertEqual(repo.sshAccess, Repository.SSHAccessType.LoggedInReadWrite) XCTAssertEqual(repo.writeAccessExternalIds, []) XCTAssertEqual(repo.readAccessExternalIds, []) } From 7fbd3197dd69cca5225890783fbe0c6084311e8b Mon Sep 17 00:00:00 2001 From: Mateusz Zajac Date: Tue, 30 Jun 2015 08:34:10 +0200 Subject: [PATCH 11/11] README support update --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4360f55..c4bd7b1 100644 --- a/README.md +++ b/README.md @@ -79,14 +79,14 @@ We're providing a Plaground in which you can easily interact with `XcodeServerSD | Delete a bot | :no_entry: | :white_check_mark: | | _Get bot's most recent integrations_ | :white_check_mark: | :white_check_mark: | | _Enqueue a new integration_ | :white_check_mark: | :white_check_mark: | -| _List integrations on server_ | :white_check_mark: | :no_entry: | -| _Retrieve an integration by ID_ | :white_check_mark: | :no_entry: | +| _List integrations on server_ | :white_check_mark: | :white_check_mark: | +| _Retrieve an integration by ID_ | :white_check_mark: | :white_check_mark: | | Cancel integration | :no_entry: | :white_check_mark: | | _List the commits included in an integration_ | :white_check_mark: | :no_entry: | | _List the build issues produced by an integration_ | :white_check_mark: | :no_entry: | | _List devices connected to server_ | :white_check_mark: | :white_check_mark: | -| _List hosted repositories on server_ | :white_check_mark: | :no_entry: | -| _Create a new hosted repository_ | :white_check_mark: | :no_entry: | +| _List hosted repositories on server_ | :white_check_mark: | :white_check_mark: | +| _Create a new hosted repository_ | :white_check_mark: | :white_check_mark: | | Get supported platforms | :no_entry: | :white_check_mark: | | Get SCM branches from Blueprint | :no_entry: | :white_check_mark: | | Verify user can manage server | :no_entry: | :white_check_mark: |