Skip to content

Commit

Permalink
Add Owner to EditChange struct (#2750)
Browse files Browse the repository at this point in the history
Fixes: #2749.
  • Loading branch information
ecrupper committed Apr 12, 2023
1 parent 683c2d7 commit 6d92e30
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
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.

0 comments on commit 6d92e30

Please sign in to comment.