Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Base, Ref, and SHA to EditChange struct #1619

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
105 changes: 105 additions & 0 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}