Skip to content

Add Owner to EditChange struct #2750

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

Merged
merged 4 commits into from
Apr 12, 2023
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
12 changes: 12 additions & 0 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ type EditChange struct {
Body *EditBody `json:"body,omitempty"`
Base *EditBase `json:"base,omitempty"`
Repo *EditRepo `json:"repository,omitempty"`
Owner *EditOwner `json:"owner,omitempty"`
}

// EditTitle represents a pull-request title change.
Expand Down Expand Up @@ -360,6 +361,17 @@ type EditRepo struct {
Name *RepoName `json:"name,omitempty"`
}

// EditOwner represents a change of repository ownership.
type EditOwner struct {
OwnerInfo *OwnerInfo `json:"from,omitempty"`
}

// OwnerInfo represents the account info of the owner of the repo (could be User or Organization but both are User structs).
type OwnerInfo struct {
User *User `json:"user,omitempty"`
Org *User `json:"organization,omitempty"`
}

// RepoName represents a change of repository name.
type RepoName struct {
From *string `json:"from,omitempty"`
Expand Down
76 changes: 76 additions & 0 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,82 @@ func TestEditChange_Marshal_Repo(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestEditChange_Marshal_TransferFromUser(t *testing.T) {
testJSONMarshal(t, &EditChange{}, "{}")

u := &EditChange{
Owner: &EditOwner{
OwnerInfo: &OwnerInfo{
User: &User{
Login: String("l"),
ID: Int64(1),
NodeID: String("n"),
URL: String("u"),
ReposURL: String("r"),
EventsURL: String("e"),
AvatarURL: String("a"),
},
},
},
}

want := `{
"owner": {
"from": {
"user": {
"login": "l",
"id": 1,
"node_id": "n",
"avatar_url": "a",
"url": "u",
"repos_url": "r",
"events_url": "e"
}
}
}
}`

testJSONMarshal(t, u, want)
}

func TestEditChange_Marshal_TransferFromOrg(t *testing.T) {
testJSONMarshal(t, &EditChange{}, "{}")

u := &EditChange{
Owner: &EditOwner{
OwnerInfo: &OwnerInfo{
Org: &User{
Login: String("l"),
ID: Int64(1),
NodeID: String("n"),
URL: String("u"),
ReposURL: String("r"),
EventsURL: String("e"),
AvatarURL: String("a"),
},
},
},
}

want := `{
"owner": {
"from": {
"organization": {
"login": "l",
"id": 1,
"node_id": "n",
"avatar_url": "a",
"url": "u",
"repos_url": "r",
"events_url": "e"
}
}
}
}`

testJSONMarshal(t, u, want)
}

func TestProjectChange_Marshal_NameChange(t *testing.T) {
testJSONMarshal(t, &ProjectChange{}, "{}")

Expand Down
32 changes: 32 additions & 0 deletions github/github-accessors.go

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

28 changes: 28 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.