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

Initial refactor of syncer #51

Merged
merged 5 commits into from
May 17, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 16 additions & 16 deletions BuildaCIServer/XcodeServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public extension XcodeServer {
self.http.sendRequest(request, completion: { (response, body, error) -> () in

if response == nil {
let e = error ?? Errors.errorWithInfo("Nil response")
let e = error ?? Error.withInfo("Nil response")
completion(response: nil, body: body, error: e)
return
}
Expand All @@ -156,7 +156,7 @@ public extension XcodeServer {
})

} else {
completion(response: nil, body: nil, error: Errors.errorWithInfo("Couldn't create Request"))
completion(response: nil, body: nil, error: Error.withInfo("Couldn't create Request"))
}
}

Expand All @@ -173,11 +173,11 @@ public extension XcodeServer {
if response.statusCode == 204 {
completion(success: true, error: nil)
} else {
completion(success: false, error: Errors.errorWithInfo("Wrong status code: \(response.statusCode)"))
completion(success: false, error: Error.withInfo("Wrong status code: \(response.statusCode)"))
}
return
}
completion(success: false, error: Errors.errorWithInfo("Nil response"))
completion(success: false, error: Error.withInfo("Nil response"))
}
}

Expand All @@ -194,11 +194,11 @@ public extension XcodeServer {
if response.statusCode == 204 {
completion(success: true, error: nil)
} else {
completion(success: false, error: Errors.errorWithInfo("Wrong status code: \(response.statusCode)"))
completion(success: false, error: Error.withInfo("Wrong status code: \(response.statusCode)"))
}
return
}
completion(success: false, error: Errors.errorWithInfo("Nil response"))
completion(success: false, error: Error.withInfo("Nil response"))
}
}

