Skip to content

Commit 21c2976

Browse files
fix: Handle null assignee in Copilot Seat Billing API response (#3619)
1 parent eff2bbd commit 21c2976

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

github/copilot.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error {
203203
cp.PlanType = seatDetail.PlanType
204204

205205
switch v := seatDetail.Assignee.(type) {
206+
case nil:
207+
// Assignee can be null according to GitHub API specification.
208+
// See: https://docs.github.com/en/rest/copilot/copilot-user-management?apiVersion=2022-11-28#list-all-copilot-seat-assignments-for-an-organization
209+
// Note: Copilot API is in public preview and subject to change.
210+
cp.Assignee = nil
206211
case map[string]any:
207212
jsonData, err := json.Marshal(seatDetail.Assignee)
208213
if err != nil {

github/copilot_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ func TestCopilotSeatDetails_UnmarshalJSON(t *testing.T) {
5858
want: &CopilotSeatDetails{},
5959
wantErr: true,
6060
},
61+
{
62+
name: "Null Assignee",
63+
data: `{
64+
"assignee": null
65+
}`,
66+
want: &CopilotSeatDetails{
67+
Assignee: nil,
68+
},
69+
wantErr: false,
70+
},
6171
{
6272
name: "Invalid Assignee Field Type",
6373
data: `{

0 commit comments

Comments
 (0)