From 1daf5ef9aa06c0ce6bea3b02ec337a3973d17377 Mon Sep 17 00:00:00 2001 From: Marcelo Boeira Date: Mon, 7 Feb 2022 21:14:58 +0100 Subject: [PATCH] Add printing_merge_request_link_enabled attribute to projects As mentioned on gitlabhq#782, the field is available on GitLab but still not possible to use on terraform Reference: - gitlabhq#782 --- docs/data-sources/project.md | 3 +-- docs/resources/project.md | 1 + examples/gitlab-managed-state/main.tf | 1 + internal/provider/data_source_gitlab_project.go | 5 +++++ internal/provider/resource_gitlab_project.go | 11 +++++++++++ internal/provider/resource_gitlab_project_test.go | 1 + 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/data-sources/project.md b/docs/data-sources/project.md index a4920ae53..9ce67ac9c 100644 --- a/docs/data-sources/project.md +++ b/docs/data-sources/project.md @@ -45,6 +45,7 @@ data "gitlab_project" "example" { - **pipelines_enabled** (Boolean) Enable pipelines for the project. - **push_rules** (List of Object) Push rules for the project. (see [below for nested schema](#nestedatt--push_rules)) - **remove_source_branch_after_merge** (Boolean) Enable `Delete source branch` option by default for all new merge requests +- **printing_merge_request_link_enabled** (Boolean) Show link to create/view merge request when pushing from the command line - **request_access_enabled** (Boolean) Allow users to request member access. - **runners_token** (String) Registration token to use during runner setup. - **snippets_enabled** (Boolean) Enable snippets for the project. @@ -69,5 +70,3 @@ Read-Only: - **member_check** (Boolean) - **prevent_secrets** (Boolean) - **reject_unsigned_commits** (Boolean) - - diff --git a/docs/resources/project.md b/docs/resources/project.md index 972e3022f..5ee8a4dda 100644 --- a/docs/resources/project.md +++ b/docs/resources/project.md @@ -74,6 +74,7 @@ resource "gitlab_project" "example-two" { - **pipelines_enabled** (Boolean) Enable pipelines for the project. - **push_rules** (Block List, Max: 1) Push rules for the project. (see [below for nested schema](#nestedblock--push_rules)) - **remove_source_branch_after_merge** (Boolean) Enable `Delete source branch` option by default for all new merge requests. +- **printing_merge_request_link_enabled** (Boolean) Show link to create/view merge request when pushing from the command line - **request_access_enabled** (Boolean) Allow users to request member access. - **shared_runners_enabled** (Boolean) Enable shared runners for this project. - **snippets_enabled** (Boolean) Enable snippets for the project. diff --git a/examples/gitlab-managed-state/main.tf b/examples/gitlab-managed-state/main.tf index 48eaf2a1e..56c8140c5 100644 --- a/examples/gitlab-managed-state/main.tf +++ b/examples/gitlab-managed-state/main.tf @@ -41,6 +41,7 @@ resource "gitlab_project" "api" { only_allow_merge_if_all_discussions_are_resolved = true only_allow_merge_if_pipeline_succeeds = true remove_source_branch_after_merge = true + printing_merge_request_link_enabled = true container_registry_enabled = false lfs_enabled = false diff --git a/internal/provider/data_source_gitlab_project.go b/internal/provider/data_source_gitlab_project.go index 6c5a83441..87015d770 100644 --- a/internal/provider/data_source_gitlab_project.go +++ b/internal/provider/data_source_gitlab_project.go @@ -134,6 +134,11 @@ var _ = registerDataSource("gitlab_project", func() *schema.Resource { Type: schema.TypeBool, Computed: true, }, + "printing_merge_request_link_enabled": { + Description: " Show link to create/view merge request when pushing from the command line", + Type: schema.TypeBool, + Optional: true, + }, // lintignore: S031 // TODO: Resolve this tfproviderlint issue "push_rules": { Description: "Push rules for the project.", diff --git a/internal/provider/resource_gitlab_project.go b/internal/provider/resource_gitlab_project.go index fa23433e6..3f2cb2377 100644 --- a/internal/provider/resource_gitlab_project.go +++ b/internal/provider/resource_gitlab_project.go @@ -204,6 +204,11 @@ var resourceGitLabProjectSchema = map[string]*schema.Schema{ Type: schema.TypeBool, Optional: true, }, + "printing_merge_request_link_enabled": { + Description: " Show link to create/view merge request when pushing from the command line", + Type: schema.TypeBool, + Optional: true, + }, "packages_enabled": { Description: "Enable packages repository for the project.", Type: schema.TypeBool, @@ -413,6 +418,7 @@ func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Pro d.Set("archived", project.Archived) d.Set("squash_option", project.SquashOption) d.Set("remove_source_branch_after_merge", project.RemoveSourceBranchAfterMerge) + d.Set("printing_merge_request_link_enabled", project.PrintingMergeRequestLinkEnabled) d.Set("packages_enabled", project.PackagesEnabled) d.Set("pages_access_level", string(project.PagesAccessLevel)) d.Set("mirror", project.Mirror) @@ -449,6 +455,7 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me SquashOption: stringToSquashOptionValue(d.Get("squash_option").(string)), RemoveSourceBranchAfterMerge: gitlab.Bool(d.Get("remove_source_branch_after_merge").(bool)), PackagesEnabled: gitlab.Bool(d.Get("packages_enabled").(bool)), + PrintingMergeRequestLinkEnabled: gitlab.Bool(d.Get("printing_merge_request_link_enabled").(bool)), Mirror: gitlab.Bool(d.Get("mirror").(bool)), MirrorTriggerBuilds: gitlab.Bool(d.Get("mirror_trigger_builds").(bool)), BuildCoverageRegex: gitlab.String(d.Get("build_coverage_regex").(string)), @@ -773,6 +780,10 @@ func resourceGitlabProjectUpdate(ctx context.Context, d *schema.ResourceData, me options.RemoveSourceBranchAfterMerge = gitlab.Bool(d.Get("remove_source_branch_after_merge").(bool)) } + if d.HasChange("printing_merge_request_link_enabled") { + options.PrintingMergeRequestLinkEnabled = gitlab.Bool(d.Get("printing_merge_request_link_enabled").(bool)) + } + if d.HasChange("packages_enabled") { options.PackagesEnabled = gitlab.Bool(d.Get("packages_enabled").(bool)) } diff --git a/internal/provider/resource_gitlab_project_test.go b/internal/provider/resource_gitlab_project_test.go index c61fa0515..58be6a851 100644 --- a/internal/provider/resource_gitlab_project_test.go +++ b/internal/provider/resource_gitlab_project_test.go @@ -463,6 +463,7 @@ func TestAccGitlabProject_willError(t *testing.T) { SharedRunnersEnabled: true, Visibility: gitlab.PublicVisibility, MergeMethod: gitlab.FastForwardMerge, + PrintingMergeRequestLinkEnabled: true, OnlyAllowMergeIfPipelineSucceeds: true, OnlyAllowMergeIfAllDiscussionsAreResolved: true, SquashOption: gitlab.SquashOptionDefaultOff,