Skip to content

Commit 2c92c4c

Browse files
committed
chore: extract git operations to separate package
1 parent b272a97 commit 2c92c4c

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

envbuilder.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"syscall"
2525
"time"
2626

27+
"github.com/coder/envbuilder/git"
2728
"github.com/coder/envbuilder/options"
2829

2930
"github.com/GoogleContainerTools/kaniko/pkg/config"
@@ -204,7 +205,7 @@ func Run(ctx context.Context, opts options.Options) error {
204205
}
205206
}()
206207

207-
cloneOpts := CloneRepoOptions{
208+
cloneOpts := git.CloneRepoOptions{
208209
Path: opts.WorkspaceFolder,
209210
Storage: opts.Filesystem,
210211
Insecure: opts.Insecure,
@@ -214,15 +215,15 @@ func Run(ctx context.Context, opts options.Options) error {
214215
CABundle: caBundle,
215216
}
216217

217-
cloneOpts.RepoAuth = SetupRepoAuth(&opts)
218+
cloneOpts.RepoAuth = git.SetupRepoAuth(&opts)
218219
if opts.GitHTTPProxyURL != "" {
219220
cloneOpts.ProxyOptions = transport.ProxyOptions{
220221
URL: opts.GitHTTPProxyURL,
221222
}
222223
}
223224
cloneOpts.RepoURL = opts.GitURL
224225

225-
cloned, fallbackErr = CloneRepo(ctx, cloneOpts)
226+
cloned, fallbackErr = git.CloneRepo(ctx, cloneOpts)
226227
if fallbackErr == nil {
227228
if cloned {
228229
endStage("📦 Cloned repository!")

git.go renamed to git/git.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package envbuilder
1+
package git
22

33
import (
44
"context"

git_test.go renamed to git/git_test.go

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package envbuilder_test
1+
package git_test
22

33
import (
44
"context"
@@ -12,9 +12,10 @@ import (
1212
"regexp"
1313
"testing"
1414

15+
"github.com/coder/envbuilder/git"
16+
1517
"github.com/coder/envbuilder/options"
1618

17-
"github.com/coder/envbuilder"
1819
"github.com/coder/envbuilder/internal/log"
1920
"github.com/coder/envbuilder/testutil/gittest"
2021
"github.com/coder/envbuilder/testutil/mwtest"
@@ -90,7 +91,7 @@ func TestCloneRepo(t *testing.T) {
9091
clientFS := memfs.New()
9192
// A repo already exists!
9293
_ = gittest.NewRepo(t, clientFS)
93-
cloned, err := envbuilder.CloneRepo(context.Background(), envbuilder.CloneRepoOptions{
94+
cloned, err := git.CloneRepo(context.Background(), git.CloneRepoOptions{
9495
Path: "/",
9596
RepoURL: srv.URL,
9697
Storage: clientFS,
@@ -108,7 +109,7 @@ func TestCloneRepo(t *testing.T) {
108109
srv := httptest.NewServer(authMW(gittest.NewServer(srvFS)))
109110
clientFS := memfs.New()
110111

111-
cloned, err := envbuilder.CloneRepo(context.Background(), envbuilder.CloneRepoOptions{
112+
cloned, err := git.CloneRepo(context.Background(), git.CloneRepoOptions{
112113
Path: "/workspace",
113114
RepoURL: srv.URL,
114115
Storage: clientFS,
@@ -145,7 +146,7 @@ func TestCloneRepo(t *testing.T) {
145146
authURL.User = url.UserPassword(tc.username, tc.password)
146147
clientFS := memfs.New()
147148

148-
cloned, err := envbuilder.CloneRepo(context.Background(), envbuilder.CloneRepoOptions{
149+
cloned, err := git.CloneRepo(context.Background(), git.CloneRepoOptions{
149150
Path: "/workspace",
150151
RepoURL: authURL.String(),
151152
Storage: clientFS,
@@ -184,7 +185,7 @@ func TestCloneRepoSSH(t *testing.T) {
184185
gitURL := tr.String()
185186
clientFS := memfs.New()
186187

187-
cloned, err := envbuilder.CloneRepo(context.Background(), envbuilder.CloneRepoOptions{
188+
cloned, err := git.CloneRepo(context.Background(), git.CloneRepoOptions{
188189
Path: "/workspace",
189190
RepoURL: gitURL,
190191
Storage: clientFS,
@@ -216,7 +217,7 @@ func TestCloneRepoSSH(t *testing.T) {
216217
clientFS := memfs.New()
217218

218219
anotherKey := randKeygen(t)
219-
cloned, err := envbuilder.CloneRepo(context.Background(), envbuilder.CloneRepoOptions{
220+
cloned, err := git.CloneRepo(context.Background(), git.CloneRepoOptions{
220221
Path: "/workspace",
221222
RepoURL: gitURL,
222223
Storage: clientFS,
@@ -246,7 +247,7 @@ func TestCloneRepoSSH(t *testing.T) {
246247
gitURL := tr.String()
247248
clientFS := memfs.New()
248249

249-
cloned, err := envbuilder.CloneRepo(context.Background(), envbuilder.CloneRepoOptions{
250+
cloned, err := git.CloneRepo(context.Background(), git.CloneRepoOptions{
250251
Path: "/workspace",
251252
RepoURL: gitURL,
252253
Storage: clientFS,
@@ -270,7 +271,7 @@ func TestSetupRepoAuth(t *testing.T) {
270271
opts := &options.Options{
271272
Logger: testLog(t),
272273
}
273-
auth := envbuilder.SetupRepoAuth(opts)
274+
auth := git.SetupRepoAuth(opts)
274275
require.Nil(t, auth)
275276
})
276277

@@ -279,7 +280,7 @@ func TestSetupRepoAuth(t *testing.T) {
279280
GitURL: "http://host.tld/repo",
280281
Logger: testLog(t),
281282
}
282-
auth := envbuilder.SetupRepoAuth(opts)
283+
auth := git.SetupRepoAuth(opts)
283284
require.Nil(t, auth)
284285
})
285286

@@ -290,7 +291,7 @@ func TestSetupRepoAuth(t *testing.T) {
290291
GitPassword: "pass",
291292
Logger: testLog(t),
292293
}
293-
auth := envbuilder.SetupRepoAuth(opts)
294+
auth := git.SetupRepoAuth(opts)
294295
ba, ok := auth.(*githttp.BasicAuth)
295296
require.True(t, ok)
296297
require.Equal(t, opts.GitUsername, ba.Username)
@@ -304,7 +305,7 @@ func TestSetupRepoAuth(t *testing.T) {
304305
GitPassword: "pass",
305306
Logger: testLog(t),
306307
}
307-
auth := envbuilder.SetupRepoAuth(opts)
308+
auth := git.SetupRepoAuth(opts)
308309
ba, ok := auth.(*githttp.BasicAuth)
309310
require.True(t, ok)
310311
require.Equal(t, opts.GitUsername, ba.Username)
@@ -318,7 +319,7 @@ func TestSetupRepoAuth(t *testing.T) {
318319
GitSSHPrivateKeyPath: kPath,
319320
Logger: testLog(t),
320321
}
321-
auth := envbuilder.SetupRepoAuth(opts)
322+
auth := git.SetupRepoAuth(opts)
322323
_, ok := auth.(*gitssh.PublicKeys)
323324
require.True(t, ok)
324325
})
@@ -330,7 +331,7 @@ func TestSetupRepoAuth(t *testing.T) {
330331
GitSSHPrivateKeyPath: kPath,
331332
Logger: testLog(t),
332333
}
333-
auth := envbuilder.SetupRepoAuth(opts)
334+
auth := git.SetupRepoAuth(opts)
334335
_, ok := auth.(*gitssh.PublicKeys)
335336
require.True(t, ok)
336337
})
@@ -343,7 +344,7 @@ func TestSetupRepoAuth(t *testing.T) {
343344
GitSSHPrivateKeyPath: kPath,
344345
Logger: testLog(t),
345346
}
346-
auth := envbuilder.SetupRepoAuth(opts)
347+
auth := git.SetupRepoAuth(opts)
347348
_, ok := auth.(*gitssh.PublicKeys)
348349
require.True(t, ok)
349350
})
@@ -356,7 +357,7 @@ func TestSetupRepoAuth(t *testing.T) {
356357
GitUsername: "user",
357358
Logger: testLog(t),
358359
}
359-
auth := envbuilder.SetupRepoAuth(opts)
360+
auth := git.SetupRepoAuth(opts)
360361
_, ok := auth.(*gitssh.PublicKeys)
361362
require.True(t, ok)
362363
})
@@ -368,7 +369,7 @@ func TestSetupRepoAuth(t *testing.T) {
368369
GitSSHPrivateKeyPath: kPath,
369370
Logger: testLog(t),
370371
}
371-
auth := envbuilder.SetupRepoAuth(opts)
372+
auth := git.SetupRepoAuth(opts)
372373
pk, ok := auth.(*gitssh.PublicKeys)
373374
require.True(t, ok)
374375
require.NotNil(t, pk.Signer)
@@ -382,7 +383,7 @@ func TestSetupRepoAuth(t *testing.T) {
382383
GitURL: "ssh://[email protected]:repo/path",
383384
Logger: testLog(t),
384385
}
385-
auth := envbuilder.SetupRepoAuth(opts)
386+
auth := git.SetupRepoAuth(opts)
386387
require.Nil(t, auth) // TODO: actually test SSH_AUTH_SOCK
387388
})
388389
}

0 commit comments

Comments
 (0)