Skip to content

Commit 8922dba

Browse files
committed
Move loadGitDetails mutator to Initialize phase
This will require API call and we want to keep Load phase fast.
1 parent 7b9726d commit 8922dba

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

bundle/config/mutator/mutator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func DefaultMutators() []bundle.Mutator {
2626
ComputeIdToClusterId(),
2727
InitializeVariables(),
2828
DefineDefaultTarget(),
29-
LoadGitDetails(),
3029
pythonmutator.PythonMutator(pythonmutator.PythonMutatorPhaseLoad),
3130

3231
// Note: This mutator must run before the target overrides are merged.

bundle/phases/initialize.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func Initialize() bundle.Mutator {
3939
mutator.MergePipelineClusters(),
4040
mutator.InitializeWorkspaceClient(),
4141
mutator.PopulateCurrentUser(),
42+
mutator.LoadGitDetails(),
4243

4344
mutator.DefineDefaultWorkspaceRoot(),
4445
mutator.ExpandWorkspaceRoot(),

bundle/tests/environment_git_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import (
55
"strings"
66
"testing"
77

8+
"github.com/databricks/cli/bundle/config/mutator"
89
"github.com/stretchr/testify/assert"
910
)
1011

1112
func TestGitAutoLoadWithEnvironment(t *testing.T) {
12-
b := load(t, "./environments_autoload_git")
13+
b := load(t, "./environments_autoload_git", mutator.LoadGitDetails())
1314
assert.True(t, b.Config.Bundle.Git.Inferred)
1415
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
1516
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
1617
}
1718

1819
func TestGitManuallySetBranchWithEnvironment(t *testing.T) {
19-
b := loadTarget(t, "./environments_autoload_git", "production")
20+
b := loadTarget(t, "./environments_autoload_git", "production", mutator.LoadGitDetails())
2021
assert.False(t, b.Config.Bundle.Git.Inferred)
2122
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
2223
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")

bundle/tests/git_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ import (
1212
"github.com/stretchr/testify/assert"
1313
)
1414

15-
func TestGitAutoLoad(t *testing.T) {
16-
b := load(t, "./autoload_git")
17-
assert.True(t, b.Config.Bundle.Git.Inferred)
18-
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
19-
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
20-
}
21-
2215
func TestGitManuallySetBranch(t *testing.T) {
23-
b := loadTarget(t, "./autoload_git", "production")
16+
b := loadTarget(t, "./autoload_git", "production", mutator.LoadGitDetails())
2417
assert.False(t, b.Config.Bundle.Git.Inferred)
2518
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
2619
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
@@ -33,7 +26,7 @@ func TestGitBundleBranchValidation(t *testing.T) {
3326
git.GitDirectoryName = ".git"
3427
})
3528

36-
b := load(t, "./git_branch_validation")
29+
b := load(t, "./git_branch_validation", mutator.LoadGitDetails())
3730
assert.False(t, b.Config.Bundle.Git.Inferred)
3831
assert.Equal(t, "feature-a", b.Config.Bundle.Git.Branch)
3932
assert.Equal(t, "feature-b", b.Config.Bundle.Git.ActualBranch)

bundle/tests/loader.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,33 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18-
func load(t *testing.T, path string) *bundle.Bundle {
18+
func load(t *testing.T, path string, mutators ...bundle.Mutator) *bundle.Bundle {
1919
ctx := context.Background()
2020
b, err := bundle.Load(ctx, path)
2121
require.NoError(t, err)
2222
diags := bundle.Apply(ctx, b, phases.Load())
2323
require.NoError(t, diags.Error())
24+
for _, m := range mutators {
25+
diags := bundle.Apply(ctx, b, m)
26+
require.NoError(t, diags.Error())
27+
}
2428
return b
2529
}
2630

27-
func loadTarget(t *testing.T, path, env string) *bundle.Bundle {
28-
b, diags := loadTargetWithDiags(path, env)
31+
func loadTarget(t *testing.T, path, env string, mutators ...bundle.Mutator) *bundle.Bundle {
32+
b, diags := loadTargetWithDiags(path, env, mutators...)
2933
require.NoError(t, diags.Error())
3034
return b
3135
}
3236

33-
func loadTargetWithDiags(path, env string) (*bundle.Bundle, diag.Diagnostics) {
37+
func loadTargetWithDiags(path, env string, mutators ...bundle.Mutator) (*bundle.Bundle, diag.Diagnostics) {
3438
ctx := context.Background()
3539
b, err := bundle.Load(ctx, path)
3640
if err != nil {
3741
return nil, diag.FromErr(err)
3842
}
3943

40-
diags := bundle.Apply(ctx, b, bundle.Seq(
44+
seq := []bundle.Mutator{
4145
phases.LoadNamedTarget(env),
4246
mutator.RewriteSyncPaths(),
4347
mutator.SyncDefaultPath(),
@@ -46,7 +50,10 @@ func loadTargetWithDiags(path, env string) (*bundle.Bundle, diag.Diagnostics) {
4650
mutator.MergeJobParameters(),
4751
mutator.MergeJobTasks(),
4852
mutator.MergePipelineClusters(),
49-
))
53+
}
54+
seq = append(seq, mutators...)
55+
diags := bundle.Apply(ctx, b, bundle.Seq(seq...))
56+
5057
return b, diags
5158
}
5259

0 commit comments

Comments
 (0)