Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct AddGitHubPipelineSheet: View {
@StateObject private var branch = DebouncedText()
@StateObject private var branchList = GitHubBranchList()
@StateObject private var builder = GitHubPipelineBuilder()
@State private var tokenInput: String = ""

var body: some View {
VStack {
Expand All @@ -29,10 +30,15 @@ struct AddGitHubPipelineSheet: View {
.padding(.bottom)
Form {
HStack {
TextField("Authentication:", text: $authenticator.tokenDescription)
TextField("Authentication:", text: $tokenInput, prompt: Text("paste token or sign in"))
.accessibilityIdentifier("Token field")
.truncationMode(.tail)
.disabled(true)
.onChange(of: tokenInput) {
authenticator.setToken(tokenInput)
}
.onSubmit {
authenticator.setToken(tokenInput)
}
if authenticator.isWaitingForToken {
Button("Cancel") {
authenticator.cancelSignIn()
Expand All @@ -42,6 +48,7 @@ struct AddGitHubPipelineSheet: View {
Task {
if await authenticator.signInAtGitHub() {
await authenticator.waitForToken()
tokenInput = authenticator.token ?? ""
}
}
}
Expand Down Expand Up @@ -152,6 +159,7 @@ struct AddGitHubPipelineSheet: View {
.padding()
.onAppear() {
authenticator.fetchTokenFromKeychain()
tokenInput = authenticator.token ?? ""
}
.onDisappear() {
authenticator.storeTokenInKeychain()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ class GitHubAuthenticator: ObservableObject {
tokenDescription = token ?? ""
}

func setToken(_ newToken: String) {
let trimmed = newToken.trimmingCharacters(in: .whitespacesAndNewlines)
token = trimmed.isEmpty ? nil : trimmed
tokenDescription = token ?? ""
}

func openApplicationsOnWebsite() {
NSWorkspace.shared.open(GitHubAPI.applicationsUrl())
}
Expand Down