Skip to content

Commit 7342217

Browse files
authored
feat!: Change Hook.Config field from map to *HookConfig (#3073)
Fixes: #3072. BREAKING CHANGE: Changes `Hook.Config` from `map[string]interface{}` to `*HookConfig`.
1 parent 454c1dd commit 7342217

File tree

8 files changed

+50
-29
lines changed

8 files changed

+50
-29
lines changed

github/event_types_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7691,6 +7691,7 @@ func TestPingEvent_Marshal(t *testing.T) {
76917691

76927692
l := make(map[string]interface{})
76937693
l["key"] = "value"
7694+
hookConfig := new(HookConfig)
76947695

76957696
u := &PingEvent{
76967697
Zen: String("z"),
@@ -7705,7 +7706,7 @@ func TestPingEvent_Marshal(t *testing.T) {
77057706
TestURL: String("tu"),
77067707
PingURL: String("pu"),
77077708
LastResponse: l,
7708-
Config: l,
7709+
Config: hookConfig,
77097710
Events: []string{"a"},
77107711
Active: Bool(true),
77117712
},
@@ -12165,6 +12166,9 @@ func TestMetaEvent_Marshal(t *testing.T) {
1216512166

1216612167
v := make(map[string]interface{})
1216712168
v["a"] = "b"
12169+
hookConfig := &HookConfig{
12170+
ContentType: String("json"),
12171+
}
1216812172

1216912173
u := &MetaEvent{
1217012174
Action: String("a"),
@@ -12179,7 +12183,7 @@ func TestMetaEvent_Marshal(t *testing.T) {
1217912183
TestURL: String("tu"),
1218012184
PingURL: String("pu"),
1218112185
LastResponse: v,
12182-
Config: v,
12186+
Config: hookConfig,
1218312187
Events: []string{"a"},
1218412188
Active: Bool(true),
1218512189
},
@@ -12201,7 +12205,7 @@ func TestMetaEvent_Marshal(t *testing.T) {
1220112205
"a": "b"
1220212206
},
1220312207
"config": {
12204-
"a": "b"
12208+
"content_type": "json"
1220512209
},
1220612210
"events": [
1220712211
"a"

github/github-accessors.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-stringify_test.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/orgs_audit_log.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ type GetAuditLogOptions struct {
2020
ListCursorOptions
2121
}
2222

23-
// HookConfig describes metadata about a webhook configuration.
24-
type HookConfig struct {
25-
ContentType *string `json:"content_type,omitempty"`
26-
InsecureSSL *string `json:"insecure_ssl,omitempty"`
27-
URL *string `json:"url,omitempty"`
28-
29-
// Secret is returned obfuscated by GitHub, but it can be set for outgoing requests.
30-
Secret *string `json:"secret,omitempty"`
31-
}
32-
3323
// ActorLocation contains information about reported location for an actor.
3424
type ActorLocation struct {
3525
CountryCode *string `json:"country_code,omitempty"`

github/repos_hooks.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ type Hook struct {
5151

5252
// Only the following fields are used when creating a hook.
5353
// Config is required.
54-
Config map[string]interface{} `json:"config,omitempty"`
55-
Events []string `json:"events,omitempty"`
56-
Active *bool `json:"active,omitempty"`
54+
Config *HookConfig `json:"config,omitempty"`
55+
Events []string `json:"events,omitempty"`
56+
Active *bool `json:"active,omitempty"`
5757
}
5858

5959
func (h Hook) String() string {
@@ -67,10 +67,10 @@ func (h Hook) String() string {
6767
// information.
6868
type createHookRequest struct {
6969
// Config is required.
70-
Name string `json:"name"`
71-
Config map[string]interface{} `json:"config,omitempty"`
72-
Events []string `json:"events,omitempty"`
73-
Active *bool `json:"active,omitempty"`
70+
Name string `json:"name"`
71+
Config *HookConfig `json:"config,omitempty"`
72+
Events []string `json:"events,omitempty"`
73+
Active *bool `json:"active,omitempty"`
7474
}
7575

7676
// CreateHook creates a Hook for the specified repository.

github/repos_hooks_configuration.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ import (
1010
"fmt"
1111
)
1212

13+
// HookConfig describes metadata about a webhook configuration.
14+
type HookConfig struct {
15+
// The media type used to serialize the payloads
16+
// Possible values are `json` and `form`, the field is not specified the default is `form`
17+
ContentType *string `json:"content_type,omitempty"`
18+
// The possible values are 0 and 1.
19+
// Setting it to 1 will allow skip certificate verification for the host,
20+
// potentially exposing to MitM attacks: https://en.wikipedia.org/wiki/Man-in-the-middle_attack
21+
InsecureSSL *string `json:"insecure_ssl,omitempty"`
22+
URL *string `json:"url,omitempty"`
23+
24+
// Secret is returned obfuscated by GitHub, but it can be set for outgoing requests.
25+
Secret *string `json:"secret,omitempty"`
26+
}
27+
1328
// GetHookConfiguration returns the configuration for the specified repository webhook.
1429
//
1530
// GitHub API docs: https://docs.github.com/rest/repos/webhooks#get-a-webhook-configuration-for-a-repository

github/repos_hooks_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,17 +502,15 @@ func TestBranchCreateHookRequest_Marshal(t *testing.T) {
502502
Name: "abc",
503503
Events: []string{"1", "2", "3"},
504504
Active: Bool(true),
505-
Config: map[string]interface{}{
506-
"thing": "@123",
507-
},
505+
Config: &HookConfig{ContentType: String("json")},
508506
}
509507

510508
want := `{
511509
"name": "abc",
512510
"active": true,
513511
"events": ["1","2","3"],
514512
"config":{
515-
"thing": "@123"
513+
"content_type": "json"
516514
}
517515
}`
518516

@@ -534,9 +532,7 @@ func TestBranchHook_Marshal(t *testing.T) {
534532
LastResponse: map[string]interface{}{
535533
"item": "item",
536534
},
537-
Config: map[string]interface{}{
538-
"thing": "@123",
539-
},
535+
Config: &HookConfig{ContentType: String("json")},
540536
Events: []string{"1", "2", "3"},
541537
Active: Bool(true),
542538
}
@@ -554,7 +550,7 @@ func TestBranchHook_Marshal(t *testing.T) {
554550
"item": "item"
555551
},
556552
"config":{
557-
"thing": "@123"
553+
"content_type": "json"
558554
},
559555
"events": ["1","2","3"],
560556
"active": true

0 commit comments

Comments
 (0)