Skip to content
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Default code owners
* @martin-alexander-msc
4 changes: 3 additions & 1 deletion Sources/GitwCore/GitwApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public struct GitwApp {
throw GitwError.usage("login requires --email <email>")
}

let username = try ttyReadLine("GitHub username: ")
// `--name` is the GitHub username (and also the commit author name we pass via env).
// Do not prompt for username again.
let username = name
let token = try ttyReadSecret("GitHub personal access token: ")

let profile = GitwProfile(githubUsername: username, token: token, gitName: name, gitEmail: email)
Expand Down
5 changes: 3 additions & 2 deletions Sources/GitwCore/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public struct GitwProfile: Sendable, Codable, Equatable {
}

public enum KeychainStore {
// We deliberately keep this fixed; gitw only supports GitHub HTTPS.
public static let server = "github.com"
// Keychain namespace. We still authenticate against github.com, but we store credentials
// under a dedicated Keychain server name to avoid collisions with other GitHub tooling.
public static let server = "gitw.github.com"
private static let service = "gitw"

/// Load credentials for a given alias.
Expand Down
11 changes: 6 additions & 5 deletions Tests/GitwCoreTests/GitwAppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,22 @@ struct GitwAppTests {

let status = try app.run(
.login(alias: "work", repoURL: "https://github.com/OWNER/REPO.git"),
ttyReadLine: { _ in "real-user" },
ttyReadLine: { _ in throw GitwError.io("unexpected ttyReadLine") },
ttyReadSecret: { _ in "tok" },
name: "Real Name",
name: "real-user",
email: "real@example.com"
)

#expect(status == 0)
#expect(git.calls.count == 1)
#expect(git.calls[0].args == ["ls-remote", "https://github.com/OWNER/REPO.git"])
#expect(git.calls[0].githubUsername == "real-user")
#expect(git.calls[0].name == "Real Name")
#expect(git.calls[0].name == "real-user")
#expect(git.calls[0].email == "real@example.com")
#expect(kc.saved.count == 1)
#expect(kc.saved[0].alias == "work")
#expect(kc.saved[0].profile.githubUsername == "real-user")
#expect(kc.saved[0].profile.gitName == "real-user")
}

@Test
Expand All @@ -87,9 +88,9 @@ struct GitwAppTests {
do {
_ = try app.run(
.login(alias: "work", repoURL: "https://github.com/OWNER/REPO.git"),
ttyReadLine: { _ in "real-user" },
ttyReadLine: { _ in throw GitwError.io("unexpected ttyReadLine") },
ttyReadSecret: { _ in "tok" },
name: "Real Name",
name: "real-user",
email: "real@example.com"
)
Issue.record("Expected login to fail")
Expand Down
Loading