From 6282c33e0c8d53381729ef090f093ef501c177b2 Mon Sep 17 00:00:00 2001 From: MasterOogway1466 <76559554+MasterOogway1466@users.noreply.github.com> Date: Sat, 11 Apr 2026 15:16:47 +0530 Subject: [PATCH 1/4] feat: add DownloadCopilotMetrics helper method and commented legacy metrics endpoints --- github/copilot.go | 44 +++++++++++++++++ github/copilot_test.go | 110 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) diff --git a/github/copilot.go b/github/copilot.go index bca4f77c4da..0ea86e46260 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -10,6 +10,7 @@ import ( "encoding/json" "errors" "fmt" + "net/http" "time" ) @@ -491,6 +492,10 @@ func (s *CopilotService) GetSeatDetails(ctx context.Context, org, user string) ( // GetEnterpriseMetrics gets Copilot usage metrics for an enterprise. // +// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. +// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. +// Use GetEnterpriseDailyMetricsReport or GetEnterpriseMetricsReport instead. +// // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/copilot/metrics @@ -517,6 +522,9 @@ func (s *CopilotService) GetEnterpriseMetrics(ctx context.Context, enterprise st // GetEnterpriseTeamMetrics gets Copilot usage metrics for an enterprise team. // +// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. +// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. +// // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise-team // //meta:operation GET /enterprises/{enterprise}/team/{team_slug}/copilot/metrics @@ -543,6 +551,10 @@ func (s *CopilotService) GetEnterpriseTeamMetrics(ctx context.Context, enterpris // GetOrganizationMetrics gets Copilot usage metrics for an organization. // +// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. +// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. +// Use GetOrganizationDailyMetricsReport or GetOrganizationMetricsReport instead. +// // GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-organization // //meta:operation GET /orgs/{org}/copilot/metrics @@ -569,6 +581,9 @@ func (s *CopilotService) GetOrganizationMetrics(ctx context.Context, org string, // GetOrganizationTeamMetrics gets Copilot usage metrics for an organization team. // +// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. +// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. +// // GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics#get-copilot-metrics-for-a-team // //meta:operation GET /orgs/{org}/team/{team_slug}/copilot/metrics @@ -784,3 +799,32 @@ func (s *CopilotService) GetOrganizationUsersMetricsReport(ctx context.Context, return report, resp, nil } + +// DownloadCopilotMetrics downloads a Copilot metrics report from the provided download link +// and returns the metric data. This can be used to download metrics from a link returned by +// GetEnterpriseDailyMetricsReport, GetEnterpriseMetricsReport, GetEnterpriseUsersDailyMetricsReport, +// GetEnterpriseUsersMetricsReport, GetOrganizationDailyMetricsReport, GetOrganizationMetricsReport, +// GetOrganizationUsersDailyMetricsReport, GetOrganizationUsersMetricsReport. +func (s *CopilotService) DownloadCopilotMetrics(ctx context.Context, url string) ([]*CopilotMetrics, *Response, error) { + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, nil, err + } + + resp, err := s.client.client.Do(req) + if err != nil { + return nil, nil, err + } + defer resp.Body.Close() + + if err := CheckResponse(resp); err != nil { + return nil, newResponse(resp), err + } + + var metrics []*CopilotMetrics + if err := json.NewDecoder(resp.Body).Decode(&metrics); err != nil { + return nil, newResponse(resp), err + } + + return metrics, newResponse(resp), nil +} diff --git a/github/copilot_test.go b/github/copilot_test.go index eb87edef7cd..911d333eb8e 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -2778,3 +2778,113 @@ func TestCopilotService_GetOrganizationUsersMetricsReport(t *testing.T) { return resp, err }) } + +func TestCopilotService_DownloadCopilotMetrics(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/path/to/download", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "date": "2023-01-01", + "total_active_users": 100, + "total_engaged_users": 50, + "copilot_ide_code_completions": { + "total_engaged_users": 50, + "languages": [ + { + "name": "go", + "total_engaged_users": 10 + } + ], + "editors": [ + { + "name": "vscode", + "total_engaged_users": 10, + "models": [ + { + "name": "model1", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 10, + "languages": [ + { + "name": "go", + "total_engaged_users": 10, + "total_code_suggestions": 100, + "total_code_acceptances": 50, + "total_code_lines_suggested": 1000, + "total_code_lines_accepted": 500 + } + ] + } + ] + } + ] + } + }]`) + }) + + ctx := t.Context() + url := client.BaseURL.String() + "path/to/download" + got, _, err := client.Copilot.DownloadCopilotMetrics(ctx, url) + if err != nil { + t.Errorf("Copilot.DownloadCopilotMetrics returned error: %v", err) + } + + want := []*CopilotMetrics{ + { + Date: "2023-01-01", + TotalActiveUsers: Ptr(100), + TotalEngagedUsers: Ptr(50), + CopilotIDECodeCompletions: &CopilotIDECodeCompletions{ + TotalEngagedUsers: 50, + Languages: []*CopilotIDECodeCompletionsLanguage{ + { + Name: "go", + TotalEngagedUsers: 10, + }, + }, + Editors: []*CopilotIDECodeCompletionsEditor{ + { + Name: "vscode", + TotalEngagedUsers: 10, + Models: []*CopilotIDECodeCompletionsModel{ + { + Name: "model1", + IsCustomModel: false, + TotalEngagedUsers: 10, + Languages: []*CopilotIDECodeCompletionsModelLanguage{ + { + Name: "go", + TotalEngagedUsers: 10, + TotalCodeSuggestions: 100, + TotalCodeAcceptances: 50, + TotalCodeLinesSuggested: 1000, + TotalCodeLinesAccepted: 500, + }, + }, + }, + }, + }, + }, + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Copilot.DownloadCopilotMetrics returned %+v, want %+v", got, want) + } + + // Test unexpected status code + mux.HandleFunc("/path/to/download/error", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.WriteHeader(http.StatusNotFound) + }) + + urlErr := client.BaseURL.String() + "path/to/download/error" + _, _, err = client.Copilot.DownloadCopilotMetrics(ctx, urlErr) + if err == nil { + t.Errorf("Copilot.DownloadCopilotMetrics expected error but got none") + } +} From b4818cfb152e5663ab402e5dbd6b375a41d03666 Mon Sep 17 00:00:00 2001 From: MasterOogway1466 <76559554+MasterOogway1466@users.noreply.github.com> Date: Sat, 11 Apr 2026 21:57:53 +0530 Subject: [PATCH 2/4] docs: update Copilot API documentation links and deprecation notices --- github/copilot.go | 66 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/github/copilot.go b/github/copilot.go index 0ea86e46260..876ba8c4a16 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -17,7 +17,7 @@ import ( // CopilotService provides access to the Copilot-related functions // in the GitHub API. // -// GitHub API docs: https://docs.github.com/en/rest/copilot/ +// GitHub API docs: https://docs.github.com/rest/copilot?apiVersion=2022-11-28 type CopilotService service // CopilotOrganizationDetails represents the details of an organization's Copilot for Business subscription. @@ -225,7 +225,7 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { switch v := seatDetail.Assignee.(type) { case nil: // 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 + // See: https://docs.github.com/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: @@ -280,7 +280,7 @@ func (cp *CopilotSeatDetails) GetOrganization() (*Organization, bool) { // GetCopilotBilling gets Copilot for Business billing information and settings for an organization. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management#get-copilot-seat-information-and-settings-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management?apiVersion=2022-11-28#get-copilot-seat-information-and-settings-for-an-organization // //meta:operation GET /orgs/{org}/copilot/billing func (s *CopilotService) GetCopilotBilling(ctx context.Context, org string) (*CopilotOrganizationDetails, *Response, error) { @@ -304,7 +304,7 @@ func (s *CopilotService) GetCopilotBilling(ctx context.Context, org string) (*Co // // To paginate through all seats, populate 'Page' with the number of the last page. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management#list-all-copilot-seat-assignments-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management?apiVersion=2022-11-28#list-all-copilot-seat-assignments-for-an-organization // //meta:operation GET /orgs/{org}/copilot/billing/seats func (s *CopilotService) ListCopilotSeats(ctx context.Context, org string, opts *ListOptions) (*ListCopilotSeatsResponse, *Response, error) { @@ -332,7 +332,7 @@ func (s *CopilotService) ListCopilotSeats(ctx context.Context, org string, opts // // To paginate through all seats, populate 'Page' with the number of the last page. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-user-management#list-all-copilot-seat-assignments-for-an-enterprise +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-user-management?apiVersion=2022-11-28#list-all-copilot-seat-assignments-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/copilot/billing/seats func (s *CopilotService) ListCopilotEnterpriseSeats(ctx context.Context, enterprise string, opts *ListOptions) (*ListCopilotSeatsResponse, *Response, error) { @@ -358,7 +358,7 @@ func (s *CopilotService) ListCopilotEnterpriseSeats(ctx context.Context, enterpr // AddCopilotTeams adds teams to the Copilot for Business subscription for an organization. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management#add-teams-to-the-copilot-subscription-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management?apiVersion=2022-11-28#add-teams-to-the-copilot-subscription-for-an-organization // //meta:operation POST /orgs/{org}/copilot/billing/selected_teams func (s *CopilotService) AddCopilotTeams(ctx context.Context, org string, teamNames []string) (*SeatAssignments, *Response, error) { @@ -386,7 +386,7 @@ func (s *CopilotService) AddCopilotTeams(ctx context.Context, org string, teamNa // RemoveCopilotTeams removes teams from the Copilot for Business subscription for an organization. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management#remove-teams-from-the-copilot-subscription-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management?apiVersion=2022-11-28#remove-teams-from-the-copilot-subscription-for-an-organization // //meta:operation DELETE /orgs/{org}/copilot/billing/selected_teams func (s *CopilotService) RemoveCopilotTeams(ctx context.Context, org string, teamNames []string) (*SeatCancellations, *Response, error) { @@ -414,7 +414,7 @@ func (s *CopilotService) RemoveCopilotTeams(ctx context.Context, org string, tea // AddCopilotUsers adds users to the Copilot for Business subscription for an organization // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management#add-users-to-the-copilot-subscription-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management?apiVersion=2022-11-28#add-users-to-the-copilot-subscription-for-an-organization // //meta:operation POST /orgs/{org}/copilot/billing/selected_users func (s *CopilotService) AddCopilotUsers(ctx context.Context, org string, users []string) (*SeatAssignments, *Response, error) { @@ -442,7 +442,7 @@ func (s *CopilotService) AddCopilotUsers(ctx context.Context, org string, users // RemoveCopilotUsers removes users from the Copilot for Business subscription for an organization. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management#remove-users-from-the-copilot-subscription-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management?apiVersion=2022-11-28#remove-users-from-the-copilot-subscription-for-an-organization // //meta:operation DELETE /orgs/{org}/copilot/billing/selected_users func (s *CopilotService) RemoveCopilotUsers(ctx context.Context, org string, users []string) (*SeatCancellations, *Response, error) { @@ -470,7 +470,7 @@ func (s *CopilotService) RemoveCopilotUsers(ctx context.Context, org string, use // GetSeatDetails gets Copilot for Business seat assignment details for a user. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management#get-copilot-seat-assignment-details-for-a-user +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-user-management?apiVersion=2022-11-28#get-copilot-seat-assignment-details-for-a-user // //meta:operation GET /orgs/{org}/members/{username}/copilot func (s *CopilotService) GetSeatDetails(ctx context.Context, org, user string) (*CopilotSeatDetails, *Response, error) { @@ -492,11 +492,11 @@ func (s *CopilotService) GetSeatDetails(ctx context.Context, org, user string) ( // GetEnterpriseMetrics gets Copilot usage metrics for an enterprise. // -// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. -// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. -// Use GetEnterpriseDailyMetricsReport or GetEnterpriseMetricsReport instead. +// Deprecated: This endpoint was closed down on April 2, 2026 for github.com. +// It may still be available for GitHub Enterprise Server. Use GetEnterpriseDailyMetricsReport +// or GetEnterpriseMetricsReport instead. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-metrics?apiVersion=2022-11-28#get-copilot-metrics-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/copilot/metrics func (s *CopilotService) GetEnterpriseMetrics(ctx context.Context, enterprise string, opts *CopilotMetricsListOptions) ([]*CopilotMetrics, *Response, error) { @@ -522,10 +522,11 @@ func (s *CopilotService) GetEnterpriseMetrics(ctx context.Context, enterprise st // GetEnterpriseTeamMetrics gets Copilot usage metrics for an enterprise team. // -// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. -// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. +// Deprecated: This endpoint was closed down on April 2, 2026 for github.com. +// It may still be available for GitHub Enterprise Server. Use GetEnterpriseDailyMetricsReport +// or GetEnterpriseMetricsReport instead. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise-team +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-metrics?apiVersion=2022-11-28#get-copilot-metrics-for-an-enterprise-team // //meta:operation GET /enterprises/{enterprise}/team/{team_slug}/copilot/metrics func (s *CopilotService) GetEnterpriseTeamMetrics(ctx context.Context, enterprise, team string, opts *CopilotMetricsListOptions) ([]*CopilotMetrics, *Response, error) { @@ -551,11 +552,11 @@ func (s *CopilotService) GetEnterpriseTeamMetrics(ctx context.Context, enterpris // GetOrganizationMetrics gets Copilot usage metrics for an organization. // -// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. -// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. -// Use GetOrganizationDailyMetricsReport or GetOrganizationMetricsReport instead. +// Deprecated: This endpoint was closed down on April 2, 2026 for github.com. +// It may still be available for GitHub Enterprise Server. Use GetOrganizationDailyMetricsReport +// or GetOrganizationMetricsReport instead. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics?apiVersion=2022-11-28#get-copilot-metrics-for-an-organization // //meta:operation GET /orgs/{org}/copilot/metrics func (s *CopilotService) GetOrganizationMetrics(ctx context.Context, org string, opts *CopilotMetricsListOptions) ([]*CopilotMetrics, *Response, error) { @@ -581,10 +582,11 @@ func (s *CopilotService) GetOrganizationMetrics(ctx context.Context, org string, // GetOrganizationTeamMetrics gets Copilot usage metrics for an organization team. // -// Deprecated: Focus has shifted to the new Download Copilot Usage Metrics APIs. -// These endpoints are kept around for GitHub Enterprise Server users, but are no longer supported on the Public GitHub service. +// Deprecated: This endpoint was closed down on April 2, 2026 for github.com. +// It may still be available for GitHub Enterprise Server. Use GetOrganizationDailyMetricsReport +// or GetOrganizationMetricsReport instead. // -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics#get-copilot-metrics-for-a-team +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics?apiVersion=2022-11-28#get-copilot-metrics-for-a-team // //meta:operation GET /orgs/{org}/team/{team_slug}/copilot/metrics func (s *CopilotService) GetOrganizationTeamMetrics(ctx context.Context, org, team string, opts *CopilotMetricsListOptions) ([]*CopilotMetrics, *Response, error) { @@ -610,7 +612,7 @@ func (s *CopilotService) GetOrganizationTeamMetrics(ctx context.Context, org, te // GetEnterpriseDailyMetricsReport gets a report containing Copilot metrics for a single day for an enterprise. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-enterprise-usage-metrics-for-a-specific-day +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-enterprise-usage-metrics-for-a-specific-day // //meta:operation GET /enterprises/{enterprise}/copilot/metrics/reports/enterprise-1-day func (s *CopilotService) GetEnterpriseDailyMetricsReport(ctx context.Context, enterprise string, opts *CopilotMetricsReportOptions) (*CopilotDailyMetricsReport, *Response, error) { @@ -636,7 +638,7 @@ func (s *CopilotService) GetEnterpriseDailyMetricsReport(ctx context.Context, en // GetEnterpriseMetricsReport gets a report containing Copilot metrics for a 28-day rolling window for an enterprise. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-enterprise-usage-metrics +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-enterprise-usage-metrics // //meta:operation GET /enterprises/{enterprise}/copilot/metrics/reports/enterprise-28-day/latest func (s *CopilotService) GetEnterpriseMetricsReport(ctx context.Context, enterprise string) (*CopilotMetricsReport, *Response, error) { @@ -658,7 +660,7 @@ func (s *CopilotService) GetEnterpriseMetricsReport(ctx context.Context, enterpr // GetEnterpriseUsersDailyMetricsReport gets a report containing Copilot user metrics for a single day for an enterprise. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-users-usage-metrics-for-a-specific-day +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-users-usage-metrics-for-a-specific-day // //meta:operation GET /enterprises/{enterprise}/copilot/metrics/reports/users-1-day func (s *CopilotService) GetEnterpriseUsersDailyMetricsReport(ctx context.Context, enterprise string, opts *CopilotMetricsReportOptions) (*CopilotDailyMetricsReport, *Response, error) { @@ -684,7 +686,7 @@ func (s *CopilotService) GetEnterpriseUsersDailyMetricsReport(ctx context.Contex // GetEnterpriseUsersMetricsReport gets a report containing Copilot user metrics for a 28-day rolling window for an enterprise. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-users-usage-metrics +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-users-usage-metrics // //meta:operation GET /enterprises/{enterprise}/copilot/metrics/reports/users-28-day/latest func (s *CopilotService) GetEnterpriseUsersMetricsReport(ctx context.Context, enterprise string) (*CopilotMetricsReport, *Response, error) { @@ -706,7 +708,7 @@ func (s *CopilotService) GetEnterpriseUsersMetricsReport(ctx context.Context, en // GetOrganizationDailyMetricsReport gets a report containing Copilot metrics for a single day for an organization. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-organization-usage-metrics-for-a-specific-day +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-organization-usage-metrics-for-a-specific-day // //meta:operation GET /orgs/{org}/copilot/metrics/reports/organization-1-day func (s *CopilotService) GetOrganizationDailyMetricsReport(ctx context.Context, org string, opts *CopilotMetricsReportOptions) (*CopilotDailyMetricsReport, *Response, error) { @@ -732,7 +734,7 @@ func (s *CopilotService) GetOrganizationDailyMetricsReport(ctx context.Context, // GetOrganizationMetricsReport gets a report containing Copilot metrics for a 28-day rolling window for an organization. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-organization-usage-metrics +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-organization-usage-metrics // //meta:operation GET /orgs/{org}/copilot/metrics/reports/organization-28-day/latest func (s *CopilotService) GetOrganizationMetricsReport(ctx context.Context, org string) (*CopilotMetricsReport, *Response, error) { @@ -754,7 +756,7 @@ func (s *CopilotService) GetOrganizationMetricsReport(ctx context.Context, org s // GetOrganizationUsersDailyMetricsReport gets a report containing Copilot user metrics for a single day for an organization. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-organization-users-usage-metrics-for-a-specific-day +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-organization-users-usage-metrics-for-a-specific-day // //meta:operation GET /orgs/{org}/copilot/metrics/reports/users-1-day func (s *CopilotService) GetOrganizationUsersDailyMetricsReport(ctx context.Context, org string, opts *CopilotMetricsReportOptions) (*CopilotDailyMetricsReport, *Response, error) { @@ -780,7 +782,7 @@ func (s *CopilotService) GetOrganizationUsersDailyMetricsReport(ctx context.Cont // GetOrganizationUsersMetricsReport gets a report containing Copilot user metrics for a 28-day rolling window for an organization. // -// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics#get-copilot-organization-users-usage-metrics +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/copilot/copilot-usage-metrics?apiVersion=2022-11-28#get-copilot-organization-users-usage-metrics // //meta:operation GET /orgs/{org}/copilot/metrics/reports/users-28-day/latest func (s *CopilotService) GetOrganizationUsersMetricsReport(ctx context.Context, org string) (*CopilotMetricsReport, *Response, error) { From cfa26f98af868cc35b07bbacc71cef7b5202049b Mon Sep 17 00:00:00 2001 From: MasterOogway1466 <76559554+MasterOogway1466@users.noreply.github.com> Date: Sat, 11 Apr 2026 23:23:16 +0530 Subject: [PATCH 3/4] test: added more test cases for DownloadCopilotMetrics and skip the method in metadata --- github/copilot_test.go | 30 ++++++++++++++++++++++++++++-- tools/metadata/metadata.go | 1 + 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/github/copilot_test.go b/github/copilot_test.go index 911d333eb8e..3bdea2469fd 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -2827,10 +2827,13 @@ func TestCopilotService_DownloadCopilotMetrics(t *testing.T) { ctx := t.Context() url := client.BaseURL.String() + "path/to/download" - got, _, err := client.Copilot.DownloadCopilotMetrics(ctx, url) + got, resp, err := client.Copilot.DownloadCopilotMetrics(ctx, url) if err != nil { t.Errorf("Copilot.DownloadCopilotMetrics returned error: %v", err) } + if resp.StatusCode != http.StatusOK { + t.Errorf("Copilot.DownloadCopilotMetrics returned status code: %v", resp.StatusCode) + } want := []*CopilotMetrics{ { @@ -2885,6 +2888,29 @@ func TestCopilotService_DownloadCopilotMetrics(t *testing.T) { urlErr := client.BaseURL.String() + "path/to/download/error" _, _, err = client.Copilot.DownloadCopilotMetrics(ctx, urlErr) if err == nil { - t.Errorf("Copilot.DownloadCopilotMetrics expected error but got none") + t.Error("Copilot.DownloadCopilotMetrics expected error but got none") + } + + // Test invalid URL (fails http.NewRequestWithContext) + _, _, err = client.Copilot.DownloadCopilotMetrics(ctx, "\n") + if err == nil { + t.Error("Copilot.DownloadCopilotMetrics expected error for invalid URL, got none") + } + + // Test invalid scheme (fails client.Do) + _, _, err = client.Copilot.DownloadCopilotMetrics(ctx, "invalid-scheme://test") + if err == nil { + t.Error("Copilot.DownloadCopilotMetrics expected error for invalid scheme, got none") + } + + // Test json decoding error + mux.HandleFunc("/path/to/download/badjson", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{invalid JSON`) + }) + urlBadJson := client.BaseURL.String() + "path/to/download/badjson" + _, _, err = client.Copilot.DownloadCopilotMetrics(ctx, urlBadJson) + if err == nil { + t.Error("Copilot.DownloadCopilotMetrics expected error for bad JSON, got none") } } diff --git a/tools/metadata/metadata.go b/tools/metadata/metadata.go index dd4bcfe47a4..1d14d223238 100644 --- a/tools/metadata/metadata.go +++ b/tools/metadata/metadata.go @@ -547,4 +547,5 @@ var skipServiceMethod = map[string]bool{ "BillingService.GetOrganizationStorageBilling": true, "BillingService.GetPackagesBilling": true, "BillingService.GetStorageBilling": true, + "CopilotService.DownloadCopilotMetrics": true, } From 5349287d72d1f93da8de2312c44903e77d46e63e Mon Sep 17 00:00:00 2001 From: Manas Shetty <76559554+MasterOogway1466@users.noreply.github.com> Date: Sun, 12 Apr 2026 09:36:49 +0530 Subject: [PATCH 4/4] Update github/copilot_test.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/copilot_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/copilot_test.go b/github/copilot_test.go index 3bdea2469fd..81c1f06cf13 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -2908,7 +2908,7 @@ func TestCopilotService_DownloadCopilotMetrics(t *testing.T) { testMethod(t, r, "GET") fmt.Fprint(w, `[{invalid JSON`) }) - urlBadJson := client.BaseURL.String() + "path/to/download/badjson" + urlBadJSON := client.BaseURL.String() + "path/to/download/badjson" _, _, err = client.Copilot.DownloadCopilotMetrics(ctx, urlBadJson) if err == nil { t.Error("Copilot.DownloadCopilotMetrics expected error for bad JSON, got none")