Skip to content

Commit 6d92e30

Browse files
authored
Add Owner to EditChange struct (#2750)
Fixes: #2749.
1 parent 683c2d7 commit 6d92e30

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

github/event_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ type EditChange struct {
332332
Body *EditBody `json:"body,omitempty"`
333333
Base *EditBase `json:"base,omitempty"`
334334
Repo *EditRepo `json:"repository,omitempty"`
335+
Owner *EditOwner `json:"owner,omitempty"`
335336
}
336337

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

364+
// EditOwner represents a change of repository ownership.
365+
type EditOwner struct {
366+
OwnerInfo *OwnerInfo `json:"from,omitempty"`
367+
}
368+
369+
// OwnerInfo represents the account info of the owner of the repo (could be User or Organization but both are User structs).
370+
type OwnerInfo struct {
371+
User *User `json:"user,omitempty"`
372+
Org *User `json:"organization,omitempty"`
373+
}
374+
363375
// RepoName represents a change of repository name.
364376
type RepoName struct {
365377
From *string `json:"from,omitempty"`

github/event_types_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,82 @@ func TestEditChange_Marshal_Repo(t *testing.T) {
104104
testJSONMarshal(t, u, want)
105105
}
106106

107+
func TestEditChange_Marshal_TransferFromUser(t *testing.T) {
108+
testJSONMarshal(t, &EditChange{}, "{}")
109+
110+
u := &EditChange{
111+
Owner: &EditOwner{
112+
OwnerInfo: &OwnerInfo{
113+
User: &User{
114+
Login: String("l"),
115+
ID: Int64(1),
116+
NodeID: String("n"),
117+
URL: String("u"),
118+
ReposURL: String("r"),
119+
EventsURL: String("e"),
120+
AvatarURL: String("a"),
121+
},
122+
},
123+
},
124+
}
125+
126+
want := `{
127+
"owner": {
128+
"from": {
129+
"user": {
130+
"login": "l",
131+
"id": 1,
132+
"node_id": "n",
133+
"avatar_url": "a",
134+
"url": "u",
135+
"repos_url": "r",
136+
"events_url": "e"
137+
}
138+
}
139+
}
140+
}`
141+
142+
testJSONMarshal(t, u, want)
143+
}
144+
145+
func TestEditChange_Marshal_TransferFromOrg(t *testing.T) {
146+
testJSONMarshal(t, &EditChange{}, "{}")
147+
148+
u := &EditChange{
149+
Owner: &EditOwner{
150+
OwnerInfo: &OwnerInfo{
151+
Org: &User{
152+
Login: String("l"),
153+
ID: Int64(1),
154+
NodeID: String("n"),
155+
URL: String("u"),
156+
ReposURL: String("r"),
157+
EventsURL: String("e"),
158+
AvatarURL: String("a"),
159+
},
160+
},
161+
},
162+
}
163+
164+
want := `{
165+
"owner": {
166+
"from": {
167+
"organization": {
168+
"login": "l",
169+
"id": 1,
170+
"node_id": "n",
171+
"avatar_url": "a",
172+
"url": "u",
173+
"repos_url": "r",
174+
"events_url": "e"
175+
}
176+
}
177+
}
178+
}`
179+
180+
testJSONMarshal(t, u, want)
181+
}
182+
107183
func TestProjectChange_Marshal_NameChange(t *testing.T) {
108184
testJSONMarshal(t, &ProjectChange{}, "{}")
109185

github/github-accessors.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)