Expand All @@ -217,7 +217,7 @@ public extension XcodeServer {
let bot = Bot(json: body as NSDictionary)
completion(bot: bot, error: nil)
} else {
completion(bot: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(bot: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand All @@ -239,7 +239,7 @@ public extension XcodeServer {
let bot = Bot(json: body)
completion(bot: bot, error: nil)
} else {
completion(bot: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(bot: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand All @@ -262,10 +262,10 @@ public extension XcodeServer {
if response.statusCode == 204 {
completion(success: true, error: nil)
} else {
completion(success: false, error: Errors.errorWithInfo("Wrong status code: \(response.statusCode)"))
completion(success: false, error: Error.withInfo("Wrong status code: \(response.statusCode)"))
}
} else {
completion(success: false, error: Errors.errorWithInfo("Nil response"))
completion(success: false, error: Error.withInfo("Nil response"))
}
}
}
Expand All @@ -283,7 +283,7 @@ public extension XcodeServer {
let bots: [Bot] = XcodeServerArray(body)
completion(bots: bots, error: nil)
} else {
completion(bots: nil, error: Errors.errorWithInfo("Wrong data returned: \(body)"))
completion(bots: nil, error: Error.withInfo("Wrong data returned: \(body)"))
}
}
}
Expand All @@ -305,7 +305,7 @@ public extension XcodeServer {
let integrations: [Integration] = XcodeServerArray(body)
completion(integrations: integrations, error: nil)
} else {
completion(integrations: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(integrations: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand All @@ -332,7 +332,7 @@ public extension XcodeServer {
let integration = Integration(json: body)
completion(integration: integration, error: nil)
} else {
completion(integration: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(integration: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ public extension XcodeServer {
let devices: [Device] = XcodeServerArray(array)
completion(devices: devices, error: error)
} else {
completion(devices: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(devices: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand All @@ -385,10 +385,10 @@ public extension XcodeServer {
if let canCreateBots = body["result"] as? Bool where canCreateBots == true {
completion(canCreateBots: true, error: nil)
} else {
completion(canCreateBots: false, error: Errors.errorWithInfo("Specified user cannot create bots"))
completion(canCreateBots: false, error: Error.withInfo("Specified user cannot create bots"))
}
} else {
completion(canCreateBots: false, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(canCreateBots: false, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion BuildaGitServer/GitHubEndpoints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GitHubEndpoints {
private let baseURL: String
private let token: String?

init(baseURL: String, token: String?) {
public init(baseURL: String, token: String?) {
self.baseURL = baseURL
self.token = token
}
Expand Down
28 changes: 14 additions & 14 deletions BuildaGitServer/GitHubServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extension GitHubServer {
}

if response == nil {
completion(response: nil, body: body, error: Errors.errorWithInfo("Nil response"))
completion(response: nil, body: body, error: Error.withInfo("Nil response"))
return
}

Expand All @@ -151,7 +151,7 @@ extension GitHubServer {
where message == "Not Found" {

let url = request.URL ?? ""
completion(response: nil, body: nil, error: Errors.errorWithInfo("Not found: \(url)"))
completion(response: nil, body: nil, error: Error.withInfo("Not found: \(url)"))
return
}

Expand All @@ -162,7 +162,7 @@ extension GitHubServer {
case 400 ... 500:
let message = (body as? NSDictionary)?["message"] as? String ?? "Unknown error"
let resultString = "\(statusCode): \(message)"
completion(response: response, body: body, error: Errors.errorWithInfo(resultString, internalError: error))
completion(response: response, body: body, error: Error.withInfo(resultString, internalError: error))
return
default:
break
Expand All @@ -189,7 +189,7 @@ extension GitHubServer {

self.sendRequestWithPossiblePagination(request, accumulatedResponseBody: NSArray(), completion: completion)
} else {
completion(response: nil, body: nil, error: Errors.errorWithInfo("Couldn't create Request"))
completion(response: nil, body: nil, error: Error.withInfo("Couldn't create Request"))
}
}

Expand All @@ -212,7 +212,7 @@ extension GitHubServer {
let prs: [PullRequest] = GitHubArray(body)
completion(prs: prs, error: nil)
} else {
completion(prs: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(prs: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand All @@ -238,7 +238,7 @@ extension GitHubServer {
let pr = PullRequest(json: body)
completion(pr: pr, error: nil)
} else {
completion(pr: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(pr: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down Expand Up @@ -266,7 +266,7 @@ extension GitHubServer {
let mostRecentStatus = statuses.sorted({ return $0.created! > $1.created! }).first
completion(status: mostRecentStatus, error: nil)
} else {
completion(status: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(status: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand All @@ -293,7 +293,7 @@ extension GitHubServer {
let status = Status(json: body)
completion(status: status, error: nil)
} else {
completion(status: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(status: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ extension GitHubServer {
let comments: [Comment] = GitHubArray(body)
completion(comments: comments, error: nil)
} else {
completion(comments: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(comments: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down Expand Up @@ -351,7 +351,7 @@ extension GitHubServer {
let comment = Comment(json: body)
completion(comment: comment, error: nil)
} else {
completion(comment: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(comment: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ extension GitHubServer {
let comment = Comment(json: body)
completion(comment: comment, error: nil)
} else {
completion(comment: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(comment: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down Expand Up @@ -433,7 +433,7 @@ extension GitHubServer {
completion(result: nil, error: error)
}
} else {
completion(result: nil, error: Errors.errorWithInfo("Nil response"))
completion(result: nil, error: Error.withInfo("Nil response"))
}
}
}
Expand All @@ -459,7 +459,7 @@ extension GitHubServer {
let branches: [Branch] = GitHubArray(body)
completion(branches: branches, error: nil)
} else {
completion(branches: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(branches: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand All @@ -485,7 +485,7 @@ extension GitHubServer {
let repository: Repo = Repo(json: body)
completion(repo: repository, error: nil)
} else {
completion(repo: nil, error: Errors.errorWithInfo("Wrong body \(body)"))
completion(repo: nil, error: Error.withInfo("Wrong body \(body)"))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions BuildaGitServer/GitHubServerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public extension GitHubServer {
let sha = pr.head.sha
self.getStatusOfCommit(sha, repo: repo, completion: completion)
} else {
completion(status: nil, error: Errors.errorWithInfo("PR is nil and error is nil"))
completion(status: nil, error: Error.withInfo("PR is nil and error is nil"))
}
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ public extension GitHubServer {
}
completion(foundComments: filtered, error: nil)
} else {
completion(foundComments: nil, error: Errors.errorWithInfo("Nil comments and nil error. Wat?"))
completion(foundComments: nil, error: Error.withInfo("Nil comments and nil error. Wat?"))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions BuildaUtils/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public enum BuildaError: String {
case UnknownError = "Unknown error"
}

public class Errors {
public class Error {

public class func errorFromType(type: BuildaError) -> NSError {
public class func fromType(type: BuildaError) -> NSError {

return self.errorWithInfo(type.rawValue)
return self.withInfo(type.rawValue)
}

public class func errorWithInfo(info: String?, internalError: NSError? = nil, userInfo: NSDictionary? = nil) -> NSError {
public class func withInfo(info: String?, internalError: NSError? = nil, userInfo: NSDictionary? = nil) -> NSError {

var finalInfo = NSMutableDictionary()
if let info = info {
Expand Down
4 changes: 2 additions & 2 deletions BuildaUtils/HTTPUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class HTTP {

let commonError: NSError? = {
if let userInfo = userInfo {
return Errors.errorWithInfo(nil, internalError: nil, userInfo: userInfo)
return Error.withInfo(nil, internalError: nil, userInfo: userInfo)
}
return nil
}()
Expand All @@ -87,7 +87,7 @@ public class HTTP {
completion(response: httpResponse, body: code, error: error)
}
} else {
let e = error ?? Errors.errorWithInfo("Response is nil")
let e = error ?? Error.withInfo("Response is nil")
completion(response: nil, body: nil, error: e)
}

Expand Down
4 changes: 2 additions & 2 deletions BuildaUtils/XcodeProjectParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public class XcodeProjectParser {
if let parsed = self.parseCheckoutFile(checkoutUrl) {
return (parsed, nil)
} else {
let error = Errors.errorWithInfo("Cannot parse the checkout file at path \(checkoutUrl)")
let error = Error.withInfo("Cannot parse the checkout file at path \(checkoutUrl)")
return (nil, error)
}
}
//no checkout, what to do?
let error = Errors.errorWithInfo("Cannot find the Checkout file, please make sure to open this project in Xcode at least once (it will generate the required Checkout file). Then try again.")
let error = Error.withInfo("Cannot find the Checkout file, please make sure to open this project in Xcode at least once (it will generate the required Checkout file). Then try again.")
return (nil, error)
}

Expand Down
Loading