From da012217fe99e5585b45e4a5e849bfc39df9e0c8 Mon Sep 17 00:00:00 2001 From: sanjayy-gowdaa Date: Wed, 2 Jul 2025 03:03:33 +0530 Subject: [PATCH 1/2] Fix: Handle null assignee in Copilot API response --- github/copilot.go | 3 +++ github/copilot_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/github/copilot.go b/github/copilot.go index bed83536b41..5914f1d9df2 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -203,6 +203,9 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { cp.PlanType = seatDetail.PlanType switch v := seatDetail.Assignee.(type) { + case nil: + // Assignee can be null according to GitHub API specification + cp.Assignee = nil case map[string]any: jsonData, err := json.Marshal(seatDetail.Assignee) if err != nil { diff --git a/github/copilot_test.go b/github/copilot_test.go index ed81761370e..1aeb4308555 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -58,6 +58,16 @@ func TestCopilotSeatDetails_UnmarshalJSON(t *testing.T) { want: &CopilotSeatDetails{}, wantErr: true, }, + { + name: "Null Assignee", + data: `{ + "assignee": null + }`, + want: &CopilotSeatDetails{ + Assignee: nil, + }, + wantErr: false, + }, { name: "Invalid Assignee Field Type", data: `{ From 0e5803bbce689067be588e3a11a72eb88ddd4da2 Mon Sep 17 00:00:00 2001 From: sanjayy-gowdaa Date: Wed, 2 Jul 2025 03:33:41 +0530 Subject: [PATCH 2/2] Add documentation link and API version to null assignee comment --- github/copilot.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/github/copilot.go b/github/copilot.go index 5914f1d9df2..b4f21ad39aa 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -204,7 +204,9 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { switch v := seatDetail.Assignee.(type) { case nil: - // Assignee can be null according to GitHub API specification + // Assignee can be null according to GitHub API specification. + // See: https://docs.github.com/en/rest/copilot/copilot-user-management?apiVersion=2022-11-28#list-all-copilot-seat-assignments-for-an-organization + // Note: Copilot API is in public preview and subject to change. cp.Assignee = nil case map[string]any: jsonData, err := json.Marshal(seatDetail.Assignee)