diff --git a/github/event_types.go b/github/event_types.go index cdfd6e8831d..6e096dffdaf 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -221,6 +221,14 @@ type EditChange struct { Body *struct { From *string `json:"from,omitempty"` } `json:"body,omitempty"` + Base *struct { + Ref *struct { + From *string `json:"from,omitempty"` + } `json:"ref,omitempty"` + SHA *struct { + From *string `json:"from,omitempty"` + } `json:"sha,omitempty"` + } `json:"base,omitempty"` } // ProjectChange represents the changes when a project has been edited. diff --git a/github/event_types_test.go b/github/event_types_test.go new file mode 100644 index 00000000000..986d9719f78 --- /dev/null +++ b/github/event_types_test.go @@ -0,0 +1,105 @@ +// Copyright 2020 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "testing" +) + +func TestEditChange_Marshal_TitleChange(t *testing.T) { + testJSONMarshal(t, &EditChange{}, "{}") + + TitleFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("TitleFrom"), + } + + u := &EditChange{ + Title: &TitleFrom, + Body: nil, + Base: nil, + } + + want := `{ + "title": { + "from": "TitleFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestEditChange_Marshal_BodyChange(t *testing.T) { + testJSONMarshal(t, &EditChange{}, "{}") + + BodyFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("BodyFrom"), + } + + u := &EditChange{ + Title: nil, + Body: &BodyFrom, + Base: nil, + } + + want := `{ + "body": { + "from": "BodyFrom" + } + }` + + testJSONMarshal(t, u, want) +} + +func TestEditChange_Marshal_BaseChange(t *testing.T) { + testJSONMarshal(t, &EditChange{}, "{}") + + RefFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("BaseRefFrom"), + } + + SHAFrom := struct { + From *string `json:"from,omitempty"` + }{ + From: String("BaseSHAFrom"), + } + + Base := struct { + Ref *struct { + From *string `json:"from,omitempty"` + } `json:"ref,omitempty"` + SHA *struct { + From *string `json:"from,omitempty"` + } `json:"sha,omitempty"` + }{ + Ref: &RefFrom, + SHA: &SHAFrom, + } + + u := &EditChange{ + Title: nil, + Body: nil, + Base: &Base, + } + + want := `{ + "base": { + "ref": { + "from": "BaseRefFrom" + }, + "sha": { + "from": "BaseSHAFrom" + } + } + }` + + testJSONMarshal(t, u, want) +}