summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-29 10:28:49 +0300
committerPaul Buetow <paul@buetow.org>2026-05-29 10:28:49 +0300
commitf7a2c1168a81d879c1307b38b679614fc0752e42 (patch)
tree7d5bf397b9baff16d7608ed994db1b7df99224c7
parentde3a697796d2e6820e8f19890252ace08bc0ef63 (diff)
refactor(cli): use org host helpers in forge client dispatch (lq)
-rw-r--r--internal/cli/forge_client.go6
-rw-r--r--internal/cli/forge_client_test.go75
2 files changed, 63 insertions, 18 deletions
diff --git a/internal/cli/forge_client.go b/internal/cli/forge_client.go
index d602803..609b75f 100644
--- a/internal/cli/forge_client.go
+++ b/internal/cli/forge_client.go
@@ -8,11 +8,11 @@ import (
)
func newRepoClientForOrg(org config.Organization) (forge.RepoClient, bool) {
- switch org.Host {
- case "git@github.com":
+ switch {
+ case org.IsGitHub():
client := github.NewClient(org.GitHubToken, org.Name)
return client, true
- case "git@codeberg.org":
+ case org.IsCodeberg():
client := codeberg.NewClient(org.CodebergToken, org.Name)
return client, true
default:
diff --git a/internal/cli/forge_client_test.go b/internal/cli/forge_client_test.go
index 9aff10b..6ce220a 100644
--- a/internal/cli/forge_client_test.go
+++ b/internal/cli/forge_client_test.go
@@ -37,31 +37,76 @@ func TestNewRepoClientForOrg(t *testing.T) {
}
})
- t.Run("unsupported", func(t *testing.T) {
- client, ok := newRepoClientForOrg(config.Organization{
- Host: "ssh://example.org",
- Name: "acme",
- })
- if ok {
- t.Fatal("expected unsupported host")
+ t.Run("github host variants", func(t *testing.T) {
+ t.Parallel()
+
+ variantHosts := []string{
+ "ssh://github.com",
+ "git@github.company.com",
+ "git@github.com:acme",
+ "https://github.com",
}
- if client != nil {
- t.Fatal("expected nil client for unsupported host")
+
+ for _, host := range variantHosts {
+ host := host
+ t.Run(host, func(t *testing.T) {
+ t.Parallel()
+
+ client, ok := newRepoClientForOrg(config.Organization{
+ Host: host,
+ Name: "acme",
+ GitHubToken: "token",
+ })
+ if !ok {
+ t.Fatalf("expected supported github host variant %q", host)
+ }
+ if !client.HasToken() {
+ t.Fatalf("expected github client token for host variant %q", host)
+ }
+ })
}
})
- t.Run("unsupported near miss hosts", func(t *testing.T) {
+ t.Run("codeberg host variants", func(t *testing.T) {
t.Parallel()
- nearMissHosts := []string{
- "ssh://github.com",
- "git@github.company.com",
- "git@github.com:acme",
+ variantHosts := []string{
"https://codeberg.org",
+ "ssh://codeberg.org",
+ "git@codeberg.org:acme",
"git@codeberg.org.example",
}
- for _, host := range nearMissHosts {
+ for _, host := range variantHosts {
+ host := host
+ t.Run(host, func(t *testing.T) {
+ t.Parallel()
+
+ client, ok := newRepoClientForOrg(config.Organization{
+ Host: host,
+ Name: "acme",
+ CodebergToken: "token",
+ })
+ if !ok {
+ t.Fatalf("expected supported codeberg host variant %q", host)
+ }
+ if !client.HasToken() {
+ t.Fatalf("expected codeberg client token for host variant %q", host)
+ }
+ })
+ }
+ })
+
+ t.Run("unsupported hosts", func(t *testing.T) {
+ t.Parallel()
+
+ unsupportedHosts := []string{
+ "ssh://example.org",
+ "git@gitlab.com",
+ "file:///srv/git",
+ }
+
+ for _, host := range unsupportedHosts {
host := host
t.Run(host, func(t *testing.T) {
t.Parallel()