Skip to content

Commit 2292b9e

Browse files
zawazawa0316thuckdan-hill2802pdecatsirlatrom
authored
add build coverage regex (#627)
* add build coverage regex * fmt * modify data source and tests * modify doc * fmt * Feature (#1) * Fix documentation to show up on terraform registry * update reference to `master` branch to `main` Tested to confirm that it does create a `main` branch by default * Add support for importing Pipeline Schedules and Triggers * Also wait for import_status when a project template is configured Signed-off-by: Sune Keller <[email protected]> * Update dependencies Signed-off-by: Julien Pivotto <[email protected]> * Add most Premium features for gitlab_branch_protection (#556) * Rebase and update go.mod Signed-off-by: Sune Keller <[email protected]> * Add most Premium features for gitlab_branch_protection Signed-off-by: Sune Keller <[email protected]> * Re-work modified schema for gitlab_branch_protection, and update docs Signed-off-by: Sune Keller <[email protected]> * Accommodate to name changes from library maintainer Signed-off-by: Sune Keller <[email protected]> * Remove invalid check for CE Signed-off-by: Sune Keller <[email protected]> * Revert back how merge_access_level and push_access_level are created Signed-off-by: Sune Keller <[email protected]> * Simplify expansion of arguments Signed-off-by: Sune Keller <[email protected]> * Remove several obsolete functions and make acceptance tests independent of implementation functions Signed-off-by: Sune Keller <[email protected]> * fix: update default_branch to "main" for gitlab_project tests * chore: add error handling to resourceGitlabProjectSetToState * Documentation improvements (#642) * Documentation improvements * More Markdown lint fixes * Add golangci-lint to the pipeline Fixes #361 * Add protected_branch_ids to gitlab_project_approval_rule (#542) Signed-off-by: Sune Keller <[email protected]> * chore: remove incomplete gitlab_project_repository_file resource (#650) This file was part of #556 but did not include a test, docs, or an entry in gitlab/provider.go, so we are removing it until it can be completed. * golangci-lint: exclude ResourceData.Set (#652) The common case when using this method is to ignore the error return. This is because the Terraform test framework checks these errors for primitive types for us. * CI: Add tfproviderlint workflow * Ignore preexisting tfproviderlint issues * chore: run golangci-lint for pull requests and annotate failing checks so we can fix them individually (#658) * chore: fix markdown linter errors in branch_protection.md (#656) * modify Co-authored-by: Denis Doria <[email protected]> Co-authored-by: Daniel Hill <[email protected]> Co-authored-by: Patrick Decat <[email protected]> Co-authored-by: Sune Keller <[email protected]> Co-authored-by: Julien Pivotto <[email protected]> Co-authored-by: Matt Kasa <[email protected]> Co-authored-by: Mikhail Mazurskiy <[email protected]> Co-authored-by: Willian Paixao <[email protected]> Co-authored-by: Matt Kasa <[email protected]> Co-authored-by: Adam Snyder <[email protected]> Co-authored-by: Adam Snyder <[email protected]> Co-authored-by: Denis Doria <[email protected]> Co-authored-by: Daniel Hill <[email protected]> Co-authored-by: Patrick Decat <[email protected]> Co-authored-by: Sune Keller <[email protected]> Co-authored-by: Julien Pivotto <[email protected]> Co-authored-by: Matt Kasa <[email protected]> Co-authored-by: Mikhail Mazurskiy <[email protected]> Co-authored-by: Willian Paixao <[email protected]> Co-authored-by: Matt Kasa <[email protected]> Co-authored-by: Adam Snyder <[email protected]> Co-authored-by: Adam Snyder <[email protected]>
1 parent 8e2faa7 commit 2292b9e

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

docs/data-sources/projects.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ Projects items have the following fields:
190190

191191
* `custom_attributes`
192192

193+
* `build_coverage_regex`
194+
193195
The `owner` attribute exposes the following sub-attributes:
194196

195197
> **NOTE**: These sub-attributes are only populated if the Gitlab token used has an administrator scope.

docs/resources/project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ consult the [gitlab documentation](https://docs.gitlab.com/ee/user/project/repos
105105
Valid values are `disabled`, `private`, `enabled`, `public`.
106106
`private` is the default.
107107

108+
* `build_coverage_regex` - (Optional) Test coverage parsing for the project.
109+
108110
## Attributes Reference
109111

110112
The following additional attributes are exported:

gitlab/data_source_gitlab_projects.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func flattenProjects(projects []*gitlab.Project) (values []map[string]interface{
160160
"ci_config_path": project.CIConfigPath,
161161
"custom_attributes": project.CustomAttributes,
162162
"packages_enabled": project.PackagesEnabled,
163+
"build_coverage_regex": project.BuildCoverageRegex,
163164
}
164165
values = append(values, v)
165166
}
@@ -658,6 +659,10 @@ func dataSourceGitlabProjects() *schema.Resource {
658659
Type: schema.TypeBool,
659660
Computed: true,
660661
},
662+
"build_coverage_regex": {
663+
Type: schema.TypeString,
664+
Computed: true,
665+
},
661666
},
662667
},
663668
},

gitlab/resource_gitlab_project.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{
295295
Optional: true,
296296
Default: false,
297297
},
298+
"build_coverage_regex": {
299+
Type: schema.TypeString,
300+
Optional: true,
301+
},
298302
}
299303

