Skip to content

Commit d321c73

Browse files
committed
resource/gitlab_project: Add ci_default_git_depth attribute
Closes: #1140
1 parent 334b041 commit d321c73

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

docs/resources/project.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ resource "gitlab_project" "peters_repo" {
8686
- `build_timeout` (Number) The maximum amount of time, in seconds, that a job can run.
8787
- `builds_access_level` (String) Set the builds access level. Valid values are `disabled`, `private`, `enabled`.
8888
- `ci_config_path` (String) Custom Path to CI config file.
89+
- `ci_default_git_depth` (Number) Default number of revisions for shallow cloning.
8990
- `ci_forward_deployment_enabled` (Boolean) When a new deployment job starts, skip older deployment jobs that are still pending.
9091
- `container_expiration_policy` (Block List, Max: 1) Set the image cleanup policy for this project. **Note**: this field is sometimes named `container_expiration_policy_attributes` in the GitLab Upstream API. (see [below for nested schema](#nestedblock--container_expiration_policy))
9192
- `container_registry_access_level` (String) Set visibility of container registry, for this project. Valid values are `disabled`, `private`, `enabled`.

internal/provider/resource_gitlab_project.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
585585
Type: schema.TypeString,
586586
Optional: true,
587587
},
588+
"ci_default_git_depth": {
589+
Description: "Default number of revisions for shallow cloning.",
590+
Type: schema.TypeInt,
591+
Optional: true,
592+
Computed: true,
593+
},
588594
}
589595

590596
var validContainerExpirationPolicyAttributesCadenceValues = []string{
@@ -756,6 +762,8 @@ func resourceGitlabProjectSetToState(ctx context.Context, client *gitlab.Client,
756762
//Note: This field is deprecated and will always be an empty string starting in GitLab 15.0.
757763
d.Set("build_coverage_regex", project.BuildCoverageRegex)
758764

765+
d.Set("ci_default_git_depth", project.CIDefaultGitDepth)
766+
759767
return nil
760768
}
761769

@@ -1146,6 +1154,10 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
11461154
editProjectOptions.MergeTrainsEnabled = gitlab.Bool(v.(bool))
11471155
}
11481156

1157+
if v, ok := d.GetOk("ci_default_git_depth"); ok {
1158+
editProjectOptions.CIDefaultGitDepth = gitlab.Int(v.(int))
1159+
}
1160+
11491161
if (editProjectOptions != gitlab.EditProjectOptions{}) {
11501162
if _, _, err := client.Projects.EditProject(d.Id(), &editProjectOptions, gitlab.WithContext(ctx)); err != nil {
11511163
return diag.Errorf("Could not update project %q: %s", d.Id(), err)
@@ -1461,6 +1473,10 @@ func resourceGitlabProjectUpdate(ctx context.Context, d *schema.ResourceData, me
14611473
options.MergeCommitTemplate = gitlab.String(d.Get("merge_commit_template").(string))
14621474
}
14631475

1476+
if d.HasChange("ci_default_git_depth") {
1477+
options.CIDefaultGitDepth = gitlab.Int(d.Get("ci_default_git_depth").(int))
1478+
}
1479+
14641480
if *options != (gitlab.EditProjectOptions{}) {
14651481
log.Printf("[DEBUG] update gitlab project %s", d.Id())
14661482
_, _, err := client.Projects.EditProject(d.Id(), options, gitlab.WithContext(ctx))

internal/provider/resource_gitlab_project_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,7 @@ resource "gitlab_project" "foo" {
16231623
wiki_access_level = "enabled"
16241624
squash_commit_template = "hello squash"
16251625
merge_commit_template = "hello merge"
1626+
ci_default_git_depth = 42
16261627
}
16271628
`, rInt, rInt, defaultBranchStatement)
16281629
}
@@ -1723,6 +1724,7 @@ resource "gitlab_project" "foo" {
17231724
wiki_access_level = "disabled"
17241725
squash_commit_template = "goodby squash"
17251726
merge_commit_template = "goodby merge"
1727+
ci_default_git_depth = 84
17261728
}
17271729
`, rInt, rInt)
17281730
}
@@ -2061,6 +2063,7 @@ resource "gitlab_project" "foo" {
20612063
wiki_access_level = "enabled"
20622064
squash_commit_template = "hello squash"
20632065
merge_commit_template = "hello merge"
2066+
ci_default_git_depth = 42
20642067
20652068
# EE features
20662069
approvals_before_merge = 2

0 commit comments

Comments
 (0)