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

Handling of missing Xcode project/workspaces #179

Merged
merged 2 commits into from
Oct 15, 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
21 changes: 13 additions & 8 deletions BuildaKit/SyncerFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public protocol SyncerFactoryType {
func defaultConfigTriplet() -> ConfigTriplet
func newEditableTriplet() -> EditableConfigTriplet
func createXcodeServer(config: XcodeServerConfig) -> XcodeServer
func createProject(config: ProjectConfig) -> Project
func createProject(config: ProjectConfig) -> Project?
func createSourceServer(token: String) -> GitHubServer
func createTrigger(config: TriggerConfig) -> Trigger
}
Expand All @@ -28,14 +28,17 @@ public class SyncerFactory: SyncerFactoryType {

public init() { }

private func createSyncer(triplet: ConfigTriplet) -> HDGitHubXCBotSyncer {
private func createSyncer(triplet: ConfigTriplet) -> HDGitHubXCBotSyncer? {

let xcodeServer = self.createXcodeServer(triplet.server)
let githubServer = self.createSourceServer(triplet.project.githubToken)
let project = self.createProject(triplet.project)
let maybeProject = self.createProject(triplet.project)
let triggers = triplet.triggers.map { self.createTrigger($0) }

if let poolAttempt = self.syncerPool[triplet.syncer.id] {
guard let project = maybeProject else { return nil }

if let poolAttempt = self.syncerPool[triplet.syncer.id]
{
poolAttempt.config.value = triplet.syncer
poolAttempt.xcodeServer = xcodeServer
poolAttempt.github = githubServer
Expand All @@ -62,7 +65,7 @@ public class SyncerFactory: SyncerFactoryType {
public func createSyncers(configs: [ConfigTriplet]) -> [HDGitHubXCBotSyncer] {

//create syncers
let created = configs.map { self.createSyncer($0) }
let created = configs.map { self.createSyncer($0) }.filter { $0 != nil }.map { $0! }

let createdIds = Set(created.map { $0.config.value.id })

Expand Down Expand Up @@ -98,16 +101,18 @@ public class SyncerFactory: SyncerFactoryType {
return server
}

public func createProject(config: ProjectConfig) -> Project {
public func createProject(config: ProjectConfig) -> Project? {

if let poolAttempt = self.projectPool[config.id] {
poolAttempt.config.value = config
return poolAttempt
}

//TODO: maybe this producer SHOULD throw errors, when parsing fails?
let project = try! Project(config: config)
self.projectPool[config.id] = project
let project = try? Project(config: config)
if let project = project {
self.projectPool[config.id] = project
}

return project
}
Expand Down
2 changes: 1 addition & 1 deletion BuildaKit/SyncerProducerFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SyncerProducerFactory {

let projects = configs.map { configsArray in
return configsArray.map { factory.createProject($0) }
}
}.map { $0.filter { $0 != nil } }.map { $0.map { $0! } }
return projects
}

Expand Down
10 changes: 8 additions & 2 deletions Buildasaur/EmptyProjectViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class EmptyProjectViewController: EditableViewController {
let configsProducer = self.storageManager.projectConfigs.producer
let allConfigsProducer = configsProducer
.map { Array($0.values) }
.map { configs in configs.filter { (try? Project(config: $0)) != nil } }
.map { configs in configs.sort { $0.name < $1.name } }
allConfigsProducer.startWithNext { [weak self] newConfigs in
guard let sself = self else { return }
Expand Down Expand Up @@ -138,8 +139,13 @@ class EmptyProjectViewController: EditableViewController {
return config
} catch {
//local source is malformed, something terrible must have happened, inform the user this can't be used (log should tell why exactly)
UIUtils.showAlertWithText("Couldn't add Xcode project at path \(url.absoluteString), error: \((error as NSError).localizedDescription).", style: NSAlertStyle.CriticalAlertStyle, completion: { (resp) -> () in
//
let buttons = ["See workaround", "OK"]

UIUtils.showAlertWithButtons("Couldn't add Xcode project at path \(url.absoluteString), error: \((error as NSError).localizedDescription).", buttons: buttons, style: NSAlertStyle.CriticalAlertStyle, completion: { (tappedButton) -> () in

if tappedButton == "See workaround" {
openLink("https://github.com/czechboy0/Buildasaur/issues/165#issuecomment-148220340")
}
})
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions Buildasaur/UIUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class UIUtils {
self.showAlertAskingConfirmation(text, dangerButton: "Remove", completion: completion)
}

public class func showAlertWithButtons(text: String, buttons: [String], completion: (tappedButton: String) -> ()) {
public class func showAlertWithButtons(text: String, buttons: [String], style: NSAlertStyle? = nil, completion: (tappedButton: String) -> ()) {

let alert = self.createAlert(text, style: nil)
let alert = self.createAlert(text, style: style)

buttons.forEach { alert.addButtonWithTitle($0) }

Expand Down