300304
func resourceGitlabProject() *schema.Resource {
@@ -346,6 +350,7 @@ func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Pro
346350
"mirror_trigger_builds": project.MirrorTriggerBuilds,
347351
"mirror_overwrites_diverged_branches": project.MirrorOverwritesDivergedBranches,
348352
"only_mirror_protected_branches": project.OnlyMirrorProtectedBranches,
353+
"build_coverage_regex": project.BuildCoverageRegex,
349354
}
350355
return setResourceData(d, values)
351356
}
@@ -373,6 +378,7 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
373378
PackagesEnabled: gitlab.Bool(d.Get("packages_enabled").(bool)),
374379
Mirror: gitlab.Bool(d.Get("mirror").(bool)),
375380
MirrorTriggerBuilds: gitlab.Bool(d.Get("mirror_trigger_builds").(bool)),
381+
BuildCoverageRegex: gitlab.String(d.Get("build_coverage_regex").(string)),
376382
}
377383

378384
if v, ok := d.GetOk("path"); ok {
@@ -641,6 +647,10 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
641647
options.MirrorOverwritesDivergedBranches = gitlab.Bool(d.Get("mirror_overwrites_diverged_branches").(bool))
642648
}
643649

650+
if d.HasChange("build_coverage_regex") {
651+
options.BuildCoverageRegex = gitlab.String(d.Get("build_coverage_regex").(string))
652+
}
653+
644654
if *options != (gitlab.EditProjectOptions{}) {
645655
log.Printf("[DEBUG] update gitlab project %s", d.Id())
646656
_, _, err := client.Projects.EditProject(d.Id(), options)

gitlab/resource_gitlab_project_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ func TestAccGitlabProject_basic(t *testing.T) {
4343
MergeMethod: gitlab.FastForwardMerge,
4444
OnlyAllowMergeIfPipelineSucceeds: true,
4545
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
46-
Archived: false, // needless, but let's make this explicit
47-
PackagesEnabled: true,
48-
PagesAccessLevel: gitlab.PublicAccessControl,
46+
Archived: false, // needless, but let's make this explicit
47+
PackagesEnabled: true,
48+
PagesAccessLevel: gitlab.PublicAccessControl,
49+
BuildCoverageRegex: "foo",
4950
}
5051

5152
defaultsMainBranch = defaults
@@ -85,9 +86,10 @@ func TestAccGitlabProject_basic(t *testing.T) {
8586
MergeMethod: gitlab.FastForwardMerge,
8687
OnlyAllowMergeIfPipelineSucceeds: true,
8788
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
88-
Archived: true,
89-
PackagesEnabled: false,
90-
PagesAccessLevel: gitlab.DisabledAccessControl,
89+
Archived: true,
90+
PackagesEnabled: false,
91+
PagesAccessLevel: gitlab.DisabledAccessControl,
92+
BuildCoverageRegex: "bar",
9193
}, &received),
9294
),
9395
},
@@ -358,8 +360,9 @@ func TestAccGitlabProject_willError(t *testing.T) {
358360
MergeMethod: gitlab.FastForwardMerge,
359361
OnlyAllowMergeIfPipelineSucceeds: true,
360362
OnlyAllowMergeIfAllDiscussionsAreResolved: true,
361-
PackagesEnabled: true,
362-
PagesAccessLevel: gitlab.PublicAccessControl,
363+
PackagesEnabled: true,
364+
PagesAccessLevel: gitlab.PublicAccessControl,
365+
BuildCoverageRegex: "foo",
363366
}
364367
willError := defaults
365368
willError.TagList = []string{"notatag"}
@@ -459,8 +462,9 @@ func TestAccGitlabProject_transfer(t *testing.T) {
459462
MergeMethod: gitlab.NoFastForwardMerge,
460463
OnlyAllowMergeIfPipelineSucceeds: false,
461464
OnlyAllowMergeIfAllDiscussionsAreResolved: false,
462-
PackagesEnabled: true,
463-
PagesAccessLevel: gitlab.PrivateAccessControl,
465+
PackagesEnabled: true,
466+
PagesAccessLevel: gitlab.PrivateAccessControl,
467+
BuildCoverageRegex: "foo",
464468
}
465469

466470
resource.Test(t, resource.TestCase{
@@ -887,6 +891,7 @@ resource "gitlab_project" "foo" {
887891
# So that acceptance tests can be run in a gitlab organization
888892
# with no billing
889893
visibility_level = "public"
894+
build_coverage_regex = "foo"
890895
}
891896
`, rInt, rInt, rInt)
892897
}
@@ -913,6 +918,7 @@ resource "gitlab_project" "foo" {
913918
# So that acceptance tests can be run in a gitlab organization
914919
# with no billing
915920
visibility_level = "public"
921+
build_coverage_regex = "foo"
916922
}
917923
`, rInt, rInt, rInt, rInt, rInt)
918924
}
@@ -943,6 +949,7 @@ resource "gitlab_project" "foo" {
943949
only_allow_merge_if_pipeline_succeeds = true
944950
only_allow_merge_if_all_discussions_are_resolved = true
945951
pages_access_level = "public"
952+
build_coverage_regex = "foo"
946953
}
947954
`, rInt, rInt, defaultBranchStatement)
948955
}
@@ -1010,6 +1017,7 @@ resource "gitlab_project" "foo" {
10101017
archived = true
10111018
packages_enabled = false
10121019
pages_access_level = "disabled"
1020+
build_coverage_regex = "bar"
10131021
}
10141022
`, rInt, rInt)
10151023
}

0 commit comments

Comments
 (0)