Skip to content

Commit 3c55c75

Browse files
committed
fix(config): add support for git repository inheritance
1 parent 5bc5d58 commit 3c55c75

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

internal/config.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ func NewVercelConfig() VercelConfig {
1717
return VercelConfig{
1818

1919
ProjectConfig: ProjectConfig{
20-
GitRepository: GitRepository{
21-
ProductionBranch: "main",
22-
},
2320
PasswordProtection: PasswordProtection{
2421
ProtectProduction: true,
2522
},
@@ -113,8 +110,14 @@ func (c *ProjectConfig) extendConfig(o *ProjectConfig) *ProjectConfig {
113110
cfg.ManualProductionDeployment = c.ManualProductionDeployment
114111
}
115112

116-
if c.GitRepository.Type != "" || c.GitRepository.Repo != "" {
117-
cfg.GitRepository = c.GitRepository
113+
if c.GitRepository.Type != "" || c.GitRepository.Repo != "" || c.GitRepository.ProductionBranch != "" {
114+
result := c.GitRepository.extendConfig(&o.GitRepository)
115+
if result != nil {
116+
cfg.GitRepository = *result
117+
} else {
118+
cfg.GitRepository = c.GitRepository
119+
}
120+
118121
}
119122

120123
if c.ProtectionBypassForAutomation {
@@ -153,6 +156,32 @@ type GitRepository struct {
153156
Repo string `mapstructure:"repo"`
154157
}
155158

159+
func (c *GitRepository) extendConfig(o *GitRepository) *GitRepository {
160+
if o != nil && o != (&GitRepository{}) {
161+
cfg := &GitRepository{
162+
ProductionBranch: o.ProductionBranch,
163+
Type: o.Type,
164+
Repo: o.Repo,
165+
}
166+
167+
if c.ProductionBranch != "" {
168+
cfg.ProductionBranch = c.ProductionBranch
169+
}
170+
171+
if c.Type != "" {
172+
cfg.Type = c.Type
173+
}
174+
175+
if c.Repo != "" {
176+
cfg.Repo = c.Repo
177+
}
178+
179+
return cfg
180+
}
181+
182+
return c
183+
}
184+
156185
type PasswordProtection struct {
157186
Password string `mapstructure:"password"`
158187
ProtectProduction bool `mapstructure:"protect_production"`

internal/plugin_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package internal
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -194,6 +195,11 @@ func TestSiteComponentInheritance(t *testing.T) {
194195
"serverless_function_region": "iad1",
195196
"manual_production_deployment": false,
196197
"environment_variables": siteVariables,
198+
"git_repository": map[string]any{
199+
"production_branch": "main",
200+
"type": "github",
201+
"repo": "mach-composer/my-project",
202+
},
197203
},
198204
}
199205

@@ -211,6 +217,9 @@ func TestSiteComponentInheritance(t *testing.T) {
211217
"serverless_function_region": "fra1",
212218
"manual_production_deployment": true,
213219
"environment_variables": componentVariables,
220+
"git_repository": map[string]any{
221+
"production_branch": "production",
222+
},
214223
},
215224
}
216225

@@ -229,6 +238,7 @@ func TestSiteComponentInheritance(t *testing.T) {
229238
assert.Contains(t, component.Variables, "vercel_project_manual_production_deployment = true")
230239
assert.Contains(t, component.Variables, "key = \"TEST_ENVIRONMENT_VARIABLE_2\"")
231240
assert.Contains(t, component.Variables, "key = \"TEST_ENVIRONMENT_VARIABLE_3\"")
241+
assert.Contains(t, component.Variables, "production_branch = \"production\"")
232242

233243
}
234244

@@ -321,6 +331,8 @@ func TestCompleteInheritance(t *testing.T) {
321331

322332
component, err := plugin.RenderTerraformComponent("my-site", "test-component")
323333

334+
fmt.Println(component)
335+
324336
assert.Contains(t, component.Variables, "vercel_project_serverless_function_region = \"fra1\"")
325337
assert.Contains(t, component.Variables, "type = \"github\"")
326338
assert.Contains(t, component.Variables, "production_branch = \"production\"")

0 commit comments

Comments
 (0)