Skip to content

Commit b6465ca

Browse files
committed
add support for 'push_events_branch_filter', 'confidential_issues_events', 'confidential_note_events' in 'gitlab_project_hook' resource
1 parent a101a1c commit b6465ca

File tree

4 files changed

+94
-44
lines changed

4 files changed

+94
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ website/node_modules
2323
*.iml
2424
*.test
2525
*.iml
26+
.envrc
2627

2728
website/vendor
2829

docs/resources/project_hook.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,24 @@ The following arguments are supported:
2525

2626
* `token` - (Optional) A token to present when invoking the hook.
2727

28-
* `enable_ssl_verification` - (Optional) Enable ssl verification when invoking
29-
the hook.
28+
* `enable_ssl_verification` - (Optional) Enable ssl verification when invoking the hook.
3029

3130
* `push_events` - (Optional) Invoke the hook for push events.
3231

32+
* `push_events_branch_filter` - (Optional) Invoke the hook for push events on matching branches only.
33+
3334
* `issues_events` - (Optional) Invoke the hook for issues events.
3435

36+
* `confidential_issues_events` - (Optional) Invoke the hook for confidential issues events.
37+
3538
* `merge_requests_events` - (Optional) Invoke the hook for merge requests.
3639

3740
* `tag_push_events` - (Optional) Invoke the hook for tag push events.
3841

3942
* `note_events` - (Optional) Invoke the hook for notes events.
4043

44+
* `confidential_note_events` - (Optional) Invoke the hook for confidential notes events.
45+
4146
* `job_events` - (Optional) Invoke the hook for job events.
4247

4348
* `pipeline_events` - (Optional) Invoke the hook for pipeline events.

gitlab/resource_gitlab_project_hook.go

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,20 @@ func resourceGitlabProjectHook() *schema.Resource {
3535
Optional: true,
3636
Default: true,
3737
},
38+
"push_events_branch_filter": {
39+
Type: schema.TypeString,
40+
Optional: true,
41+
},
3842
"issues_events": {
3943
Type: schema.TypeBool,
4044
Optional: true,
4145
Default: false,
4246
},
47+
"confidential_issues_events": {
48+
Type: schema.TypeBool,
49+
Optional: true,
50+
Default: false,
51+
},
4352
"merge_requests_events": {
4453
Type: schema.TypeBool,
4554
Optional: true,
@@ -55,6 +64,11 @@ func resourceGitlabProjectHook() *schema.Resource {
5564
Optional: true,
5665
Default: false,
5766
},
67+
"confidential_note_events": {
68+
Type: schema.TypeBool,
69+
Optional: true,
70+
Default: false,
71+
},
5872
"job_events": {
5973
Type: schema.TypeBool,
6074
Optional: true,
@@ -83,16 +97,19 @@ func resourceGitlabProjectHookCreate(d *schema.ResourceData, meta interface{}) e
8397
client := meta.(*gitlab.Client)
8498
project := d.Get("project").(string)
8599
options := &gitlab.AddProjectHookOptions{
86-
URL: gitlab.String(d.Get("url").(string)),
87-
PushEvents: gitlab.Bool(d.Get("push_events").(bool)),
88-
IssuesEvents: gitlab.Bool(d.Get("issues_events").(bool)),
89-
MergeRequestsEvents: gitlab.Bool(d.Get("merge_requests_events").(bool)),
90-
TagPushEvents: gitlab.Bool(d.Get("tag_push_events").(bool)),
91-
NoteEvents: gitlab.Bool(d.Get("note_events").(bool)),
92-
JobEvents: gitlab.Bool(d.Get("job_events").(bool)),
93-
PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)),
94-
WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)),
95-
EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)),
100+
URL: gitlab.String(d.Get("url").(string)),
101+
PushEvents: gitlab.Bool(d.Get("push_events").(bool)),
102+
PushEventsBranchFilter: gitlab.String(d.Get("push_events_branch_filter").(string)),
103+
IssuesEvents: gitlab.Bool(d.Get("issues_events").(bool)),
104+
ConfidentialIssuesEvents: gitlab.Bool(d.Get("confidential_issues_events").(bool)),
105+
MergeRequestsEvents: gitlab.Bool(d.Get("merge_requests_events").(bool)),
106+
TagPushEvents: gitlab.Bool(d.Get("tag_push_events").(bool)),
107+
NoteEvents: gitlab.Bool(d.Get("note_events").(bool)),
108+
ConfidentialNoteEvents: gitlab.Bool(d.Get("confidential_note_events").(bool)),
109+
JobEvents: gitlab.Bool(d.Get("job_events").(bool)),
110+
PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)),
111+
WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)),
112+
EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)),
96113
}
97114

