Add configurable SSH clone prefix

6831e2e70e097cb55f008277b3d4e95e82a83d1c
Alexis Sellier committed ago 1 parent 09eea184
handler.go +1 -1
278 278
		Tree:       tree,
279 279
		Readme:     readme,
280 280
		LastCommit: lastCommit,
281 281
		ActiveBlob: blob,
282 282
		ActivePath: activePath,
283 -
		CloneSSH:   "git@radiant.computer:radiant/" + repo.Name + ".git",
283 +
		CloneSSH:   s.sshClonePrefix + repo.Name + ".git",
284 284
		CloneHTTPS: cloneHTTPS,
285 285
	}
286 286
	s.tmpl.render(w, "home", pd)
287 287
}
288 288
handler_test.go +20 -8
88 88
		t.Fatalf("openDB: %v", err)
89 89
	}
90 90
	t.Cleanup(func() { db.Close() })
91 91
92 92
	return &server{
93 -
		repos:       map[string]*RepoInfo{"testrepo": repo},
94 -
		sorted:      []string{"testrepo"},
95 -
		tmpl:        tmpl,
96 -
		db:          db,
97 -
		title:       "Test Forge",
98 -
		description: "test site description",
99 -
		baseURL:     "",
100 -
		scanPath:    tmpDir,
93 +
		repos:          map[string]*RepoInfo{"testrepo": repo},
94 +
		sorted:         []string{"testrepo"},
95 +
		tmpl:           tmpl,
96 +
		db:             db,
97 +
		title:          "Test Forge",
98 +
		description:    "test site description",
99 +
		baseURL:        "",
100 +
		sshClonePrefix: "git@code.cloudhead.io:cloudhead/",
101 +
		scanPath:       tmpDir,
101 102
	}
102 103
}
103 104
104 105
func gitRun(t *testing.T, dir string, args ...string) {
105 106
	t.Helper()
382 383
	assertContains(t, w, "testrepo.git")
383 384
	// No footer on repo pages
384 385
	assertNotContains(t, w, "Powered by")
385 386
}
386 387
388 +
func TestSummary_CloneSSH(t *testing.T) {
389 +
	srv := testServer(t)
390 +
	repo := srv.repos["testrepo"]
391 +
	repo.Name = "example"
392 +
	srv.repos = map[string]*RepoInfo{"example": repo}
393 +
394 +
	w := get(t, srv, "/example/")
395 +
	assertCode(t, w, 200)
396 +
	assertContains(t, w, "git@code.cloudhead.io:cloudhead/example.git")
397 +
}
398 +
387 399
func TestSummary_NoTrailingSlash(t *testing.T) {
388 400
	srv := testServer(t)
389 401
	w := get(t, srv, "/testrepo")
390 402
	assertCode(t, w, 200)
391 403
	assertContains(t, w, "testrepo")
file.go +0 -0
old.go +0 -0
new.go +0 -0
image.png +0 -0
file.go +0 -0
a.go +0 -0
b.go +0 -0
main.go +27 -24
11 11
	"sort"
12 12
	"strings"
13 13
)
14 14
15 15
type server struct {
16 -
	repos       map[string]*RepoInfo
17 -
	sorted      []string
18 -
	tmpl        *templateSet
19 -
	db          *sql.DB
20 -
	title       string
21 -
	description string
22 -
	baseURL     string
23 -
	scanPath    string
24 -
	username    string
25 -
	password    string
26 -
	dev         bool
27 -
	discussions bool
16 +
	repos          map[string]*RepoInfo
17 +
	sorted         []string
18 +
	tmpl           *templateSet
19 +
	db             *sql.DB
20 +
	title          string
21 +
	description    string
22 +
	baseURL        string
23 +
	sshClonePrefix string
24 +
	scanPath       string
25 +
	username       string
26 +
	password       string
27 +
	dev            bool
28 +
	discussions    bool
28 29
}
29 30
30 31
func main() {
31 32
	listen := flag.String("listen", ":8080", "listen address")
32 33
	scanPath := flag.String("scan-path", ".", "path to scan for git repos")
33 34
	title := flag.String("title", "radiant code repositories", "site title")
34 35
	description := flag.String("description", "", "site description shown on the index page")
35 36
	baseURL := flag.String("base-url", "", "base URL prefix (e.g. /git)")
37 +
	sshClonePrefix := flag.String("ssh-clone-prefix", "git@radiant.computer:radiant/", "SSH clone URL prefix")
36 38
	nonBare := flag.Bool("non-bare", false, "also scan for non-bare repos (dirs containing .git)")
37 39
	username := flag.String("username", "", "HTTP basic auth username (requires -password)")
38 40
	password := flag.String("password", "", "HTTP basic auth password (requires -username)")
39 41
	dbPath := flag.String("db-path", "./forge.db", "path to SQLite database for discussions")
40 42
	discussions := flag.Bool("discussions", false, "enable discussions feature")
76 78
		}
77 79
		defer db.Close()
78 80
	}
79 81
80 82
	srv := &server{
81 -
		repos:       repos,
82 -
		sorted:      sorted,
83 -
		tmpl:        tmpl,
84 -
		db:          db,
85 -
		title:       *title,
86 -
		description: *description,
87 -
		baseURL:     strings.TrimRight(*baseURL, "/"),
88 -
		scanPath:    abs,
89 -
		username:    *username,
90 -
		password:    *password,
91 -
		dev:         *dev,
92 -
		discussions: *discussions,
83 +
		repos:          repos,
84 +
		sorted:         sorted,
85 +
		tmpl:           tmpl,
86 +
		db:             db,
87 +
		title:          *title,
88 +
		description:    *description,
89 +
		baseURL:        strings.TrimRight(*baseURL, "/"),
90 +
		sshClonePrefix: *sshClonePrefix,
91 +
		scanPath:       abs,
92 +
		username:       *username,
93 +
		password:       *password,
94 +
		dev:            *dev,
95 +
		discussions:    *discussions,
93 96
	}
94 97
95 98
	mux := http.NewServeMux()
96 99
	mux.HandleFunc("/style.css", srv.serveCSS)
97 100
	mux.HandleFunc("/radiant.svg", srv.serveLogo)