Skip to content

Commit

Permalink
feat!: Change Hook.Config field from map to *HookConfig (#3073)
Browse files Browse the repository at this point in the history
Fixes: #3072.

BREAKING CHANGE: Changes `Hook.Config` from `map[string]interface{}` to `*HookConfig`.
  • Loading branch information
himazawa committed Feb 17, 2024
1 parent 454c1dd commit 7342217
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 29 deletions.
10 changes: 7 additions & 3 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7691,6 +7691,7 @@ func TestPingEvent_Marshal(t *testing.T) {

l := make(map[string]interface{})
l["key"] = "value"
hookConfig := new(HookConfig)

u := &PingEvent{
Zen: String("z"),
Expand All @@ -7705,7 +7706,7 @@ func TestPingEvent_Marshal(t *testing.T) {
TestURL: String("tu"),
PingURL: String("pu"),
LastResponse: l,
Config: l,
Config: hookConfig,
Events: []string{"a"},
Active: Bool(true),
},
Expand Down Expand Up @@ -12165,6 +12166,9 @@ func TestMetaEvent_Marshal(t *testing.T) {

v := make(map[string]interface{})
v["a"] = "b"
hookConfig := &HookConfig{
ContentType: String("json"),
}

u := &MetaEvent{
Action: String("a"),
Expand All @@ -12179,7 +12183,7 @@ func TestMetaEvent_Marshal(t *testing.T) {
TestURL: String("tu"),
PingURL: String("pu"),
LastResponse: v,
Config: v,
Config: hookConfig,
Events: []string{"a"},
Active: Bool(true),
},
Expand All @@ -12201,7 +12205,7 @@ func TestMetaEvent_Marshal(t *testing.T) {
"a": "b"
},
"config": {
"a": "b"
"content_type": "json"
},
"events": [
"a"
Expand Down
8 changes: 8 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions github/orgs_audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ type GetAuditLogOptions struct {
ListCursorOptions
}

// HookConfig describes metadata about a webhook configuration.
type HookConfig struct {
ContentType *string `json:"content_type,omitempty"`
InsecureSSL *string `json:"insecure_ssl,omitempty"`
URL *string `json:"url,omitempty"`

// Secret is returned obfuscated by GitHub, but it can be set for outgoing requests.
Secret *string `json:"secret,omitempty"`
}

// ActorLocation contains information about reported location for an actor.
type ActorLocation struct {
CountryCode *string `json:"country_code,omitempty"`
Expand Down
14 changes: 7 additions & 7 deletions github/repos_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ type Hook struct {

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

func (h Hook) String() string {
Expand All @@ -67,10 +67,10 @@ func (h Hook) String() string {
// information.
type createHookRequest struct {
// Config is required.
Name string `json:"name"`
Config map[string]interface{} `json:"config,omitempty"`
Events []string `json:"events,omitempty"`
Active *bool `json:"active,omitempty"`
Name string `json:"name"`
Config *HookConfig `json:"config,omitempty"`
Events []string `json:"events,omitempty"`
Active *bool `json:"active,omitempty"`
}

// CreateHook creates a Hook for the specified repository.
Expand Down
15 changes: 15 additions & 0 deletions github/repos_hooks_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ import (
"fmt"
)

// HookConfig describes metadata about a webhook configuration.
type HookConfig struct {
// The media type used to serialize the payloads
// Possible values are `json` and `form`, the field is not specified the default is `form`
ContentType *string `json:"content_type,omitempty"`
// The possible values are 0 and 1.
// Setting it to 1 will allow skip certificate verification for the host,
// potentially exposing to MitM attacks: https://en.wikipedia.org/wiki/Man-in-the-middle_attack
InsecureSSL *string `json:"insecure_ssl,omitempty"`
URL *string `json:"url,omitempty"`

// Secret is returned obfuscated by GitHub, but it can be set for outgoing requests.
Secret *string `json:"secret,omitempty"`
}

// GetHookConfiguration returns the configuration for the specified repository webhook.
//
// GitHub API docs: https://docs.github.com/rest/repos/webhooks#get-a-webhook-configuration-for-a-repository
Expand Down
12 changes: 4 additions & 8 deletions github/repos_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,15 @@ func TestBranchCreateHookRequest_Marshal(t *testing.T) {
Name: "abc",
Events: []string{"1", "2", "3"},
Active: Bool(true),
Config: map[string]interface{}{
"thing": "@123",
},
Config: &HookConfig{ContentType: String("json")},
}

want := `{
"name": "abc",
"active": true,
"events": ["1","2","3"],
"config":{
"thing": "@123"
"content_type": "json"
}
}`

Expand All @@ -534,9 +532,7 @@ func TestBranchHook_Marshal(t *testing.T) {
LastResponse: map[string]interface{}{
"item": "item",
},
Config: map[string]interface{}{
"thing": "@123",
},
Config: &HookConfig{ContentType: String("json")},
Events: []string{"1", "2", "3"},
Active: Bool(true),
}
Expand All @@ -554,7 +550,7 @@ func TestBranchHook_Marshal(t *testing.T) {
"item": "item"
},
"config":{
"thing": "@123"
"content_type": "json"
},
"events": ["1","2","3"],
"active": true
Expand Down

0 comments on commit 7342217

Please sign in to comment.