From d974dd66e43a76cb7c4813197936af9f0573be92 Mon Sep 17 00:00:00 2001 From: Hossein Naderi Date: Mon, 27 Dec 2021 09:38:21 +0330 Subject: [PATCH] Added releases event webhook option --- docs/resources/project_hook.md | 1 + internal/provider/resource_gitlab_project_hook.go | 9 +++++++++ internal/provider/resource_gitlab_project_hook_test.go | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/docs/resources/project_hook.md b/docs/resources/project_hook.md index 46109224b..642710a5a 100644 --- a/docs/resources/project_hook.md +++ b/docs/resources/project_hook.md @@ -46,6 +46,7 @@ resource "gitlab_project_hook" "example" { - **pipeline_events** (Boolean) Invoke the hook for pipeline events. - **push_events** (Boolean) Invoke the hook for push events. - **push_events_branch_filter** (String) Invoke the hook for push events on matching branches only. +- **releases_events** (Boolean) Invoke the hook for releases events. - **tag_push_events** (Boolean) Invoke the hook for tag push events. - **token** (String, Sensitive) A token to present when invoking the hook. - **wiki_page_events** (Boolean) Invoke the hook for wiki page events. diff --git a/internal/provider/resource_gitlab_project_hook.go b/internal/provider/resource_gitlab_project_hook.go index 5f03f88f8..05ef559e1 100644 --- a/internal/provider/resource_gitlab_project_hook.go +++ b/internal/provider/resource_gitlab_project_hook.go @@ -111,6 +111,12 @@ var _ = registerResource("gitlab_project_hook", func() *schema.Resource { Optional: true, Default: false, }, + "releases_events": { + Description: "Invoke the hook for releases events.", + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "enable_ssl_verification": { Description: "Enable ssl verification when invoking the hook.", Type: schema.TypeBool, @@ -138,6 +144,7 @@ func resourceGitlabProjectHookCreate(ctx context.Context, d *schema.ResourceData PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)), WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)), DeploymentEvents: gitlab.Bool(d.Get("deployment_events").(bool)), + ReleasesEvents: gitlab.Bool(d.Get("releases_events").(bool)), EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)), } @@ -189,6 +196,7 @@ func resourceGitlabProjectHookRead(ctx context.Context, d *schema.ResourceData, d.Set("pipeline_events", hook.PipelineEvents) d.Set("wiki_page_events", hook.WikiPageEvents) d.Set("deployment_events", hook.DeploymentEvents) + d.Set("releases_events", hook.ReleasesEvents) d.Set("enable_ssl_verification", hook.EnableSSLVerification) return nil } @@ -214,6 +222,7 @@ func resourceGitlabProjectHookUpdate(ctx context.Context, d *schema.ResourceData PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)), WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)), DeploymentEvents: gitlab.Bool(d.Get("deployment_events").(bool)), + ReleasesEvents: gitlab.Bool(d.Get("releases_events").(bool)), EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)), } diff --git a/internal/provider/resource_gitlab_project_hook_test.go b/internal/provider/resource_gitlab_project_hook_test.go index eba8675c8..d263381f5 100644 --- a/internal/provider/resource_gitlab_project_hook_test.go +++ b/internal/provider/resource_gitlab_project_hook_test.go @@ -51,6 +51,7 @@ func TestAccGitlabProjectHook_basic(t *testing.T) { PipelineEvents: true, WikiPageEvents: true, DeploymentEvents: true, + ReleasesEvents: true, EnableSSLVerification: false, }), ), @@ -110,6 +111,7 @@ type testAccGitlabProjectHookExpectedAttributes struct { PipelineEvents bool WikiPageEvents bool DeploymentEvents bool + ReleasesEvents bool EnableSSLVerification bool } @@ -171,6 +173,10 @@ func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *tes return fmt.Errorf("got deployment_events %t; want %t", hook.DeploymentEvents, want.DeploymentEvents) } + if hook.ReleasesEvents != want.ReleasesEvents { + return fmt.Errorf("got releases_events %t; want %t", hook.ReleasesEvents, want.ReleasesEvents) + } + return nil } } @@ -242,6 +248,7 @@ resource "gitlab_project_hook" "foo" { pipeline_events = true wiki_page_events = true deployment_events = true + releases_events = true } `, rInt, rInt) }