Skip to content

Commit 394a961

Browse files
authored
Merge pull request #525 from RomanNess/520_gitlab_project_hook_attributes
support additional attributes in `gitlab_project_hook`
2 parents a101a1c + 333fffc commit 394a961

File tree

4 files changed

+111
-44
lines changed

4 files changed

+111
-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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,31 @@ 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.
4449

4550
* `wiki_page_events` - (Optional) Invoke the hook for wiki page events.
51+
52+
* `deployment_events` - (Optional) Invoke the hook for deployment events.
4653

4754
## Attributes Reference
4855

gitlab/resource_gitlab_project_hook.go

Lines changed: 51 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,
@@ -70,6 +84,11 @@ func resourceGitlabProjectHook() *schema.Resource {
7084
Optional: true,
7185
Default: false,
7286
},
87+
"deployment_events": {
88+
Type: schema.TypeBool,
89+
Optional: true,
90+
Default: false,
91+
},
7392
"enable_ssl_verification": {
7493
Type: schema.TypeBool,
7594
Optional: true,
@@ -83,16 +102,20 @@ func resourceGitlabProjectHookCreate(d *schema.ResourceData, meta interface{}) e
83102
client := meta.(*gitlab.Client)
84103
project := d.Get("project").(string)
85104
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)),
105+
URL: gitlab.String(d.Get("url").(string)),
106+
PushEvents: gitlab.Bool(d.Get("push_events").(bool)),
107+
PushEventsBranchFilter: gitlab.String(d.Get("push_events_branch_filter").(string)),
108+
IssuesEvents: gitlab.Bool(d.Get("issues_events").(bool)),
109+
ConfidentialIssuesEvents: gitlab.Bool(d.Get("confidential_issues_events").(bool)),
110+
MergeRequestsEvents: gitlab.Bool(d.Get("merge_requests_events").(bool)),
111+
TagPushEvents: gitlab.Bool(d.Get("tag_push_events").(bool)),
112+
NoteEvents: gitlab.Bool(d.Get("note_events").(bool)),
113+
ConfidentialNoteEvents: gitlab.Bool(d.Get("confidential_note_events").(bool)),
114+
JobEvents: gitlab.Bool(d.Get("job_events").(bool)),
115+
PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)),
116+
WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)),
117+
DeploymentEvents: gitlab.Bool(d.Get("deployment_events").(bool)),
118+
EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)),
96119
}
97120

98121
if v, ok := d.GetOk("token"); ok {
@@ -127,13 +150,17 @@ func resourceGitlabProjectHookRead(d *schema.ResourceData, meta interface{}) err
127150

128151
d.Set("url", hook.URL)
129152
d.Set("push_events", hook.PushEvents)
153+
d.Set("push_events_branch_filter", hook.PushEventsBranchFilter)
130154
d.Set("issues_events", hook.IssuesEvents)
155+
d.Set("confidential_issues_events", hook.ConfidentialIssuesEvents)
131156
d.Set("merge_requests_events", hook.MergeRequestsEvents)
132157
d.Set("tag_push_events", hook.TagPushEvents)
133158
d.Set("note_events", hook.NoteEvents)
159+
d.Set("confidential_note_events", hook.ConfidentialNoteEvents)
134160
d.Set("job_events", hook.JobEvents)
135161
d.Set("pipeline_events", hook.PipelineEvents)
136162
d.Set("wiki_page_events", hook.WikiPageEvents)
163+
d.Set("deployment_events", hook.DeploymentEvents)
137164
d.Set("enable_ssl_verification", hook.EnableSSLVerification)
138165
return nil
139166
}
@@ -146,16 +173,20 @@ func resourceGitlabProjectHookUpdate(d *schema.ResourceData, meta interface{}) e
146173
return err
147174
}
148175
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)),
176+
URL: gitlab.String(d.Get("url").(string)),
177+
PushEvents: gitlab.Bool(d.Get("push_events").(bool)),
178+
PushEventsBranchFilter: gitlab.String(d.Get("push_events_branch_filter").(string)),
179+
IssuesEvents: gitlab.Bool(d.Get("issues_events").(bool)),
180+
ConfidentialIssuesEvents: gitlab.Bool(d.Get("confidential_issues_events").(bool)),
181+
MergeRequestsEvents: gitlab.Bool(d.Get("merge_requests_events").(bool)),
182+
TagPushEvents: gitlab.Bool(d.Get("tag_push_events").(bool)),
183+
NoteEvents: gitlab.Bool(d.Get("note_events").(bool)),
184+
ConfidentialNoteEvents: gitlab.Bool(d.Get("confidential_note_events").(bool)),
185+
JobEvents: gitlab.Bool(d.Get("job_events").(bool)),
186+
PipelineEvents: gitlab.Bool(d.Get("pipeline_events").(bool)),
187+
WikiPageEvents: gitlab.Bool(d.Get("wiki_page_events").(bool)),
188+
DeploymentEvents: gitlab.Bool(d.Get("deployment_events").(bool)),
189+
EnableSSLVerification: gitlab.Bool(d.Get("enable_ssl_verification").(bool)),
159190
}
160191

