Skip to content

Commit

Permalink
Decided against making tray pipeline credentials editable.
Browse files Browse the repository at this point in the history
Is the username part of the ID of a pipeline...?
  • Loading branch information
erikdoe committed May 18, 2024
1 parent d88f533 commit ee6516b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 54 deletions.
4 changes: 0 additions & 4 deletions CCMenu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -200,7 +199,6 @@
03CC11F1265467C200130833 /* CCTrayResponseParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCTrayResponseParser.swift; sourceTree = "<group>"; };
03CC61CE2BA757050008EE76 /* TrustManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrustManager.swift; sourceTree = "<group>"; };
03CC61D02BA783EE0008EE76 /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
03D4BB002659A1120023F4CB /* PipelineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PipelineTests.swift; sourceTree = "<group>"; };
03D4BB02265EE5840023F4CB /* GitHubFeedReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubFeedReader.swift; sourceTree = "<group>"; };
03D4BB04265EE6B50023F4CB /* GitHubResponseParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubResponseParser.swift; sourceTree = "<group>"; };
03DA98DB2B4498BB0073F5BB /* GitHubRepositoryList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GitHubRepositoryList.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -387,7 +385,6 @@
03BD7E9D2598E57A000F9495 /* CCMenuTests */ = {
isa = PBXGroup;
children = (
03D4BB002659A1120023F4CB /* PipelineTests.swift */,
037AB21B297B4D5F00C33589 /* PipelineModelTests.swift */,
03B263F32B509E5300CA989A /* StatusChangeTests.swift */,
03B021242A5D9F9D00B889BE /* MenuExtraModelTests.swift */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}

Expand Down Expand Up @@ -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()
}
Expand All @@ -78,7 +78,7 @@ struct AddCCTrayPipelineSheet: View {
.padding()
}

private func credentialOptional() -> HTTPCredential? {
private var credentialOptional: HTTPCredential? {
(useBasicAuth && !credential.isEmpty) ? credential : nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
25 changes: 1 addition & 24 deletions CCMenu/Source/Pipeline Window/EditPipelineSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,13 @@ 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 {
VStack {
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")
Expand All @@ -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()
}

}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ 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

### To consider

- [ ] 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)
Expand Down

0 comments on commit ee6516b

Please sign in to comment.