98115
if v, ok := d.GetOk("token"); ok {
@@ -127,10 +144,13 @@ func resourceGitlabProjectHookRead(d *schema.ResourceData, meta interface{}) err
127144

128145
d.Set("url", hook.URL)
129146
d.Set("push_events", hook.PushEvents)
147+
d.Set("push_events_branch_filter", hook.PushEventsBranchFilter)
130148
d.Set("issues_events", hook.IssuesEvents)
149+
d.Set("confidential_issues_events", hook.ConfidentialIssuesEvents)
131150
d.Set("merge_requests_events", hook.MergeRequestsEvents)
132151
d.Set("tag_push_events", hook.TagPushEvents)
133152
d.Set("note_events", hook.NoteEvents)
153+
d.Set("confidential_note_events", hook.ConfidentialNoteEvents)
134154
d.Set("job_events", hook.JobEvents)
135155
d.Set("pipeline_events", hook.PipelineEvents)
136156
d.Set("wiki_page_events", hook.WikiPageEvents)
@@ -146,16 +166,19 @@ func resourceGitlabProjectHookUpdate(d *schema.ResourceData, meta interface{}) e
146166
return err
147167
}
148168
options := &gitlab.EditProjectHookOptions{
149-
URL: gitlab.String(d.Get("url").(string)),
150-
PushEvents: gitlab.Bool(d.Get("push_events").(bool)),
151-
IssuesEvents: gitlab.Bool(d.Get("issues_events").(bool)),
152-
MergeRequestsEvents: gitlab.Bool(d.Get("merge_requests_events").(bool)),
153-
TagPushEvents: gitlab.Bool(d.Get("tag_push_events").(bool)),
154-
NoteEvents: gitlab.Bool(d.Get("note_events").(bool)),
155-
JobEvents: gitlab.Bool(d.Get("job_events").(bool)),
156-
PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)),
157-
WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)),
158-
EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)),
169+
URL: gitlab.String(d.Get("url").(string)),
170+
PushEvents: gitlab.Bool(d.Get("push_events").(bool)),
171+
PushEventsBranchFilter: gitlab.String(d.Get("push_events_branch_filter").(string)),
172+
IssuesEvents: gitlab.Bool(d.Get("issues_events").(bool)),
173+
ConfidentialIssuesEvents: gitlab.Bool(d.Get("confidential_issues_events").(bool)),
174+
MergeRequestsEvents: gitlab.Bool(d.Get("merge_requests_events").(bool)),
175+
TagPushEvents: gitlab.Bool(d.Get("tag_push_events").(bool)),
176+
NoteEvents: gitlab.Bool(d.Get("note_events").(bool)),
177+
ConfidentialNoteEvents: gitlab.Bool(d.Get("confidential_note_events").(bool)),
178+
JobEvents: gitlab.Bool(d.Get("job_events").(bool)),
179+
PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)),
180+
WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)),
181+
EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)),
159182
}
160183