161192
if d.HasChange("token") {

gitlab/resource_gitlab_project_hook_test.go

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,20 @@ 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+
DeploymentEvents: true,
54+
EnableSSLVerification: false,
5155
}),
5256
),
5357
},
@@ -94,16 +98,20 @@ func testAccCheckGitlabProjectHookExists(n string, hook *gitlab.ProjectHook) res
9498
}
9599

96100
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
101+
URL string
102+
PushEvents bool
103+
PushEventsBranchFilter string
104+
IssuesEvents bool
105+
ConfidentialIssuesEvents bool
106+
MergeRequestsEvents bool
107+
TagPushEvents bool
108+
NoteEvents bool
109+
ConfidentialNoteEvents bool
110+
JobEvents bool
111+
PipelineEvents bool
112+
WikiPageEvents bool
113+
DeploymentEvents bool
114+
EnableSSLVerification bool
107115
}
108116

109117
func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *testAccGitlabProjectHookExpectedAttributes) resource.TestCheckFunc {
@@ -120,10 +128,18 @@ func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *tes
120128
return fmt.Errorf("got push_events %t; want %t", hook.PushEvents, want.PushEvents)
121129
}
122130

131+
if hook.PushEventsBranchFilter != want.PushEventsBranchFilter {
132+
return fmt.Errorf("got push_events_branch_filter %q; want %q", hook.PushEventsBranchFilter, want.PushEventsBranchFilter)
133+
}
134+
123135
if hook.IssuesEvents != want.IssuesEvents {
124136
return fmt.Errorf("got issues_events %t; want %t", hook.IssuesEvents, want.IssuesEvents)
125137
}
126138

139+
if hook.ConfidentialIssuesEvents != want.ConfidentialIssuesEvents {
140+
return fmt.Errorf("got confidential_issues_events %t; want %t", hook.ConfidentialIssuesEvents, want.ConfidentialIssuesEvents)
141+
}
142+
127143
if hook.MergeRequestsEvents != want.MergeRequestsEvents {
128144
return fmt.Errorf("got merge_requests_events %t; want %t", hook.MergeRequestsEvents, want.MergeRequestsEvents)
129145
}
@@ -136,6 +152,10 @@ func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *tes
136152
return fmt.Errorf("got note_events %t; want %t", hook.NoteEvents, want.NoteEvents)
137153
}
138154

155+
if hook.ConfidentialNoteEvents != want.ConfidentialNoteEvents {
156+
return fmt.Errorf("got confidential_note_events %t; want %t", hook.ConfidentialNoteEvents, want.ConfidentialNoteEvents)
157+
}
158+
139159
if hook.JobEvents != want.JobEvents {
140160
return fmt.Errorf("got job_events %t; want %t", hook.JobEvents, want.JobEvents)
141161
}
@@ -148,6 +168,10 @@ func testAccCheckGitlabProjectHookAttributes(hook *gitlab.ProjectHook, want *tes
148168
return fmt.Errorf("got wiki_page_events %t; want %t", hook.WikiPageEvents, want.WikiPageEvents)
149169
}
150170

171+
if hook.DeploymentEvents != want.DeploymentEvents {
172+
return fmt.Errorf("got deployment_events %t; want %t", hook.DeploymentEvents, want.DeploymentEvents)
173+
}
174+
151175
return nil
152176
}
153177
}
@@ -209,14 +233,18 @@ resource "gitlab_project_hook" "foo" {
209233
project = "${gitlab_project.foo.id}"
210234
url = "https://example.com/hook-%d"
211235
enable_ssl_verification = false
212-
push_events = false
213-
issues_events = true
236+
push_events = true
237+
push_events_branch_filter = "devel"
238+
issues_events = false
239+
confidential_issues_events = false
214240
merge_requests_events = true
215241
tag_push_events = true
216242
note_events = true
243+
confidential_note_events = true
217244
job_events = true
218245
pipeline_events = true
219246
wiki_page_events = true
247+
deployment_events = true
220248
}
221249
`, rInt, rInt)
222250
}

0 commit comments

Comments
 (0)