diff --git a/CCMenu.xcodeproj/project.pbxproj b/CCMenu.xcodeproj/project.pbxproj index 851686c..86f3460 100644 --- a/CCMenu.xcodeproj/project.pbxproj +++ b/CCMenu.xcodeproj/project.pbxproj @@ -72,7 +72,6 @@ 03CC11F2265467C200130833 /* CCTrayResponseParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CC11F1265467C200130833 /* CCTrayResponseParser.swift */; }; 03CC61CF2BA757050008EE76 /* TrustManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CC61CE2BA757050008EE76 /* TrustManager.swift */; }; 03CC61D12BA783EE0008EE76 /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03CC61D02BA783EE0008EE76 /* NetworkMonitor.swift */; }; - 03D4BB012659A1120023F4CB /* PipelineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D4BB002659A1120023F4CB /* PipelineTests.swift */; }; 03D4BB03265EE5840023F4CB /* GitHubFeedReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D4BB02265EE5840023F4CB /* GitHubFeedReader.swift */; }; 03D4BB05265EE6B50023F4CB /* GitHubResponseParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03D4BB04265EE6B50023F4CB /* GitHubResponseParser.swift */; }; 03DA98DC2B4498BB0073F5BB /* GitHubRepositoryList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03DA98DB2B4498BB0073F5BB /* GitHubRepositoryList.swift */; }; @@ -200,7 +199,6 @@ 03CC11F1265467C200130833 /* CCTrayResponseParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCTrayResponseParser.swift; sourceTree = ""; }; 03CC61CE2BA757050008EE76 /* TrustManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrustManager.swift; sourceTree = ""; }; 03CC61D02BA783EE0008EE76 /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = ""; }; - 03D4BB002659A1120023F4CB /* PipelineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PipelineTests.swift; sourceTree = ""; }; 03D4BB02265EE5840023F4CB /* GitHubFeedReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubFeedReader.swift; sourceTree = ""; }; 03D4BB04265EE6B50023F4CB /* GitHubResponseParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubResponseParser.swift; sourceTree = ""; }; 03DA98DB2B4498BB0073F5BB /* GitHubRepositoryList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubRepositoryList.swift; sourceTree = ""; }; @@ -387,7 +385,6 @@ 03BD7E9D2598E57A000F9495 /* CCMenuTests */ = { isa = PBXGroup; children = ( - 03D4BB002659A1120023F4CB /* PipelineTests.swift */, 037AB21B297B4D5F00C33589 /* PipelineModelTests.swift */, 03B263F32B509E5300CA989A /* StatusChangeTests.swift */, 03B021242A5D9F9D00B889BE /* MenuExtraModelTests.swift */, @@ -824,7 +821,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 03D4BB012659A1120023F4CB /* PipelineTests.swift in Sources */, 037AB21C297B4D5F00C33589 /* PipelineModelTests.swift in Sources */, 2FA28FBCC0398D63EF2D2C16 /* NSImageExtensionTests.swift in Sources */, 03B021252A5D9F9D00B889BE /* MenuExtraModelTests.swift in Sources */, diff --git a/CCMenu/Source/Pipeline Window/CCTray Sheets/AddCCTrayPipelineSheet.swift b/CCMenu/Source/Pipeline Window/CCTray Sheets/AddCCTrayPipelineSheet.swift index fb06021..0792e32 100644 --- a/CCMenu/Source/Pipeline Window/CCTray Sheets/AddCCTrayPipelineSheet.swift +++ b/CCMenu/Source/Pipeline Window/CCTray Sheets/AddCCTrayPipelineSheet.swift @@ -33,7 +33,7 @@ struct AddCCTrayPipelineSheet: View { .autocorrectionDisabled(true) .onSubmit { if !url.isEmpty { - Task { await projectList.updateProjects(url: $url, credential: credentialOptional()) } + Task { await projectList.updateProjects(url: $url, credential: credentialOptional) } } } @@ -65,7 +65,7 @@ struct AddCCTrayPipelineSheet: View { } .keyboardShortcut(.cancelAction) Button("Apply") { - let p = builder.makePipeline(feedUrl: url, credential: credentialOptional()) + let p = builder.makePipeline(feedUrl: url, credential: credentialOptional) config.setPipeline(p) presentation.dismiss() } @@ -78,7 +78,7 @@ struct AddCCTrayPipelineSheet: View { .padding() } - private func credentialOptional() -> HTTPCredential? { + private var credentialOptional: HTTPCredential? { (useBasicAuth && !credential.isEmpty) ? credential : nil } diff --git a/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift b/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift index 9ad450a..eff6b46 100644 --- a/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift +++ b/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift @@ -22,36 +22,33 @@ class CCTrayPipelineBuilder: ObservableObject { func makePipeline(feedUrl: String, credential: HTTPCredential?) -> Pipeline? { - var feedUrl = feedUrl - if let credential { - feedUrl = setUser(credential.user, inURL: feedUrl) - do { - try Keychain().setPassword(credential.password, forURL: feedUrl) - } catch { - // TODO: Figure out what to do here – so many errors... - } - } + guard var feedUrl = URL(string: feedUrl) else { return nil } + feedUrl = Self.applyCredential(credential, toURL: feedUrl) guard let project else { return nil } - guard let url = URL(string: feedUrl) else { return nil } - let feed = Pipeline.Feed(type: .cctray, url: url, name: project.name) + let feed = Pipeline.Feed(type: .cctray, url: feedUrl, name: project.name) var p: Pipeline = Pipeline(name: name, feed: feed) p.status = Pipeline.Status(activity: .sleeping) p.status.lastBuild = Build(result: .unknown) return p } - private func setUser(_ user: String?, inURL urlString: String) -> String { - guard let user, !user.isEmpty else { - return urlString - } - guard var url = URLComponents(string: urlString) else { - return urlString - } - url.user = user - guard let newUrlString = url.string else { - return "" + + static func applyCredential(_ credential: HTTPCredential?, toURL url: URL) -> URL { + guard var components = URLComponents(url: url, resolvingAgainstBaseURL: true) else { return url } + if let credential, !credential.isEmpty { + components.user = credential.user + if !credential.password.isEmpty { + do { + try Keychain().setPassword(credential.password, forURL: url.absoluteString) + } catch { + // TODO: Figure out what to do here – so many errors... + } + } + } else { + components.user = nil } - return newUrlString + let newUrl = components.url?.absoluteURL ?? url + return newUrl } } diff --git a/CCMenu/Source/Pipeline Window/EditPipelineSheet.swift b/CCMenu/Source/Pipeline Window/EditPipelineSheet.swift index 36ee522..bbaa38a 100644 --- a/CCMenu/Source/Pipeline Window/EditPipelineSheet.swift +++ b/CCMenu/Source/Pipeline Window/EditPipelineSheet.swift @@ -10,8 +10,6 @@ import SwiftUI struct EditPipelineSheet: View { @Binding var config: PipelineSheetConfig @Environment(\.presentationMode) @Binding var presentation - @State var useBasicAuth = false - @State var credential = HTTPCredential(user: "", password: "") @State var name: String = "" var body: some View { @@ -19,12 +17,6 @@ struct EditPipelineSheet: View { Text("Edit Pipeline") .font(.headline) .padding(.bottom) - - if let p = config.pipeline, p.feed.type == .cctray { - CCTrayAuthView(useBasicAuth: $useBasicAuth, credential: $credential) - .padding(.bottom) - } - Form { TextField("Name:", text: $name) .accessibilityIdentifier("Name field") @@ -48,26 +40,11 @@ struct EditPipelineSheet: View { } .onAppear() { name = config.pipeline?.name ?? "" -// if pipeline.feed.type == .cctray { -// if let url = URLComponents(string: pipeline.feed.url) { -// if let user = url.user { -// useBasicAuth = true -// credential.user = user -// do { -// if let url = url.url, let password = try Keychain().getPassword(forURL: url) { -// credential.password = password -// } -// } -// catch { -// // TODO: What to do here? -// } -// } -// } -// } } } .frame(minWidth: 400) .frame(idealWidth: 450) .padding() } + } diff --git a/README.md b/README.md index 77c9266..52bea06 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ For now the roadmap is tracked in this readme file. ### Pre-release 6 (planned) - [X] Import and export of pipelines -- [ ] Set user/password for CCTray pipelines - [X] Refresh GitHub token - [X] Allow selection of branch on GitHub @@ -57,6 +56,7 @@ For now the roadmap is tracked in this readme file. - [ ] Sounds - [ ] Support for workflow-specific GitHub tokens +- [ ] Update password for CCTray pipelines - [ ] Improve accessibility - [ ] Add support for localisation - [ ] Show avatar in notifications (committer or repo owner)