Skip to content

Commit b5a42dd

Browse files
authored
Merge pull request #1146 from timofurrer/feature/ci_default_git_depth
`gitlab_project`: Add `ci_default_git_depth` attribute
2 parents bcbfb1c + 728cb94 commit b5a42dd

File tree

7 files changed

+36
-0
lines changed

7 files changed

+36
-0
lines changed

docs/data-sources/project.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ data "gitlab_project" "example" {
3030

3131
### Optional
3232

33+
- `ci_default_git_depth` (Number) Default number of revisions for shallow cloning.
3334
- `id` (String) The integer or path with namespace that uniquely identifies the project within the gitlab install.
3435
- `path_with_namespace` (String) The path of the repository with namespace.
3536
- `public_builds` (Boolean) If true, jobs can be viewed by non-project members.

docs/data-sources/projects.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Read-Only:
9393
- `build_timeout` (Number)
9494
- `builds_access_level` (String)
9595
- `ci_config_path` (String)
96+
- `ci_default_git_depth` (Number)
9697
- `ci_forward_deployment_enabled` (Boolean)
9798
- `container_expiration_policy` (List of Object) (see [below for nested schema](#nestedobjatt--projects--container_expiration_policy))
9899
- `container_registry_access_level` (String)

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/data_source_gitlab_project.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@ var _ = registerDataSource("gitlab_project", func() *schema.Resource {
289289
Type: schema.TypeString,
290290
Computed: true,
291291
},
292+
"ci_default_git_depth": {
293+
Description: "Default number of revisions for shallow cloning.",
294+
Type: schema.TypeInt,
295+
Optional: true,
296+
Computed: true,
297+
},
292298
"push_rules": {
293299
Description: "Push rules for the project.",
294300
Type: schema.TypeList,
@@ -429,6 +435,7 @@ func dataSourceGitlabProjectRead(ctx context.Context, d *schema.ResourceData, me
429435
d.Set("wiki_access_level", string(found.WikiAccessLevel))
430436
d.Set("squash_commit_template", found.SquashCommitTemplate)
431437
d.Set("merge_commit_template", found.MergeCommitTemplate)
438+
d.Set("ci_default_git_depth", found.CIDefaultGitDepth)
432439

433440
log.Printf("[DEBUG] Reading Gitlab project %q push rules", d.Id())
434441

internal/provider/data_source_gitlab_projects.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func flattenProjects(projects []*gitlab.Project) (values []map[string]interface{
190190
"wiki_access_level": string(project.WikiAccessLevel),
191191
"squash_commit_template": project.SquashCommitTemplate,
192192
"merge_commit_template": project.MergeCommitTemplate,
193+
"ci_default_git_depth": project.CIDefaultGitDepth,
193194
}
194195
values = append(values, v)
195196
}
@@ -944,6 +945,12 @@ var _ = registerDataSource("gitlab_projects", func() *schema.Resource {
944945
Type: schema.TypeString,
945946
Computed: true,
946947
},
948+
"ci_default_git_depth": {
949+
Description: "Default number of revisions for shallow cloning.",
950+
Type: schema.TypeInt,
951+
Optional: true,
952+
Computed: true,
953+
},
947954
},
948955
},
949956
},

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
@@ -1620,6 +1620,7 @@ resource "gitlab_project" "foo" {
16201620
wiki_access_level = "enabled"
16211621
squash_commit_template = "hello squash"
16221622
merge_commit_template = "hello merge"
1623+
ci_default_git_depth = 42
16231624
}
16241625
`, rInt, rInt, defaultBranchStatement)
16251626
}
@@ -1719,6 +1720,7 @@ resource "gitlab_project" "foo" {
17191720
wiki_access_level = "disabled"
17201721
squash_commit_template = "goodby squash"
17211722
merge_commit_template = "goodby merge"
1723+
ci_default_git_depth = 84
17221724
}
17231725
`, rInt, rInt)
17241726
}
@@ -2055,6 +2057,7 @@ resource "gitlab_project" "foo" {
20552057
wiki_access_level = "enabled"
20562058
squash_commit_template = "hello squash"
20572059
merge_commit_template = "hello merge"
2060+
ci_default_git_depth = 42
20582061
20592062
# EE features
20602063
approvals_before_merge = 2

0 commit comments

Comments
 (0)