From 9bfa1ad287b5853b124ecf7c9af966833a62aa6b Mon Sep 17 00:00:00 2001 From: himazawa <73994521+himazawa@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:34:12 +0100 Subject: [PATCH 1/3] chore!: change Hook Config field from map to *HookConfig --- github/event_types_test.go | 10 +++++++--- github/hooks_config.go | 16 ++++++++++++++++ github/orgs_audit_log.go | 10 ---------- github/repos_hooks.go | 14 +++++++------- github/repos_hooks_test.go | 12 ++++-------- 5 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 github/hooks_config.go diff --git a/github/event_types_test.go b/github/event_types_test.go index 8578b922bf6..b00e94a34e4 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -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"), @@ -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), }, @@ -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"), @@ -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), }, @@ -12201,7 +12205,7 @@ func TestMetaEvent_Marshal(t *testing.T) { "a": "b" }, "config": { - "a": "b" + "content_type": "json" }, "events": [ "a" diff --git a/github/hooks_config.go b/github/hooks_config.go new file mode 100644 index 00000000000..dcbd41bf8cb --- /dev/null +++ b/github/hooks_config.go @@ -0,0 +1,16 @@ +package github + +// 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"` +} diff --git a/github/orgs_audit_log.go b/github/orgs_audit_log.go index 28ac079bb3b..025c5d02327 100644 --- a/github/orgs_audit_log.go +++ b/github/orgs_audit_log.go @@ -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"` diff --git a/github/repos_hooks.go b/github/repos_hooks.go index 3edf6475666..d221db21b6b 100644 --- a/github/repos_hooks.go +++ b/github/repos_hooks.go @@ -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 { @@ -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. diff --git a/github/repos_hooks_test.go b/github/repos_hooks_test.go index fa44440ade0..bda277af735 100644 --- a/github/repos_hooks_test.go +++ b/github/repos_hooks_test.go @@ -502,9 +502,7 @@ 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 := `{ @@ -512,7 +510,7 @@ func TestBranchCreateHookRequest_Marshal(t *testing.T) { "active": true, "events": ["1","2","3"], "config":{ - "thing": "@123" + "content_type": "json" } }` @@ -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), } @@ -554,7 +550,7 @@ func TestBranchHook_Marshal(t *testing.T) { "item": "item" }, "config":{ - "thing": "@123" + "content_type": "json" }, "events": ["1","2","3"], "active": true From ea29fb57db7c1dafa80411b595ec6332621219ba Mon Sep 17 00:00:00 2001 From: himazawa <73994521+himazawa@users.noreply.github.com> Date: Wed, 14 Feb 2024 18:50:07 +0100 Subject: [PATCH 2/3] chore: moved HookConfig --- github/hooks_config.go | 16 ---------------- github/repos_hooks_configuration.go | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 16 deletions(-) delete mode 100644 github/hooks_config.go diff --git a/github/hooks_config.go b/github/hooks_config.go deleted file mode 100644 index dcbd41bf8cb..00000000000 --- a/github/hooks_config.go +++ /dev/null @@ -1,16 +0,0 @@ -package github - -// 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"` -} diff --git a/github/repos_hooks_configuration.go b/github/repos_hooks_configuration.go index b58eb248e44..9560bd7a4ba 100644 --- a/github/repos_hooks_configuration.go +++ b/github/repos_hooks_configuration.go @@ -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 From 5d2954841a128327e67adb4e4adeccbf1d4f3962 Mon Sep 17 00:00:00 2001 From: himazawa <73994521+himazawa@users.noreply.github.com> Date: Wed, 14 Feb 2024 19:19:00 +0100 Subject: [PATCH 3/3] chore: generating formatted files --- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 7 +++++++ github/github-stringify_test.go | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index b645390e83a..89728d38df9 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -7894,6 +7894,14 @@ func (h *Hook) GetActive() bool { return *h.Active } +// GetConfig returns the Config field. +func (h *Hook) GetConfig() *HookConfig { + if h == nil { + return nil + } + return h.Config +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (h *Hook) GetCreatedAt() Timestamp { if h == nil || h.CreatedAt == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 8d5b438054d..1dcb4dc2bb9 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -9229,6 +9229,13 @@ func TestHook_GetActive(tt *testing.T) { h.GetActive() } +func TestHook_GetConfig(tt *testing.T) { + h := &Hook{} + h.GetConfig() + h = nil + h.GetConfig() +} + func TestHook_GetCreatedAt(tt *testing.T) { var zeroValue Timestamp h := &Hook{CreatedAt: &zeroValue} diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index bb69ce1ad5a..576db8ff29a 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -617,10 +617,11 @@ func TestHook_String(t *testing.T) { Name: String(""), TestURL: String(""), PingURL: String(""), + Config: &HookConfig{}, Events: []string{""}, Active: Bool(false), } - want := `github.Hook{CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, URL:"", ID:0, Type:"", Name:"", TestURL:"", PingURL:"", Events:[""], Active:false}` + want := `github.Hook{CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, URL:"", ID:0, Type:"", Name:"", TestURL:"", PingURL:"", Config:github.HookConfig{}, Events:[""], Active:false}` if got := v.String(); got != want { t.Errorf("Hook.String = %v, want %v", got, want) }