From 1d202be51fc6b809435a33143dc221e228cff89e Mon Sep 17 00:00:00 2001 From: Jacob Valdemar Andreasen Date: Tue, 25 Aug 2020 09:19:58 +0200 Subject: [PATCH 1/3] Update EditChange struct --- github/event_types.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/github/event_types.go b/github/event_types.go index cdfd6e8831d..64e90f94d1b 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. From 05744972613659beb36b076a03cf38f8446682fb Mon Sep 17 00:00:00 2001 From: Jacob Valdemar Date: Thu, 27 Aug 2020 15:06:02 +0200 Subject: [PATCH 2/3] Make Sha struct uppercase Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/event_types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/event_types.go b/github/event_types.go index 64e90f94d1b..6e096dffdaf 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -225,7 +225,7 @@ type EditChange struct { Ref *struct { From *string `json:"from,omitempty"` } `json:"ref,omitempty"` - Sha *struct { + SHA *struct { From *string `json:"from,omitempty"` } `json:"sha,omitempty"` } `json:"base,omitempty"` From db89fcb3f4766cf7e0db891ce8f5cb8c4d733815 Mon Sep 17 00:00:00 2001 From: Jacob Valdemar Andreasen Date: Mon, 31 Aug 2020 12:12:11 +0200 Subject: [PATCH 3/3] Unit test EditChange struct --- github/event_types_test.go | 105 +++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 github/event_types_test.go 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) +}