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

Add missing API calls: manage hosted repositories, get integrations #48

Merged
merged 16 commits into from
Jun 30, 2015
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions XcodeServerSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Copy link
Member

Choose a reason for hiding this comment

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

Do you know why it's duplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a strange thing... Probably because of some kind of bug. I'll handle this 😉

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 */; };
Expand All @@ -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 */
Expand Down Expand Up @@ -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 = "<group>"; };
3AA922A31B3F4630005A0F73 /* DVR.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = DVR.xcodeproj; path = Carthage/Checkouts/DVR/DVR.xcodeproj; sourceTree = "<group>"; };
3ABE68651B3AC3C500FA0A61 /* DeviceSpecification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceSpecification.swift; sourceTree = "<group>"; };
7045917E1B4074CC00BA226C /* Repository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Repository.swift; sourceTree = "<group>"; };
704591851B40945700BA226C /* RepositoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepositoryTests.swift; sourceTree = "<group>"; };
705D59A01B3AE502002521BA /* HTTPUtilsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPUtilsTests.swift; sourceTree = "<group>"; };
707D08951B2C684C003900F3 /* XcodeServerConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XcodeServerConfig.swift; sourceTree = "<group>"; };
707D08971B2C6954003900F3 /* EmailConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmailConfiguration.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -366,6 +373,7 @@
3A058A921B315BB50077FD47 /* TestUtils.swift */,
705D59A01B3AE502002521BA /* HTTPUtilsTests.swift */,
70B21FF71B3AFB1D00EAD4EB /* BotConfigurationTests.swift */,
704591851B40945700BA226C /* RepositoryTests.swift */,
3A7B48CA1B2A5AC40077ABEA /* Supporting Files */,
);
path = XcodeServerSDKTests;
Expand Down Expand Up @@ -421,6 +429,7 @@
3A7B48DB1B2A5ADE0077ABEA /* SourceControlBlueprint.swift */,
707D089B1B2C69C4003900F3 /* Trigger.swift */,
707D089D1B2C6A1F003900F3 /* TriggerConditions.swift */,
7045917E1B4074CC00BA226C /* Repository.swift */,
);
path = "Server Entities";
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand All @@ -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 */,
Expand Down
103 changes: 103 additions & 0 deletions XcodeServerSDK/Server Entities/Repository.swift
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

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

So far we have all the other types as class. Is there a particular reason to start using structs instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm... No particular reason but:

  • it'll make compiler happy
  • this is not inheriting from anything

I can switch to class, no problem - actually implementation stays the same. I was rather hoping for some kind of critique regarding implementation itself 😀


Some more investigation and I think class is a good solution as I'll be conforming to XcodeRead just to gain XcodeServerArray functionality 👍


/**
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")
}

}
60 changes: 59 additions & 1 deletion XcodeServerSDK/XcodeServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,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
Expand Down Expand Up @@ -398,6 +398,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 getIntegration(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 = [
Expand All @@ -415,6 +447,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?) -> ()) {
Copy link
Member

Choose a reason for hiding this comment

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

Btw, you can also use filters for integrations, see /Applications/Xcode-beta.app/Contents/Developer/usr/share/xcs/xcsd/routes/routes_integration.js. Not that you have to add it now, just FYI, probably something to add at some point in the future 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WOW, this is pretty cool! I'll add it for sure but I guess after #47 is complete so I don't get lost 😆

Copy link
Member

Choose a reason for hiding this comment

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

Haha yeah that makes sense. Let's split them first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@czechboy0 while working on #47 I've noticed thath your method: getBotIntegrations() use filters. Do you have any clue where I can find available keys for this :filter? query? While Charlesing around I've noticed only one:

  • last=

So I went to integrationFilterClass.js but guess what - can't find anything... 😕 Give me some hints as I want to include those to header docs.

Copy link
Member

Choose a reason for hiding this comment

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

See integrationSearchClass.js starting from line 124. Filters like from, last, number etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you‼️

I hate JS... 😕 Can't find anything in this mess! Hope Swift will replace it soon 😆


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
Expand Down
6 changes: 6 additions & 0 deletions XcodeServerSDK/XcodeServerEndpoints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class XcodeServerEndPoints {
case Logout
case Platforms
case SCM_Branches
case Repositories
}

let serverConfig: XcodeServerConfig
Expand Down Expand Up @@ -106,6 +107,11 @@ public class XcodeServerEndPoints {
let branches = "\(base)/scm/branches"
return branches

case .Repositories:

let repositories = "\(base)/repositories"
return repositories

}
}

Expand Down
46 changes: 46 additions & 0 deletions XcodeServerSDKTests/RepositoryTests.swift
Original file line number Diff line number Diff line change
@@ -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, [])
}

Copy link
Member

Choose a reason for hiding this comment

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

Awesome stuff, we need to have every class covered as well as this! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}