161184
if d.HasChange("token") {

gitlab/resource_gitlab_project_hook_test.go

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ func TestAccGitlabProjectHook_basic(t *testing.T) {
3838
Check: resource.ComposeTestCheckFunc(
3939
testAccCheckGitlabProjectHookExists("gitlab_project_hook.foo", &hook),
4040
testAccCheckGitlabProjectHookAttributes(&hook, &testAccGitlabProjectHookExpectedAttributes{
41-
URL: fmt.Sprintf("https://example.com/hook-%d", rInt),
42-
PushEvents: false,
43-
IssuesEvents: true,
44-
MergeRequestsEvents: true,
45-
TagPushEvents: true,
46-
NoteEvents: true,
47-
JobEvents: true,
48-
PipelineEvents: true,
49-
WikiPageEvents: true,
50-
EnableSSLVerification: false,
41+
URL: fmt.Sprintf("https://example.com/hook-%d", rInt),
42+
PushEvents: true,
43+
PushEventsBranchFilter: "devel",
44+
IssuesEvents: false,
45+
ConfidentialIssuesEvents: false,
46+
MergeRequestsEvents: true,
47+
TagPushEvents: true,
48+
NoteEvents: true,
49+
ConfidentialNoteEvents: true,
50+
JobEvents: true,
51+
PipelineEvents: true,
52+
WikiPageEvents: true,
53+
EnableSSLVerification: false,
5154
}),
5255
),
5356
},
@@ -94,16 +97,19 @@ func testAccCheckGitlabProjectHookExists(n string, hook *gitlab.ProjectHook) res
9497
}
9598

9699
type testAccGitlabProjectHookExpectedAttributes struct {
97-
URL string
98-
PushEvents bool
99-
IssuesEvents bool
100-
MergeRequestsEvents bool
101-
TagPushEvents bool
102-
NoteEvents bool
103-
JobEvents bool
104-
PipelineEvents bool
105-
WikiPageEvents bool
106-
EnableSSLVerification bool
100+
URL string
101+
PushEvents bool
102+
PushEventsBranchFilter string
103+
IssuesEvents bool
104+
ConfidentialIssuesEvents bool
105+
MergeRequestsEvents bool
106+
TagPushEvents bool
107+
NoteEvents bool
108+
ConfidentialNoteEvents bool
109+
JobEvents bool
110+
PipelineEvents bool
111+
WikiPageEvents bool
112+
EnableSSLVerification bool
107113
}
108114

109115
func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *testAccGitlabProjectHookExpectedAttributes) resource.TestCheckFunc {
@@ -120,10 +126,18 @@ func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *tes
120126
return fmt.Errorf("got push_events %t; want %t", hook.PushEvents, want.PushEvents)
121127
}
122128

129+
if hook.PushEventsBranchFilter != want.PushEventsBranchFilter {
130+
return fmt.Errorf("got push_events_branch_filter %q; want %q", hook.PushEventsBranchFilter, want.PushEventsBranchFilter)
131+
}
132+
123133
if hook.IssuesEvents != want.IssuesEvents {
124134
return fmt.Errorf("got issues_events %t; want %t", hook.IssuesEvents, want.IssuesEvents)
125135
}
126136

137+
if hook.ConfidentialIssuesEvents != want.ConfidentialIssuesEvents {
138+
return fmt.Errorf("got confidential_issues_events %t; want %t", hook.ConfidentialIssuesEvents, want.ConfidentialIssuesEvents)
139+
}
140+
127141
if hook.MergeRequestsEvents != want.MergeRequestsEvents {
128142
return fmt.Errorf("got merge_requests_events %t; want %t", hook.MergeRequestsEvents, want.MergeRequestsEvents)
129143
}
@@ -136,6 +150,10 @@ func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *tes
136150
return fmt.Errorf("got note_events %t; want %t", hook.NoteEvents, want.NoteEvents)
137151
}
138152

153+
if hook.ConfidentialNoteEvents != want.ConfidentialNoteEvents {
154+
return fmt.Errorf("got confidential_note_events %t; want %t", hook.ConfidentialNoteEvents, want.ConfidentialNoteEvents)
155+
}
156+
139157
if hook.JobEvents != want.JobEvents {
140158
return fmt.Errorf("got job_events %t; want %t", hook.JobEvents, want.JobEvents)
141159
}
@@ -209,11 +227,14 @@ resource "gitlab_project_hook" "foo" {
209227
project = "${gitlab_project.foo.id}"
210228
url = "https://example.com/hook-%d"
211229
enable_ssl_verification = false
212-
push_events = false
213-
issues_events = true
230+
push_events = true
231+
push_events_branch_filter = "devel"
232+
issues_events = false
233+
confidential_issues_events = false
214234
merge_requests_events = true
215235
tag_push_events = true
216236
note_events = true
237+
confidential_note_events = true
217238
job_events = true
218239
pipeline_events = true
219240
wiki_page_events = true

0 commit comments

Comments
 (0)