From 1999e7dfb4a1a38e8751b75661f05153a53e3b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Mon, 18 Nov 2024 13:36:35 +0100 Subject: [PATCH 1/9] Support Copilot metrics endpoints --- github/copilot.go | 196 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/github/copilot.go b/github/copilot.go index 7ea13bd7c85..0bb4e7abfe5 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -99,6 +99,98 @@ type CopilotUsageSummary struct { Breakdown []*CopilotUsageBreakdown `json:"breakdown"` } +// CopilotMetricsListOptions represents the optional parameters to the CopilotService get metrics methods. +type CopilotMetricsListOptions struct { + Since *time.Time `url:"since,omitempty"` + Until *time.Time `url:"until,omitempty"` + + ListOptions +} + +// CopilotIdeCodeCompletions represents Copilot usage metrics for Copilot code completions in the IDE, categorized by editor, model and language. +type CopilotIdeCodeCompletions struct { + TotalEngagedUsers int `json:"total_engaged_users"` + Languages []*struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + } `json:"languages"` + Editors []*struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalEngagedUsers int `json:"total_engaged_users"` + Languages []*struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + TotalCodeSuggestions int `json:"total_code_suggestions"` + TotalCodeAcceptances int `json:"total_code_acceptances"` + TotalCodeLinesSuggested int `json:"total_code_lines_suggested"` + TotalCodeLinesAccepted int `json:"total_code_lines_accepted"` + } `json:"languages"` + } `json:"models"` + } `json:"editors"` +} + +// CopilotIdeChat represents Copilot usage metrics for Copilot Chat in the IDE, categorized by editor and model. +type CopilotIdeChat struct { + TotalEngagedUsers int `json:"total_engaged_users"` + Editors []*struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalEngagedUsers int `json:"total_engaged_users"` + TotalChats int `json:"total_chats"` + TotalChatInsertionEvents int `json:"total_chat_insertion_events"` + TotalChatCopyEvents int `json:"total_chat_copy_events"` + } `json:"models"` + } `json:"editors"` +} + +// CopilotDotcomChat represents Copilot usage metrics for Copilot Chat in the webbrowser, categorized by model. +type CopilotDotcomChat struct { + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalEngagedUsers int `json:"total_engaged_users"` + TotalChats int `json:"total_chats"` + } `json:"models"` +} + +// CopilotDotcomPullRequests represents Copilot usage metrics for pull requests in the webbrowser, categorized by repository and model. +type CopilotDotcomPullRequests struct { + TotalEngagedUsers int `json:"total_engaged_users"` + Repositories []*struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalPrSummariesCreated int `json:"total_pr_summaries_created"` + TotalEngagedUsers int `json:"total_engaged_users"` + } `json:"models"` + } `json:"repositories"` +} + +// CopilotMetrics represents Copilot usage metrics for a given day. +type CopilotMetrics struct { + Date string `json:"date"` + TotalActiveUsers int `json:"total_active_users"` + TotalEngagedUsers int `json:"total_engaged_users"` + CopilotIdeCodeCompletions *CopilotIdeCodeCompletions `json:"copilot_ide_code_completions"` + CopilotIdeChat *CopilotIdeChat `json:"copilot_ide_chat"` + CopilotDotcomChat *CopilotDotcomChat `json:"copilot_dotcom_chat"` + CopilotDotcomPullRequests *CopilotDotcomPullRequests `json:"copilot_dotcom_pull_requests"` +} + func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { // Using an alias to avoid infinite recursion when calling json.Unmarshal type alias CopilotSeatDetails @@ -482,3 +574,107 @@ func (s *CopilotService) GetOrganizationTeamUsage(ctx context.Context, org, team return usage, resp, nil } + +// GetEnterpriseMetrics +// +// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#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) { + u := fmt.Sprintf("enterprises/%v/copilot/metrics", enterprise) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var metrics []*CopilotMetrics + resp, err := s.client.Do(ctx, req, &metrics) + if err != nil { + return nil, resp, err + } + + return metrics, resp, nil +} + +// GetEnterpriseTeamMetrics +// +// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#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) { + u := fmt.Sprintf("enterprises/%v/team/%v/copilot/metrics", enterprise, team) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var metrics []*CopilotMetrics + resp, err := s.client.Do(ctx, req, &metrics) + if err != nil { + return nil, resp, err + } + + return metrics, resp, nil +} + +// GetOrganizationMetrics +// +// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#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) { + u := fmt.Sprintf("orgs/%v/copilot/metrics", org) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var metrics []*CopilotMetrics + resp, err := s.client.Do(ctx, req, &metrics) + if err != nil { + return nil, resp, err + } + + return metrics, resp, nil +} + +// GetOrganizationTeamMetrics +// +// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#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) { + u := fmt.Sprintf("orgs/%v/team/%v/copilot/metrics", org, team) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var metrics []*CopilotMetrics + resp, err := s.client.Do(ctx, req, &metrics) + if err != nil { + return nil, resp, err + } + + return metrics, resp, nil +} From cdd3baa719301ca066fab61717dc361949bba95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Mon, 18 Nov 2024 13:38:14 +0100 Subject: [PATCH 2/9] Remove Copilot usage endpoints --- github/copilot.go | 137 ---------------------------------------------- 1 file changed, 137 deletions(-) diff --git a/github/copilot.go b/github/copilot.go index 0bb4e7abfe5..aff77ad9b19 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -66,39 +66,6 @@ type SeatCancellations struct { SeatsCancelled int `json:"seats_cancelled"` } -// CopilotUsageSummaryListOptions represents the optional parameters to the CopilotService.GetOrganizationUsage method. -type CopilotUsageSummaryListOptions struct { - Since *time.Time `url:"since,omitempty"` - Until *time.Time `url:"until,omitempty"` - - ListOptions -} - -// CopilotUsageBreakdown represents the breakdown of Copilot usage for a specific language and editor. -type CopilotUsageBreakdown struct { - Language string `json:"language"` - Editor string `json:"editor"` - SuggestionsCount int64 `json:"suggestions_count"` - AcceptancesCount int64 `json:"acceptances_count"` - LinesSuggested int64 `json:"lines_suggested"` - LinesAccepted int64 `json:"lines_accepted"` - ActiveUsers int `json:"active_users"` -} - -// CopilotUsageSummary represents the daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE across an organization. -type CopilotUsageSummary struct { - Day string `json:"day"` - TotalSuggestionsCount int64 `json:"total_suggestions_count"` - TotalAcceptancesCount int64 `json:"total_acceptances_count"` - TotalLinesSuggested int64 `json:"total_lines_suggested"` - TotalLinesAccepted int64 `json:"total_lines_accepted"` - TotalActiveUsers int64 `json:"total_active_users"` - TotalChatAcceptances int64 `json:"total_chat_acceptances"` - TotalChatTurns int64 `json:"total_chat_turns"` - TotalActiveChatUsers int `json:"total_active_chat_users"` - Breakdown []*CopilotUsageBreakdown `json:"breakdown"` -} - // CopilotMetricsListOptions represents the optional parameters to the CopilotService get metrics methods. type CopilotMetricsListOptions struct { Since *time.Time `url:"since,omitempty"` @@ -471,110 +438,6 @@ func (s *CopilotService) GetSeatDetails(ctx context.Context, org, user string) ( return seatDetails, resp, nil } -// GetOrganizationUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE across an organization. -// -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-organization-members -// -//meta:operation GET /orgs/{org}/copilot/usage -func (s *CopilotService) GetOrganizationUsage(ctx context.Context, org string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { - u := fmt.Sprintf("orgs/%v/copilot/usage", org) - u, err := addOptions(u, opts) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var usage []*CopilotUsageSummary - resp, err := s.client.Do(ctx, req, &usage) - if err != nil { - return nil, resp, err - } - - return usage, resp, nil -} - -// GetEnterpriseUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE across an enterprise. -// -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-enterprise-members -// -//meta:operation GET /enterprises/{enterprise}/copilot/usage -func (s *CopilotService) GetEnterpriseUsage(ctx context.Context, enterprise string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { - u := fmt.Sprintf("enterprises/%v/copilot/usage", enterprise) - u, err := addOptions(u, opts) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var usage []*CopilotUsageSummary - resp, err := s.client.Do(ctx, req, &usage) - if err != nil { - return nil, resp, err - } - - return usage, resp, nil -} - -// GetEnterpriseTeamUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE for a team in the enterprise. -// -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-an-enterprise-team -// -//meta:operation GET /enterprises/{enterprise}/team/{team_slug}/copilot/usage -func (s *CopilotService) GetEnterpriseTeamUsage(ctx context.Context, enterprise, team string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { - u := fmt.Sprintf("enterprises/%v/team/%v/copilot/usage", enterprise, team) - u, err := addOptions(u, opts) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var usage []*CopilotUsageSummary - resp, err := s.client.Do(ctx, req, &usage) - if err != nil { - return nil, resp, err - } - - return usage, resp, nil -} - -// GetOrganizationTeamUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE for a team in the organization. -// -// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-a-team -// -//meta:operation GET /orgs/{org}/team/{team_slug}/copilot/usage -func (s *CopilotService) GetOrganizationTeamUsage(ctx context.Context, org, team string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { - u := fmt.Sprintf("orgs/%v/team/%v/copilot/usage", org, team) - u, err := addOptions(u, opts) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest("GET", u, nil) - if err != nil { - return nil, nil, err - } - - var usage []*CopilotUsageSummary - resp, err := s.client.Do(ctx, req, &usage) - if err != nil { - return nil, resp, err - } - - return usage, resp, nil -} - // GetEnterpriseMetrics // // GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise From 6f9ab4d067324b1f6c2424ec60fa253182ed0c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Mon, 18 Nov 2024 14:32:51 +0100 Subject: [PATCH 3/9] Test Copilot metric endpoints --- github/copilot.go | 140 +-- github/copilot_test.go | 1798 ++++++++++++++++++++----------- github/github-accessors.go | 96 +- github/github-accessors_test.go | 120 ++- 4 files changed, 1436 insertions(+), 718 deletions(-) diff --git a/github/copilot.go b/github/copilot.go index aff77ad9b19..828da2e15b8 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -74,77 +74,95 @@ type CopilotMetricsListOptions struct { ListOptions } +type CopilotIdeCodeCompletionsLanguage struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` +} + +type CopilotIdeCodeCompletionsModelLanguage struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + TotalCodeSuggestions int `json:"total_code_suggestions"` + TotalCodeAcceptances int `json:"total_code_acceptances"` + TotalCodeLinesSuggested int `json:"total_code_lines_suggested"` + TotalCodeLinesAccepted int `json:"total_code_lines_accepted"` +} + +type CopilotIdeCodeCompletionsModel struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalEngagedUsers int `json:"total_engaged_users"` + Languages []*CopilotIdeCodeCompletionsModelLanguage `json:"languages"` +} + +type CopilotIdeCodeCompletionsEditor struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*CopilotIdeCodeCompletionsModel `json:"models"` +} + // CopilotIdeCodeCompletions represents Copilot usage metrics for Copilot code completions in the IDE, categorized by editor, model and language. type CopilotIdeCodeCompletions struct { - TotalEngagedUsers int `json:"total_engaged_users"` - Languages []*struct { - Name string `json:"name"` - TotalEngagedUsers int `json:"total_engaged_users"` - } `json:"languages"` - Editors []*struct { - Name string `json:"name"` - TotalEngagedUsers int `json:"total_engaged_users"` - Models []*struct { - Name string `json:"name"` - IsCustomModel bool `json:"is_custom_model"` - CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` - TotalEngagedUsers int `json:"total_engaged_users"` - Languages []*struct { - Name string `json:"name"` - TotalEngagedUsers int `json:"total_engaged_users"` - TotalCodeSuggestions int `json:"total_code_suggestions"` - TotalCodeAcceptances int `json:"total_code_acceptances"` - TotalCodeLinesSuggested int `json:"total_code_lines_suggested"` - TotalCodeLinesAccepted int `json:"total_code_lines_accepted"` - } `json:"languages"` - } `json:"models"` - } `json:"editors"` + TotalEngagedUsers int `json:"total_engaged_users"` + Languages []*CopilotIdeCodeCompletionsLanguage `json:"languages"` + Editors []*CopilotIdeCodeCompletionsEditor `json:"editors"` +} + +type CopilotIdeChatModel struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalEngagedUsers int `json:"total_engaged_users"` + TotalChats int `json:"total_chats"` + TotalChatInsertionEvents int `json:"total_chat_insertion_events"` + TotalChatCopyEvents int `json:"total_chat_copy_events"` +} + +type CopilotIdeChatEditor struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*CopilotIdeChatModel `json:"models"` } // CopilotIdeChat represents Copilot usage metrics for Copilot Chat in the IDE, categorized by editor and model. type CopilotIdeChat struct { - TotalEngagedUsers int `json:"total_engaged_users"` - Editors []*struct { - Name string `json:"name"` - TotalEngagedUsers int `json:"total_engaged_users"` - Models []*struct { - Name string `json:"name"` - IsCustomModel bool `json:"is_custom_model"` - CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` - TotalEngagedUsers int `json:"total_engaged_users"` - TotalChats int `json:"total_chats"` - TotalChatInsertionEvents int `json:"total_chat_insertion_events"` - TotalChatCopyEvents int `json:"total_chat_copy_events"` - } `json:"models"` - } `json:"editors"` + TotalEngagedUsers int `json:"total_engaged_users"` + Editors []*CopilotIdeChatEditor `json:"editors"` +} + +type CopilotDotcomChatModel struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalEngagedUsers int `json:"total_engaged_users"` + TotalChats int `json:"total_chats"` } // CopilotDotcomChat represents Copilot usage metrics for Copilot Chat in the webbrowser, categorized by model. type CopilotDotcomChat struct { - TotalEngagedUsers int `json:"total_engaged_users"` - Models []*struct { - Name string `json:"name"` - IsCustomModel bool `json:"is_custom_model"` - CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` - TotalEngagedUsers int `json:"total_engaged_users"` - TotalChats int `json:"total_chats"` - } `json:"models"` + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*CopilotDotcomChatModel `json:"models"` +} + +type CopilotDotcomPullRequestsModel struct { + Name string `json:"name"` + IsCustomModel bool `json:"is_custom_model"` + CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` + TotalPrSummariesCreated int `json:"total_pr_summaries_created"` + TotalEngagedUsers int `json:"total_engaged_users"` +} + +type CopilotDotcomPullRequestsRepository struct { + Name string `json:"name"` + TotalEngagedUsers int `json:"total_engaged_users"` + Models []*CopilotDotcomPullRequestsModel `json:"models"` } // CopilotDotcomPullRequests represents Copilot usage metrics for pull requests in the webbrowser, categorized by repository and model. type CopilotDotcomPullRequests struct { - TotalEngagedUsers int `json:"total_engaged_users"` - Repositories []*struct { - Name string `json:"name"` - TotalEngagedUsers int `json:"total_engaged_users"` - Models []*struct { - Name string `json:"name"` - IsCustomModel bool `json:"is_custom_model"` - CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` - TotalPrSummariesCreated int `json:"total_pr_summaries_created"` - TotalEngagedUsers int `json:"total_engaged_users"` - } `json:"models"` - } `json:"repositories"` + TotalEngagedUsers int `json:"total_engaged_users"` + Repositories []*CopilotDotcomPullRequestsRepository `json:"repositories"` } // CopilotMetrics represents Copilot usage metrics for a given day. @@ -438,7 +456,7 @@ func (s *CopilotService) GetSeatDetails(ctx context.Context, org, user string) ( return seatDetails, resp, nil } -// GetEnterpriseMetrics +// GetEnterpriseMetrics gets Copilot usage metrics for an enterprise. // // GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise // @@ -464,7 +482,7 @@ func (s *CopilotService) GetEnterpriseMetrics(ctx context.Context, enterprise st return metrics, resp, nil } -// GetEnterpriseTeamMetrics +// GetEnterpriseTeamMetrics gets Copilot usage metrics for an enterprise team. // // GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise-team // @@ -490,7 +508,7 @@ func (s *CopilotService) GetEnterpriseTeamMetrics(ctx context.Context, enterpris return metrics, resp, nil } -// GetOrganizationMetrics +// GetOrganizationMetrics gets Copilot usage metrics for an organization. // // GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-organization // @@ -516,7 +534,7 @@ func (s *CopilotService) GetOrganizationMetrics(ctx context.Context, org string, return metrics, resp, nil } -// GetOrganizationTeamMetrics +// GetOrganizationTeamMetrics gets Copilot usage metrics for an organization team. // // GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-a-team // diff --git a/github/copilot_test.go b/github/copilot_test.go index 6ac689a9efe..7ebad92a4e6 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -1127,805 +1127,1365 @@ func TestCopilotService_GetSeatDetails(t *testing.T) { }) } -func TestCopilotService_GetOrganisationUsage(t *testing.T) { +func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/orgs/o/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/enterprises/e/copilot/metrics", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `[ { - "day": "2023-10-15", - "total_suggestions_count": 1000, - "total_acceptances_count": 800, - "total_lines_suggested": 1800, - "total_lines_accepted": 1200, - "total_active_users": 10, - "total_chat_acceptances": 32, - "total_chat_turns": 200, - "total_active_chat_users": 4, - "breakdown": [ - { - "language": "python", - "editor": "vscode", - "suggestions_count": 300, - "acceptances_count": 250, - "lines_suggested": 900, - "lines_accepted": 700, - "active_users": 5 - }, - { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 300, - "acceptances_count": 200, - "lines_suggested": 400, - "lines_accepted": 300, - "active_users": 2 + "date": "2024-06-24", + "total_active_users": 24, + "total_engaged_users": 20, + "copilot_ide_code_completions": { + "total_engaged_users": 20, + "languages": [ + { + "name": "python", + "total_engaged_users": 10 + }, + { + "name": "ruby", + "total_engaged_users": 10 + } + ], + "editors": [ + { + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 13, + "languages": [ + { + "name": "python", + "total_engaged_users": 6, + "total_code_suggestions": 249, + "total_code_acceptances": 123, + "total_code_lines_suggested": 225, + "total_code_lines_accepted": 135 + }, + { + "name": "ruby", + "total_engaged_users": 7, + "total_code_suggestions": 496, + "total_code_acceptances": 253, + "total_code_lines_suggested": 520, + "total_code_lines_accepted": 270 + } + ] + } + ] + }, + { + "name": "neovim", + "total_engaged_users": 7, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "languages": [ + { + "name": "typescript", + "total_engaged_users": 3, + "total_code_suggestions": 112, + "total_code_acceptances": 56, + "total_code_lines_suggested": 143, + "total_code_lines_accepted": 61 + }, + { + "name": "go", + "total_engaged_users": 4, + "total_code_suggestions": 132, + "total_code_acceptances": 67, + "total_code_lines_suggested": 154, + "total_code_lines_accepted": 72 + } + ] + } + ] + } + ] }, - { - "language": "ruby", - "editor": "vscode", - "suggestions_count": 400, - "acceptances_count": 350, - "lines_suggested": 500, - "lines_accepted": 200, - "active_users": 3 - } + "copilot_ide_chat": { + "total_engaged_users": 13, + "editors": [ + { + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 12, + "total_chats": 45, + "total_chat_insertion_events": 12, + "total_chat_copy_events": 16 + }, + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_engaged_users": 1, + "total_chats": 10, + "total_chat_insertion_events": 11, + "total_chat_copy_events": 3 + } + ] + } ] - }, - { - "day": "2023-10-16", - "total_suggestions_count": 800, - "total_acceptances_count": 600, - "total_lines_suggested": 1100, - "total_lines_accepted": 700, - "total_active_users": 12, - "total_chat_acceptances": 57, - "total_chat_turns": 426, - "total_active_chat_users": 8, - "breakdown": [ - { - "language": "python", - "editor": "vscode", - "suggestions_count": 300, - "acceptances_count": 200, - "lines_suggested": 600, - "lines_accepted": 300, - "active_users": 2 }, - { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 300, - "acceptances_count": 150, - "lines_suggested": 300, - "lines_accepted": 250, - "active_users": 6 + "copilot_dotcom_chat": { + "total_engaged_users": 14, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 14, + "total_chats": 38 + } + ] }, - { - "language": "ruby", - "editor": "vscode", - "suggestions_count": 200, - "acceptances_count": 150, - "lines_suggested": 200, - "lines_accepted": 150, - "active_users": 3 - } + "copilot_dotcom_pull_requests": { + "total_engaged_users": 12, + "repositories": [ + { + "name": "demo/repo1", + "total_engaged_users": 8, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_pr_summaries_created": 6, + "total_engaged_users": 8 + } + ] + }, + { + "name": "demo/repo2", + "total_engaged_users": 4, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_pr_summaries_created": 10, + "total_engaged_users": 4 + } + ] + } ] + } } ]`) }) - summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) - summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) ctx := context.Background() - got, _, err := client.Copilot.GetOrganizationUsage(ctx, "o", &CopilotUsageSummaryListOptions{}) + got, _, err := client.Copilot.GetEnterpriseMetrics(ctx, "e", &CopilotMetricsListOptions{}) if err != nil { - t.Errorf("Copilot.GetOrganizationUsage returned error: %v", err) + t.Errorf("Copilot.GetEnterpriseMetrics returned error: %v", err) } - want := []*CopilotUsageSummary{ + want := []*CopilotMetrics{ { - Day: summaryOne.Format("2006-01-02"), - TotalSuggestionsCount: 1000, - TotalAcceptancesCount: 800, - TotalLinesSuggested: 1800, - TotalLinesAccepted: 1200, - TotalActiveUsers: 10, - TotalChatAcceptances: 32, - TotalChatTurns: 200, - TotalActiveChatUsers: 4, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 300, - AcceptancesCount: 250, - LinesSuggested: 900, - LinesAccepted: 700, - ActiveUsers: 5, - }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 300, - AcceptancesCount: 200, - LinesSuggested: 400, - LinesAccepted: 300, - ActiveUsers: 2, + Date: "2024-06-24", + TotalActiveUsers: 24, + TotalEngagedUsers: 20, + CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + TotalEngagedUsers: 20, + Languages: []*CopilotIdeCodeCompletionsLanguage{ + { + Name: "python", + TotalEngagedUsers: 10, + }, + { + Name: "ruby", + TotalEngagedUsers: 10, + }, }, - { - Language: "ruby", - Editor: "vscode", - SuggestionsCount: 400, - AcceptancesCount: 350, - LinesSuggested: 500, - LinesAccepted: 200, - ActiveUsers: 3, + Editors: []*CopilotIdeCodeCompletionsEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 13, + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "python", + TotalEngagedUsers: 6, + TotalCodeSuggestions: 249, + TotalCodeAcceptances: 123, + TotalCodeLinesSuggested: 225, + TotalCodeLinesAccepted: 135, + }, + { + Name: "ruby", + TotalEngagedUsers: 7, + TotalCodeSuggestions: 496, + TotalCodeAcceptances: 253, + TotalCodeLinesSuggested: 520, + TotalCodeLinesAccepted: 270, + }, + }, + }, + }, + }, + { + Name: "neovim", + TotalEngagedUsers: 7, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "typescript", + TotalEngagedUsers: 3, + TotalCodeSuggestions: 112, + TotalCodeAcceptances: 56, + TotalCodeLinesSuggested: 143, + TotalCodeLinesAccepted: 61, + }, + { + Name: "go", + TotalEngagedUsers: 4, + TotalCodeSuggestions: 132, + TotalCodeAcceptances: 67, + TotalCodeLinesSuggested: 154, + TotalCodeLinesAccepted: 72, + }, + }, + }, + }, + }, }, }, - }, - { - Day: summaryTwoDate.Format("2006-01-02"), - TotalSuggestionsCount: 800, - TotalAcceptancesCount: 600, - TotalLinesSuggested: 1100, - TotalLinesAccepted: 700, - TotalActiveUsers: 12, - TotalChatAcceptances: 57, - TotalChatTurns: 426, - TotalActiveChatUsers: 8, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 300, - AcceptancesCount: 200, - LinesSuggested: 600, - LinesAccepted: 300, - ActiveUsers: 2, + CopilotIdeChat: &CopilotIdeChat{ + TotalEngagedUsers: 13, + Editors: []*CopilotIdeChatEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 12, + TotalChats: 45, + TotalChatInsertionEvents: 12, + TotalChatCopyEvents: 16, + }, + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalEngagedUsers: 1, + TotalChats: 10, + TotalChatInsertionEvents: 11, + TotalChatCopyEvents: 3, + }, + }, + }, }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 300, - AcceptancesCount: 150, - LinesSuggested: 300, - LinesAccepted: 250, - ActiveUsers: 6, + }, + CopilotDotcomChat: &CopilotDotcomChat{ + TotalEngagedUsers: 14, + Models: []*CopilotDotcomChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 14, + TotalChats: 38, + }, }, - { - Language: "ruby", - Editor: "vscode", - SuggestionsCount: 200, - AcceptancesCount: 150, - LinesSuggested: 200, - LinesAccepted: 150, - ActiveUsers: 3, + }, + CopilotDotcomPullRequests: &CopilotDotcomPullRequests{ + TotalEngagedUsers: 12, + Repositories: []*CopilotDotcomPullRequestsRepository{ + { + Name: "demo/repo1", + TotalEngagedUsers: 8, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalPrSummariesCreated: 6, + TotalEngagedUsers: 8, + }, + }, + }, + { + Name: "demo/repo2", + TotalEngagedUsers: 4, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalPrSummariesCreated: 10, + TotalEngagedUsers: 4, + }, + }, + }, }, }, }, } if !cmp.Equal(got, want) { - t.Errorf("Copilot.GetOrganizationUsage returned %+v, want %+v", got, want) + t.Errorf("Copilot.GetEnterpriseMetrics returned %+v, want %+v", got, want) } - const methodName = "GetOrganizationUsage" + const methodName = "GetEnterpriseMetrics" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Copilot.GetOrganizationUsage(ctx, "\n", &CopilotUsageSummaryListOptions{}) + _, _, err = client.Copilot.GetEnterpriseMetrics(ctx, "\n", &CopilotMetricsListOptions{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Copilot.GetOrganizationUsage(ctx, "o", &CopilotUsageSummaryListOptions{}) + got, resp, err := client.Copilot.GetEnterpriseMetrics(ctx, "e", &CopilotMetricsListOptions{}) if got != nil { - t.Errorf("Copilot.GetOrganizationUsage returned %+v, want nil", got) + t.Errorf("Copilot.GetEnterpriseMetrics returned %+v, want nil", got) } return resp, err }) } -func TestCopilotService_GetEnterpriseUsage(t *testing.T) { +func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/enterprises/e/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/enterprises/e/team/t/copilot/metrics", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `[ { - "day": "2023-10-15", - "total_suggestions_count": 5000, - "total_acceptances_count": 3000, - "total_lines_suggested": 7000, - "total_lines_accepted": 3500, - "total_active_users": 15, - "total_chat_acceptances": 45, - "total_chat_turns": 350, - "total_active_chat_users": 8, - "breakdown": [ - { - "language": "python", - "editor": "vscode", - "suggestions_count": 3000, - "acceptances_count": 2000, - "lines_suggested": 3000, - "lines_accepted": 1500, - "active_users": 5 - }, - { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 1000, - "acceptances_count": 500, - "lines_suggested": 2000, - "lines_accepted": 1000, - "active_users": 5 - }, - { - "language": "javascript", - "editor": "vscode", - "suggestions_count": 1000, - "acceptances_count": 500, - "lines_suggested": 2000, - "lines_accepted": 1000, - "active_users": 5 - } - ] - }, - { - "day": "2023-10-16", - "total_suggestions_count": 5200, - "total_acceptances_count": 5100, - "total_lines_suggested": 5300, - "total_lines_accepted": 5000, - "total_active_users": 15, - "total_chat_acceptances": 57, - "total_chat_turns": 455, - "total_active_chat_users": 12, - "breakdown": [ + "date": "2024-06-24", + "total_active_users": 24, + "total_engaged_users": 20, + "copilot_ide_code_completions": { + "total_engaged_users": 20, + "languages": [ { - "language": "python", - "editor": "vscode", - "suggestions_count": 3100, - "acceptances_count": 3000, - "lines_suggested": 3200, - "lines_accepted": 3100, - "active_users": 5 + "name": "python", + "total_engaged_users": 10 }, { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 1100, - "acceptances_count": 1000, - "lines_suggested": 1200, - "lines_accepted": 1100, - "active_users": 5 + "name": "ruby", + "total_engaged_users": 10 + } + ], + "editors": [ + { + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 13, + "languages": [ + { + "name": "python", + "total_engaged_users": 6, + "total_code_suggestions": 249, + "total_code_acceptances": 123, + "total_code_lines_suggested": 225, + "total_code_lines_accepted": 135 + }, + { + "name": "ruby", + "total_engaged_users": 7, + "total_code_suggestions": 496, + "total_code_acceptances": 253, + "total_code_lines_suggested": 520, + "total_code_lines_accepted": 270 + } + ] + } + ] }, { - "language": "javascript", - "editor": "vscode", - "suggestions_count": 1000, - "acceptances_count": 900, - "lines_suggested": 1100, - "lines_accepted": 1000, - "active_users": 5 + "name": "neovim", + "total_engaged_users": 7, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "languages": [ + { + "name": "typescript", + "total_engaged_users": 3, + "total_code_suggestions": 112, + "total_code_acceptances": 56, + "total_code_lines_suggested": 143, + "total_code_lines_accepted": 61 + }, + { + "name": "go", + "total_engaged_users": 4, + "total_code_suggestions": 132, + "total_code_acceptances": 67, + "total_code_lines_suggested": 154, + "total_code_lines_accepted": 72 + } + ] + } + ] + } + ] + }, + "copilot_ide_chat": { + "total_engaged_users": 13, + "editors": [ + { + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 12, + "total_chats": 45, + "total_chat_insertion_events": 12, + "total_chat_copy_events": 16 + }, + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_engaged_users": 1, + "total_chats": 10, + "total_chat_insertion_events": 11, + "total_chat_copy_events": 3 + } + ] } ] + }, + "copilot_dotcom_chat": { + "total_engaged_users": 14, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 14, + "total_chats": 38 + } + ] + }, + "copilot_dotcom_pull_requests": { + "total_engaged_users": 12, + "repositories": [ + { + "name": "demo/repo1", + "total_engaged_users": 8, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_pr_summaries_created": 6, + "total_engaged_users": 8 + } + ] + }, + { + "name": "demo/repo2", + "total_engaged_users": 4, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_pr_summaries_created": 10, + "total_engaged_users": 4 + } + ] + } + ] + } } ]`) }) - summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) - summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) ctx := context.Background() - got, _, err := client.Copilot.GetEnterpriseUsage(ctx, "e", &CopilotUsageSummaryListOptions{}) + got, _, err := client.Copilot.GetEnterpriseTeamMetrics(ctx, "e", "t", &CopilotMetricsListOptions{}) if err != nil { - t.Errorf("Copilot.GetEnterpriseUsage returned error: %v", err) + t.Errorf("Copilot.GetEnterpriseTeamMetrics returned error: %v", err) } - want := []*CopilotUsageSummary{ + want := []*CopilotMetrics{ { - Day: summaryOne.Format("2006-01-02"), - TotalSuggestionsCount: 5000, - TotalAcceptancesCount: 3000, - TotalLinesSuggested: 7000, - TotalLinesAccepted: 3500, - TotalActiveUsers: 15, - TotalChatAcceptances: 45, - TotalChatTurns: 350, - TotalActiveChatUsers: 8, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 3000, - AcceptancesCount: 2000, - LinesSuggested: 3000, - LinesAccepted: 1500, - ActiveUsers: 5, - }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 1000, - AcceptancesCount: 500, - LinesSuggested: 2000, - LinesAccepted: 1000, - ActiveUsers: 5, + Date: "2024-06-24", + TotalActiveUsers: 24, + TotalEngagedUsers: 20, + CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + TotalEngagedUsers: 20, + Languages: []*CopilotIdeCodeCompletionsLanguage{ + { + Name: "python", + TotalEngagedUsers: 10, + }, + { + Name: "ruby", + TotalEngagedUsers: 10, + }, }, - { - Language: "javascript", - Editor: "vscode", - SuggestionsCount: 1000, - AcceptancesCount: 500, - LinesSuggested: 2000, - LinesAccepted: 1000, - ActiveUsers: 5, + Editors: []*CopilotIdeCodeCompletionsEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 13, + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "python", + TotalEngagedUsers: 6, + TotalCodeSuggestions: 249, + TotalCodeAcceptances: 123, + TotalCodeLinesSuggested: 225, + TotalCodeLinesAccepted: 135, + }, + { + Name: "ruby", + TotalEngagedUsers: 7, + TotalCodeSuggestions: 496, + TotalCodeAcceptances: 253, + TotalCodeLinesSuggested: 520, + TotalCodeLinesAccepted: 270, + }, + }, + }, + }, + }, + { + Name: "neovim", + TotalEngagedUsers: 7, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "typescript", + TotalEngagedUsers: 3, + TotalCodeSuggestions: 112, + TotalCodeAcceptances: 56, + TotalCodeLinesSuggested: 143, + TotalCodeLinesAccepted: 61, + }, + { + Name: "go", + TotalEngagedUsers: 4, + TotalCodeSuggestions: 132, + TotalCodeAcceptances: 67, + TotalCodeLinesSuggested: 154, + TotalCodeLinesAccepted: 72, + }, + }, + }, + }, + }, }, }, - }, - { - Day: summaryTwoDate.Format("2006-01-02"), - TotalSuggestionsCount: 5200, - TotalAcceptancesCount: 5100, - TotalLinesSuggested: 5300, - TotalLinesAccepted: 5000, - TotalActiveUsers: 15, - TotalChatAcceptances: 57, - TotalChatTurns: 455, - TotalActiveChatUsers: 12, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 3100, - AcceptancesCount: 3000, - LinesSuggested: 3200, - LinesAccepted: 3100, - ActiveUsers: 5, + CopilotIdeChat: &CopilotIdeChat{ + TotalEngagedUsers: 13, + Editors: []*CopilotIdeChatEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 12, + TotalChats: 45, + TotalChatInsertionEvents: 12, + TotalChatCopyEvents: 16, + }, + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalEngagedUsers: 1, + TotalChats: 10, + TotalChatInsertionEvents: 11, + TotalChatCopyEvents: 3, + }, + }, + }, }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 1100, - AcceptancesCount: 1000, - LinesSuggested: 1200, - LinesAccepted: 1100, - ActiveUsers: 5, + }, + CopilotDotcomChat: &CopilotDotcomChat{ + TotalEngagedUsers: 14, + Models: []*CopilotDotcomChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 14, + TotalChats: 38, + }, }, - { - Language: "javascript", - Editor: "vscode", - SuggestionsCount: 1000, - AcceptancesCount: 900, - LinesSuggested: 1100, - LinesAccepted: 1000, - ActiveUsers: 5, + }, + CopilotDotcomPullRequests: &CopilotDotcomPullRequests{ + TotalEngagedUsers: 12, + Repositories: []*CopilotDotcomPullRequestsRepository{ + { + Name: "demo/repo1", + TotalEngagedUsers: 8, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalPrSummariesCreated: 6, + TotalEngagedUsers: 8, + }, + }, + }, + { + Name: "demo/repo2", + TotalEngagedUsers: 4, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalPrSummariesCreated: 10, + TotalEngagedUsers: 4, + }, + }, + }, }, }, }, } if !cmp.Equal(got, want) { - t.Errorf("Copilot.GetEnterpriseUsage returned %+v, want %+v", got, want) + t.Errorf("Copilot.GetEnterpriseTeamMetrics returned %+v, want %+v", got, want) } - const methodName = "GetEnterpriseUsage" + const methodName = "GetEnterpriseTeamMetrics" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Copilot.GetEnterpriseUsage(ctx, "\n", &CopilotUsageSummaryListOptions{}) + _, _, err = client.Copilot.GetEnterpriseTeamMetrics(ctx, "\n", "t", &CopilotMetricsListOptions{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Copilot.GetEnterpriseUsage(ctx, "e", &CopilotUsageSummaryListOptions{}) + got, resp, err := client.Copilot.GetEnterpriseTeamMetrics(ctx, "e", "t", &CopilotMetricsListOptions{}) if got != nil { - t.Errorf("Copilot.GetEnterpriseUsage returned %+v, want nil", got) + t.Errorf("Copilot.GetEnterpriseTeamMetrics returned %+v, want nil", got) } return resp, err }) } -func TestCopilotService_GetEnterpriseTeamUsage(t *testing.T) { +func TestCopilotService_GetOrganizationMetrics(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/enterprises/e/team/t/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/orgs/o/copilot/metrics", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `[ { - "day": "2023-10-15", - "total_suggestions_count": 1000, - "total_acceptances_count": 800, - "total_lines_suggested": 1800, - "total_lines_accepted": 1200, - "total_active_users": 10, - "total_chat_acceptances": 32, - "total_chat_turns": 200, - "total_active_chat_users": 4, - "breakdown": [ + "date": "2024-06-24", + "total_active_users": 24, + "total_engaged_users": 20, + "copilot_ide_code_completions": { + "total_engaged_users": 20, + "languages": [ { - "language": "python", - "editor": "vscode", - "suggestions_count": 300, - "acceptances_count": 250, - "lines_suggested": 900, - "lines_accepted": 700, - "active_users": 5 + "name": "python", + "total_engaged_users": 10 }, { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 300, - "acceptances_count": 200, - "lines_suggested": 400, - "lines_accepted": 300, - "active_users": 2 + "name": "ruby", + "total_engaged_users": 10 + } + ], + "editors": [ + { + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 13, + "languages": [ + { + "name": "python", + "total_engaged_users": 6, + "total_code_suggestions": 249, + "total_code_acceptances": 123, + "total_code_lines_suggested": 225, + "total_code_lines_accepted": 135 + }, + { + "name": "ruby", + "total_engaged_users": 7, + "total_code_suggestions": 496, + "total_code_acceptances": 253, + "total_code_lines_suggested": 520, + "total_code_lines_accepted": 270 + } + ] + } + ] }, { - "language": "ruby", - "editor": "vscode", - "suggestions_count": 400, - "acceptances_count": 350, - "lines_suggested": 500, - "lines_accepted": 200, - "active_users": 3 + "name": "neovim", + "total_engaged_users": 7, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "languages": [ + { + "name": "typescript", + "total_engaged_users": 3, + "total_code_suggestions": 112, + "total_code_acceptances": 56, + "total_code_lines_suggested": 143, + "total_code_lines_accepted": 61 + }, + { + "name": "go", + "total_engaged_users": 4, + "total_code_suggestions": 132, + "total_code_acceptances": 67, + "total_code_lines_suggested": 154, + "total_code_lines_accepted": 72 + } + ] + } + ] } ] - }, - { - "day": "2023-10-16", - "total_suggestions_count": 800, - "total_acceptances_count": 600, - "total_lines_suggested": 1100, - "total_lines_accepted": 700, - "total_active_users": 12, - "total_chat_acceptances": 57, - "total_chat_turns": 426, - "total_active_chat_users": 8, - "breakdown": [ + }, + "copilot_ide_chat": { + "total_engaged_users": 13, + "editors": [ { - "language": "python", - "editor": "vscode", - "suggestions_count": 300, - "acceptances_count": 200, - "lines_suggested": 600, - "lines_accepted": 300, - "active_users": 2 - }, + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 12, + "total_chats": 45, + "total_chat_insertion_events": 12, + "total_chat_copy_events": 16 + }, + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_engaged_users": 1, + "total_chats": 10, + "total_chat_insertion_events": 11, + "total_chat_copy_events": 3 + } + ] + } + ] + }, + "copilot_dotcom_chat": { + "total_engaged_users": 14, + "models": [ { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 300, - "acceptances_count": 150, - "lines_suggested": 300, - "lines_accepted": 250, - "active_users": 6 + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 14, + "total_chats": 38 + } + ] + }, + "copilot_dotcom_pull_requests": { + "total_engaged_users": 12, + "repositories": [ + { + "name": "demo/repo1", + "total_engaged_users": 8, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_pr_summaries_created": 6, + "total_engaged_users": 8 + } + ] }, { - "language": "ruby", - "editor": "vscode", - "suggestions_count": 200, - "acceptances_count": 150, - "lines_suggested": 200, - "lines_accepted": 150, - "active_users": 3 + "name": "demo/repo2", + "total_engaged_users": 4, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_pr_summaries_created": 10, + "total_engaged_users": 4 + } + ] } ] + } } ]`) }) - summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) - summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) ctx := context.Background() - got, _, err := client.Copilot.GetEnterpriseTeamUsage(ctx, "e", "t", &CopilotUsageSummaryListOptions{}) + got, _, err := client.Copilot.GetOrganizationMetrics(ctx, "o", &CopilotMetricsListOptions{}) if err != nil { - t.Errorf("Copilot.GetEnterpriseTeamUsage returned error: %v", err) + t.Errorf("Copilot.GetOrganizationMetrics returned error: %v", err) } - want := []*CopilotUsageSummary{ + want := []*CopilotMetrics{ { - Day: summaryOne.Format("2006-01-02"), - TotalSuggestionsCount: 1000, - TotalAcceptancesCount: 800, - TotalLinesSuggested: 1800, - TotalLinesAccepted: 1200, - TotalActiveUsers: 10, - TotalChatAcceptances: 32, - TotalChatTurns: 200, - TotalActiveChatUsers: 4, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 300, - AcceptancesCount: 250, - LinesSuggested: 900, - LinesAccepted: 700, - ActiveUsers: 5, - }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 300, - AcceptancesCount: 200, - LinesSuggested: 400, - LinesAccepted: 300, - ActiveUsers: 2, + Date: "2024-06-24", + TotalActiveUsers: 24, + TotalEngagedUsers: 20, + CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + TotalEngagedUsers: 20, + Languages: []*CopilotIdeCodeCompletionsLanguage{ + { + Name: "python", + TotalEngagedUsers: 10, + }, + { + Name: "ruby", + TotalEngagedUsers: 10, + }, }, - { - Language: "ruby", - Editor: "vscode", - SuggestionsCount: 400, - AcceptancesCount: 350, - LinesSuggested: 500, - LinesAccepted: 200, - ActiveUsers: 3, + Editors: []*CopilotIdeCodeCompletionsEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 13, + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "python", + TotalEngagedUsers: 6, + TotalCodeSuggestions: 249, + TotalCodeAcceptances: 123, + TotalCodeLinesSuggested: 225, + TotalCodeLinesAccepted: 135, + }, + { + Name: "ruby", + TotalEngagedUsers: 7, + TotalCodeSuggestions: 496, + TotalCodeAcceptances: 253, + TotalCodeLinesSuggested: 520, + TotalCodeLinesAccepted: 270, + }, + }, + }, + }, + }, + { + Name: "neovim", + TotalEngagedUsers: 7, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "typescript", + TotalEngagedUsers: 3, + TotalCodeSuggestions: 112, + TotalCodeAcceptances: 56, + TotalCodeLinesSuggested: 143, + TotalCodeLinesAccepted: 61, + }, + { + Name: "go", + TotalEngagedUsers: 4, + TotalCodeSuggestions: 132, + TotalCodeAcceptances: 67, + TotalCodeLinesSuggested: 154, + TotalCodeLinesAccepted: 72, + }, + }, + }, + }, + }, }, }, - }, - { - Day: summaryTwoDate.Format("2006-01-02"), - TotalSuggestionsCount: 800, - TotalAcceptancesCount: 600, - TotalLinesSuggested: 1100, - TotalLinesAccepted: 700, - TotalActiveUsers: 12, - TotalChatAcceptances: 57, - TotalChatTurns: 426, - TotalActiveChatUsers: 8, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 300, - AcceptancesCount: 200, - LinesSuggested: 600, - LinesAccepted: 300, - ActiveUsers: 2, + CopilotIdeChat: &CopilotIdeChat{ + TotalEngagedUsers: 13, + Editors: []*CopilotIdeChatEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 12, + TotalChats: 45, + TotalChatInsertionEvents: 12, + TotalChatCopyEvents: 16, + }, + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalEngagedUsers: 1, + TotalChats: 10, + TotalChatInsertionEvents: 11, + TotalChatCopyEvents: 3, + }, + }, + }, }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 300, - AcceptancesCount: 150, - LinesSuggested: 300, - LinesAccepted: 250, - ActiveUsers: 6, + }, + CopilotDotcomChat: &CopilotDotcomChat{ + TotalEngagedUsers: 14, + Models: []*CopilotDotcomChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 14, + TotalChats: 38, + }, }, - { - Language: "ruby", - Editor: "vscode", - SuggestionsCount: 200, - AcceptancesCount: 150, - LinesSuggested: 200, - LinesAccepted: 150, - ActiveUsers: 3, + }, + CopilotDotcomPullRequests: &CopilotDotcomPullRequests{ + TotalEngagedUsers: 12, + Repositories: []*CopilotDotcomPullRequestsRepository{ + { + Name: "demo/repo1", + TotalEngagedUsers: 8, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalPrSummariesCreated: 6, + TotalEngagedUsers: 8, + }, + }, + }, + { + Name: "demo/repo2", + TotalEngagedUsers: 4, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalPrSummariesCreated: 10, + TotalEngagedUsers: 4, + }, + }, + }, }, }, }, } if !cmp.Equal(got, want) { - t.Errorf("Copilot.GetEnterpriseTeamUsage returned %+v, want %+v", got, want) + t.Errorf("Copilot.GetOrganizationMetrics returned %+v, want %+v", got, want) } - const methodName = "GetEnterpriseTeamUsage" + const methodName = "GetOrganizationMetrics" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Copilot.GetEnterpriseTeamUsage(ctx, "\n", "\n", &CopilotUsageSummaryListOptions{}) + _, _, err = client.Copilot.GetOrganizationMetrics(ctx, "\n", &CopilotMetricsListOptions{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Copilot.GetEnterpriseTeamUsage(ctx, "e", "t", &CopilotUsageSummaryListOptions{}) + got, resp, err := client.Copilot.GetOrganizationMetrics(ctx, "o", &CopilotMetricsListOptions{}) if got != nil { - t.Errorf("Copilot.GetEnterpriseTeamUsage returned %+v, want nil", got) + t.Errorf("Copilot.GetOrganizationMetrics returned %+v, want nil", got) } return resp, err }) } -func TestCopilotService_GetOrganizationTeamUsage(t *testing.T) { +func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/orgs/o/team/t/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/orgs/o/team/t/copilot/metrics", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `[ { - "day": "2023-10-15", - "total_suggestions_count": 1000, - "total_acceptances_count": 800, - "total_lines_suggested": 1800, - "total_lines_accepted": 1200, - "total_active_users": 10, - "total_chat_acceptances": 32, - "total_chat_turns": 200, - "total_active_chat_users": 4, - "breakdown": [ - { - "language": "python", - "editor": "vscode", - "suggestions_count": 300, - "acceptances_count": 250, - "lines_suggested": 900, - "lines_accepted": 700, - "active_users": 5 - }, - { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 300, - "acceptances_count": 200, - "lines_suggested": 400, - "lines_accepted": 300, - "active_users": 2 - }, - { - "language": "ruby", - "editor": "vscode", - "suggestions_count": 400, - "acceptances_count": 350, - "lines_suggested": 500, - "lines_accepted": 200, - "active_users": 3 - } - ] - }, - { - "day": "2023-10-16", - "total_suggestions_count": 800, - "total_acceptances_count": 600, - "total_lines_suggested": 1100, - "total_lines_accepted": 700, - "total_active_users": 12, - "total_chat_acceptances": 57, - "total_chat_turns": 426, - "total_active_chat_users": 8, - "breakdown": [ - { - "language": "python", - "editor": "vscode", - "suggestions_count": 300, - "acceptances_count": 200, - "lines_suggested": 600, - "lines_accepted": 300, - "active_users": 2 - }, - { - "language": "python", - "editor": "jetbrains", - "suggestions_count": 300, - "acceptances_count": 150, - "lines_suggested": 300, - "lines_accepted": 250, - "active_users": 6 - }, - { - "language": "ruby", - "editor": "vscode", - "suggestions_count": 200, - "acceptances_count": 150, - "lines_suggested": 200, - "lines_accepted": 150, - "active_users": 3 - } - ] + "date": "2024-06-24", + "total_active_users": 24, + "total_engaged_users": 20, + "copilot_ide_code_completions": { + "total_engaged_users": 20, + "languages": [ + { + "name": "python", + "total_engaged_users": 10 + }, + { + "name": "ruby", + "total_engaged_users": 10 + } + ], + "editors": [ + { + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 13, + "languages": [ + { + "name": "python", + "total_engaged_users": 6, + "total_code_suggestions": 249, + "total_code_acceptances": 123, + "total_code_lines_suggested": 225, + "total_code_lines_accepted": 135 + }, + { + "name": "ruby", + "total_engaged_users": 7, + "total_code_suggestions": 496, + "total_code_acceptances": 253, + "total_code_lines_suggested": 520, + "total_code_lines_accepted": 270 + } + ] + } + ] + }, + { + "name": "neovim", + "total_engaged_users": 7, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "languages": [ + { + "name": "typescript", + "total_engaged_users": 3, + "total_code_suggestions": 112, + "total_code_acceptances": 56, + "total_code_lines_suggested": 143, + "total_code_lines_accepted": 61 + }, + { + "name": "go", + "total_engaged_users": 4, + "total_code_suggestions": 132, + "total_code_acceptances": 67, + "total_code_lines_suggested": 154, + "total_code_lines_accepted": 72 + } + ] + } + ] + } + ] + }, + "copilot_ide_chat": { + "total_engaged_users": 13, + "editors": [ + { + "name": "vscode", + "total_engaged_users": 13, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 12, + "total_chats": 45, + "total_chat_insertion_events": 12, + "total_chat_copy_events": 16 + }, + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_engaged_users": 1, + "total_chats": 10, + "total_chat_insertion_events": 11, + "total_chat_copy_events": 3 + } + ] + } + ] + }, + "copilot_dotcom_chat": { + "total_engaged_users": 14, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_engaged_users": 14, + "total_chats": 38 + } + ] + }, + "copilot_dotcom_pull_requests": { + "total_engaged_users": 12, + "repositories": [ + { + "name": "demo/repo1", + "total_engaged_users": 8, + "models": [ + { + "name": "default", + "is_custom_model": false, + "custom_model_training_date": null, + "total_pr_summaries_created": 6, + "total_engaged_users": 8 + } + ] + }, + { + "name": "demo/repo2", + "total_engaged_users": 4, + "models": [ + { + "name": "a-custom-model", + "is_custom_model": true, + "custom_model_training_date": "2024-02-01", + "total_pr_summaries_created": 10, + "total_engaged_users": 4 + } + ] + } + ] + } } ]`) }) - summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) - summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) ctx := context.Background() - got, _, err := client.Copilot.GetOrganizationTeamUsage(ctx, "o", "t", &CopilotUsageSummaryListOptions{}) + got, _, err := client.Copilot.GetOrganizationTeamMetrics(ctx, "o", "t", &CopilotMetricsListOptions{}) if err != nil { - t.Errorf("Copilot.GetOrganizationTeamUsage returned error: %v", err) + t.Errorf("Copilot.GetOrganizationTeamMetrics returned error: %v", err) } - want := []*CopilotUsageSummary{ + want := []*CopilotMetrics{ { - Day: summaryOne.Format("2006-01-02"), - TotalSuggestionsCount: 1000, - TotalAcceptancesCount: 800, - TotalLinesSuggested: 1800, - TotalLinesAccepted: 1200, - TotalActiveUsers: 10, - TotalChatAcceptances: 32, - TotalChatTurns: 200, - TotalActiveChatUsers: 4, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 300, - AcceptancesCount: 250, - LinesSuggested: 900, - LinesAccepted: 700, - ActiveUsers: 5, - }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 300, - AcceptancesCount: 200, - LinesSuggested: 400, - LinesAccepted: 300, - ActiveUsers: 2, + Date: "2024-06-24", + TotalActiveUsers: 24, + TotalEngagedUsers: 20, + CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + TotalEngagedUsers: 20, + Languages: []*CopilotIdeCodeCompletionsLanguage{ + { + Name: "python", + TotalEngagedUsers: 10, + }, + { + Name: "ruby", + TotalEngagedUsers: 10, + }, }, - { - Language: "ruby", - Editor: "vscode", - SuggestionsCount: 400, - AcceptancesCount: 350, - LinesSuggested: 500, - LinesAccepted: 200, - ActiveUsers: 3, + Editors: []*CopilotIdeCodeCompletionsEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 13, + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "python", + TotalEngagedUsers: 6, + TotalCodeSuggestions: 249, + TotalCodeAcceptances: 123, + TotalCodeLinesSuggested: 225, + TotalCodeLinesAccepted: 135, + }, + { + Name: "ruby", + TotalEngagedUsers: 7, + TotalCodeSuggestions: 496, + TotalCodeAcceptances: 253, + TotalCodeLinesSuggested: 520, + TotalCodeLinesAccepted: 270, + }, + }, + }, + }, + }, + { + Name: "neovim", + TotalEngagedUsers: 7, + Models: []*CopilotIdeCodeCompletionsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + { + Name: "typescript", + TotalEngagedUsers: 3, + TotalCodeSuggestions: 112, + TotalCodeAcceptances: 56, + TotalCodeLinesSuggested: 143, + TotalCodeLinesAccepted: 61, + }, + { + Name: "go", + TotalEngagedUsers: 4, + TotalCodeSuggestions: 132, + TotalCodeAcceptances: 67, + TotalCodeLinesSuggested: 154, + TotalCodeLinesAccepted: 72, + }, + }, + }, + }, + }, }, }, - }, - { - Day: summaryTwoDate.Format("2006-01-02"), - TotalSuggestionsCount: 800, - TotalAcceptancesCount: 600, - TotalLinesSuggested: 1100, - TotalLinesAccepted: 700, - TotalActiveUsers: 12, - TotalChatAcceptances: 57, - TotalChatTurns: 426, - TotalActiveChatUsers: 8, - Breakdown: []*CopilotUsageBreakdown{ - { - Language: "python", - Editor: "vscode", - SuggestionsCount: 300, - AcceptancesCount: 200, - LinesSuggested: 600, - LinesAccepted: 300, - ActiveUsers: 2, + CopilotIdeChat: &CopilotIdeChat{ + TotalEngagedUsers: 13, + Editors: []*CopilotIdeChatEditor{ + { + Name: "vscode", + TotalEngagedUsers: 13, + Models: []*CopilotIdeChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 12, + TotalChats: 45, + TotalChatInsertionEvents: 12, + TotalChatCopyEvents: 16, + }, + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalEngagedUsers: 1, + TotalChats: 10, + TotalChatInsertionEvents: 11, + TotalChatCopyEvents: 3, + }, + }, + }, }, - { - Language: "python", - Editor: "jetbrains", - SuggestionsCount: 300, - AcceptancesCount: 150, - LinesSuggested: 300, - LinesAccepted: 250, - ActiveUsers: 6, + }, + CopilotDotcomChat: &CopilotDotcomChat{ + TotalEngagedUsers: 14, + Models: []*CopilotDotcomChatModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalEngagedUsers: 14, + TotalChats: 38, + }, }, - { - Language: "ruby", - Editor: "vscode", - SuggestionsCount: 200, - AcceptancesCount: 150, - LinesSuggested: 200, - LinesAccepted: 150, - ActiveUsers: 3, + }, + CopilotDotcomPullRequests: &CopilotDotcomPullRequests{ + TotalEngagedUsers: 12, + Repositories: []*CopilotDotcomPullRequestsRepository{ + { + Name: "demo/repo1", + TotalEngagedUsers: 8, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "default", + IsCustomModel: false, + CustomModelTrainingDate: nil, + TotalPrSummariesCreated: 6, + TotalEngagedUsers: 8, + }, + }, + }, + { + Name: "demo/repo2", + TotalEngagedUsers: 4, + Models: []*CopilotDotcomPullRequestsModel{ + { + Name: "a-custom-model", + IsCustomModel: true, + CustomModelTrainingDate: String("2024-02-01"), + TotalPrSummariesCreated: 10, + TotalEngagedUsers: 4, + }, + }, + }, }, }, }, } if !cmp.Equal(got, want) { - t.Errorf("Copilot.GetOrganizationTeamUsage returned %+v, want %+v", got, want) + t.Errorf("Copilot.GetOrganizationTeamMetrics returned %+v, want %+v", got, want) } - const methodName = "GetOrganizationTeamUsage" + const methodName = "GetOrganizationTeamMetrics" testBadOptions(t, methodName, func() (err error) { - _, _, err = client.Copilot.GetOrganizationTeamUsage(ctx, "\n", "\n", &CopilotUsageSummaryListOptions{}) + _, _, err = client.Copilot.GetOrganizationTeamMetrics(ctx, "\n", "\n", &CopilotMetricsListOptions{}) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Copilot.GetOrganizationTeamUsage(ctx, "o", "t", &CopilotUsageSummaryListOptions{}) + got, resp, err := client.Copilot.GetOrganizationTeamMetrics(ctx, "o", "t", &CopilotMetricsListOptions{}) if got != nil { - t.Errorf("Copilot.GetOrganizationTeamUsage returned %+v, want nil", got) + t.Errorf("Copilot.GetOrganizationTeamMetrics returned %+v, want nil", got) } return resp, err }) diff --git a/github/github-accessors.go b/github/github-accessors.go index 7d8292a9652..dbba7082b94 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4294,6 +4294,86 @@ func (c *ContributorStats) GetTotal() int { return *c.Total } +// GetCustomModelTrainingDate returns the CustomModelTrainingDate field if it's non-nil, zero value otherwise. +func (c *CopilotDotcomChatModel) GetCustomModelTrainingDate() string { + if c == nil || c.CustomModelTrainingDate == nil { + return "" + } + return *c.CustomModelTrainingDate +} + +// GetCustomModelTrainingDate returns the CustomModelTrainingDate field if it's non-nil, zero value otherwise. +func (c *CopilotDotcomPullRequestsModel) GetCustomModelTrainingDate() string { + if c == nil || c.CustomModelTrainingDate == nil { + return "" + } + return *c.CustomModelTrainingDate +} + +// GetCustomModelTrainingDate returns the CustomModelTrainingDate field if it's non-nil, zero value otherwise. +func (c *CopilotIdeChatModel) GetCustomModelTrainingDate() string { + if c == nil || c.CustomModelTrainingDate == nil { + return "" + } + return *c.CustomModelTrainingDate +} + +// GetCustomModelTrainingDate returns the CustomModelTrainingDate field if it's non-nil, zero value otherwise. +func (c *CopilotIdeCodeCompletionsModel) GetCustomModelTrainingDate() string { + if c == nil || c.CustomModelTrainingDate == nil { + return "" + } + return *c.CustomModelTrainingDate +} + +// GetCopilotDotcomChat returns the CopilotDotcomChat field. +func (c *CopilotMetrics) GetCopilotDotcomChat() *CopilotDotcomChat { + if c == nil { + return nil + } + return c.CopilotDotcomChat +} + +// GetCopilotDotcomPullRequests returns the CopilotDotcomPullRequests field. +func (c *CopilotMetrics) GetCopilotDotcomPullRequests() *CopilotDotcomPullRequests { + if c == nil { + return nil + } + return c.CopilotDotcomPullRequests +} + +// GetCopilotIdeChat returns the CopilotIdeChat field. +func (c *CopilotMetrics) GetCopilotIdeChat() *CopilotIdeChat { + if c == nil { + return nil + } + return c.CopilotIdeChat +} + +// GetCopilotIdeCodeCompletions returns the CopilotIdeCodeCompletions field. +func (c *CopilotMetrics) GetCopilotIdeCodeCompletions() *CopilotIdeCodeCompletions { + if c == nil { + return nil + } + return c.CopilotIdeCodeCompletions +} + +// GetSince returns the Since field if it's non-nil, zero value otherwise. +func (c *CopilotMetricsListOptions) GetSince() time.Time { + if c == nil || c.Since == nil { + return time.Time{} + } + return *c.Since +} + +// GetUntil returns the Until field if it's non-nil, zero value otherwise. +func (c *CopilotMetricsListOptions) GetUntil() time.Time { + if c == nil || c.Until == nil { + return time.Time{} + } + return *c.Until +} + // GetSeatBreakdown returns the SeatBreakdown field. func (c *CopilotOrganizationDetails) GetSeatBreakdown() *CopilotSeatBreakdown { if c == nil { @@ -4358,22 +4438,6 @@ func (c *CopilotSeatDetails) GetUpdatedAt() Timestamp { return *c.UpdatedAt } -// GetSince returns the Since field if it's non-nil, zero value otherwise. -func (c *CopilotUsageSummaryListOptions) GetSince() time.Time { - if c == nil || c.Since == nil { - return time.Time{} - } - return *c.Since -} - -// GetUntil returns the Until field if it's non-nil, zero value otherwise. -func (c *CopilotUsageSummaryListOptions) GetUntil() time.Time { - if c == nil || c.Until == nil { - return time.Time{} - } - return *c.Until -} - // GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. func (c *CreateCheckRunOptions) GetCompletedAt() Timestamp { if c == nil || c.CompletedAt == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 4d7b022e12c..1b0224422df 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -5564,6 +5564,104 @@ func TestContributorStats_GetTotal(tt *testing.T) { c.GetTotal() } +func TestCopilotDotcomChatModel_GetCustomModelTrainingDate(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CopilotDotcomChatModel{CustomModelTrainingDate: &zeroValue} + c.GetCustomModelTrainingDate() + c = &CopilotDotcomChatModel{} + c.GetCustomModelTrainingDate() + c = nil + c.GetCustomModelTrainingDate() +} + +func TestCopilotDotcomPullRequestsModel_GetCustomModelTrainingDate(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CopilotDotcomPullRequestsModel{CustomModelTrainingDate: &zeroValue} + c.GetCustomModelTrainingDate() + c = &CopilotDotcomPullRequestsModel{} + c.GetCustomModelTrainingDate() + c = nil + c.GetCustomModelTrainingDate() +} + +func TestCopilotIdeChatModel_GetCustomModelTrainingDate(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CopilotIdeChatModel{CustomModelTrainingDate: &zeroValue} + c.GetCustomModelTrainingDate() + c = &CopilotIdeChatModel{} + c.GetCustomModelTrainingDate() + c = nil + c.GetCustomModelTrainingDate() +} + +func TestCopilotIdeCodeCompletionsModel_GetCustomModelTrainingDate(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CopilotIdeCodeCompletionsModel{CustomModelTrainingDate: &zeroValue} + c.GetCustomModelTrainingDate() + c = &CopilotIdeCodeCompletionsModel{} + c.GetCustomModelTrainingDate() + c = nil + c.GetCustomModelTrainingDate() +} + +func TestCopilotMetrics_GetCopilotDotcomChat(tt *testing.T) { + tt.Parallel() + c := &CopilotMetrics{} + c.GetCopilotDotcomChat() + c = nil + c.GetCopilotDotcomChat() +} + +func TestCopilotMetrics_GetCopilotDotcomPullRequests(tt *testing.T) { + tt.Parallel() + c := &CopilotMetrics{} + c.GetCopilotDotcomPullRequests() + c = nil + c.GetCopilotDotcomPullRequests() +} + +func TestCopilotMetrics_GetCopilotIdeChat(tt *testing.T) { + tt.Parallel() + c := &CopilotMetrics{} + c.GetCopilotIdeChat() + c = nil + c.GetCopilotIdeChat() +} + +func TestCopilotMetrics_GetCopilotIdeCodeCompletions(tt *testing.T) { + tt.Parallel() + c := &CopilotMetrics{} + c.GetCopilotIdeCodeCompletions() + c = nil + c.GetCopilotIdeCodeCompletions() +} + +func TestCopilotMetricsListOptions_GetSince(tt *testing.T) { + tt.Parallel() + var zeroValue time.Time + c := &CopilotMetricsListOptions{Since: &zeroValue} + c.GetSince() + c = &CopilotMetricsListOptions{} + c.GetSince() + c = nil + c.GetSince() +} + +func TestCopilotMetricsListOptions_GetUntil(tt *testing.T) { + tt.Parallel() + var zeroValue time.Time + c := &CopilotMetricsListOptions{Until: &zeroValue} + c.GetUntil() + c = &CopilotMetricsListOptions{} + c.GetUntil() + c = nil + c.GetUntil() +} + func TestCopilotOrganizationDetails_GetSeatBreakdown(tt *testing.T) { tt.Parallel() c := &CopilotOrganizationDetails{} @@ -5646,28 +5744,6 @@ func TestCopilotSeatDetails_GetUpdatedAt(tt *testing.T) { c.GetUpdatedAt() } -func TestCopilotUsageSummaryListOptions_GetSince(tt *testing.T) { - tt.Parallel() - var zeroValue time.Time - c := &CopilotUsageSummaryListOptions{Since: &zeroValue} - c.GetSince() - c = &CopilotUsageSummaryListOptions{} - c.GetSince() - c = nil - c.GetSince() -} - -func TestCopilotUsageSummaryListOptions_GetUntil(tt *testing.T) { - tt.Parallel() - var zeroValue time.Time - c := &CopilotUsageSummaryListOptions{Until: &zeroValue} - c.GetUntil() - c = &CopilotUsageSummaryListOptions{} - c.GetUntil() - c = nil - c.GetUntil() -} - func TestCreateCheckRunOptions_GetCompletedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp From fafbaea0c9db384d622d833bb0de60b8b3e01f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Mon, 18 Nov 2024 14:52:30 +0100 Subject: [PATCH 4/9] Restore Copilot usage endpoints --- github/copilot.go | 137 ++++++ github/copilot_test.go | 804 ++++++++++++++++++++++++++++++++ github/github-accessors.go | 16 + github/github-accessors_test.go | 22 + 4 files changed, 979 insertions(+) diff --git a/github/copilot.go b/github/copilot.go index 828da2e15b8..3f0f051e2af 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -66,6 +66,39 @@ type SeatCancellations struct { SeatsCancelled int `json:"seats_cancelled"` } +// CopilotUsageSummaryListOptions represents the optional parameters to the CopilotService.GetOrganizationUsage method. +type CopilotUsageSummaryListOptions struct { + Since *time.Time `url:"since,omitempty"` + Until *time.Time `url:"until,omitempty"` + + ListOptions +} + +// CopilotUsageBreakdown represents the breakdown of Copilot usage for a specific language and editor. +type CopilotUsageBreakdown struct { + Language string `json:"language"` + Editor string `json:"editor"` + SuggestionsCount int64 `json:"suggestions_count"` + AcceptancesCount int64 `json:"acceptances_count"` + LinesSuggested int64 `json:"lines_suggested"` + LinesAccepted int64 `json:"lines_accepted"` + ActiveUsers int `json:"active_users"` +} + +// CopilotUsageSummary represents the daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE across an organization. +type CopilotUsageSummary struct { + Day string `json:"day"` + TotalSuggestionsCount int64 `json:"total_suggestions_count"` + TotalAcceptancesCount int64 `json:"total_acceptances_count"` + TotalLinesSuggested int64 `json:"total_lines_suggested"` + TotalLinesAccepted int64 `json:"total_lines_accepted"` + TotalActiveUsers int64 `json:"total_active_users"` + TotalChatAcceptances int64 `json:"total_chat_acceptances"` + TotalChatTurns int64 `json:"total_chat_turns"` + TotalActiveChatUsers int `json:"total_active_chat_users"` + Breakdown []*CopilotUsageBreakdown `json:"breakdown"` +} + // CopilotMetricsListOptions represents the optional parameters to the CopilotService get metrics methods. type CopilotMetricsListOptions struct { Since *time.Time `url:"since,omitempty"` @@ -456,6 +489,110 @@ func (s *CopilotService) GetSeatDetails(ctx context.Context, org, user string) ( return seatDetails, resp, nil } +// GetOrganizationUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE across an organization. +// +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-organization-members +// +//meta:operation GET /orgs/{org}/copilot/usage +func (s *CopilotService) GetOrganizationUsage(ctx context.Context, org string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { + u := fmt.Sprintf("orgs/%v/copilot/usage", org) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var usage []*CopilotUsageSummary + resp, err := s.client.Do(ctx, req, &usage) + if err != nil { + return nil, resp, err + } + + return usage, resp, nil +} + +// GetEnterpriseUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE across an enterprise. +// +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-enterprise-members +// +//meta:operation GET /enterprises/{enterprise}/copilot/usage +func (s *CopilotService) GetEnterpriseUsage(ctx context.Context, enterprise string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { + u := fmt.Sprintf("enterprises/%v/copilot/usage", enterprise) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var usage []*CopilotUsageSummary + resp, err := s.client.Do(ctx, req, &usage) + if err != nil { + return nil, resp, err + } + + return usage, resp, nil +} + +// GetEnterpriseTeamUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE for a team in the enterprise. +// +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-an-enterprise-team +// +//meta:operation GET /enterprises/{enterprise}/team/{team_slug}/copilot/usage +func (s *CopilotService) GetEnterpriseTeamUsage(ctx context.Context, enterprise, team string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { + u := fmt.Sprintf("enterprises/%v/team/%v/copilot/usage", enterprise, team) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var usage []*CopilotUsageSummary + resp, err := s.client.Do(ctx, req, &usage) + if err != nil { + return nil, resp, err + } + + return usage, resp, nil +} + +// GetOrganizationTeamUsage gets daily breakdown of aggregated usage metrics for Copilot completions and Copilot Chat in the IDE for a team in the organization. +// +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-usage#get-a-summary-of-copilot-usage-for-a-team +// +//meta:operation GET /orgs/{org}/team/{team_slug}/copilot/usage +func (s *CopilotService) GetOrganizationTeamUsage(ctx context.Context, org, team string, opts *CopilotUsageSummaryListOptions) ([]*CopilotUsageSummary, *Response, error) { + u := fmt.Sprintf("orgs/%v/team/%v/copilot/usage", org, team) + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var usage []*CopilotUsageSummary + resp, err := s.client.Do(ctx, req, &usage) + if err != nil { + return nil, resp, err + } + + return usage, resp, nil +} + // GetEnterpriseMetrics gets Copilot usage metrics for an enterprise. // // GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise diff --git a/github/copilot_test.go b/github/copilot_test.go index 7ebad92a4e6..6e525f87c9e 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -1127,6 +1127,810 @@ func TestCopilotService_GetSeatDetails(t *testing.T) { }) } +func TestCopilotService_GetOrganisationUsage(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[ + { + "day": "2023-10-15", + "total_suggestions_count": 1000, + "total_acceptances_count": 800, + "total_lines_suggested": 1800, + "total_lines_accepted": 1200, + "total_active_users": 10, + "total_chat_acceptances": 32, + "total_chat_turns": 200, + "total_active_chat_users": 4, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 300, + "acceptances_count": 250, + "lines_suggested": 900, + "lines_accepted": 700, + "active_users": 5 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 300, + "acceptances_count": 200, + "lines_suggested": 400, + "lines_accepted": 300, + "active_users": 2 + }, + { + "language": "ruby", + "editor": "vscode", + "suggestions_count": 400, + "acceptances_count": 350, + "lines_suggested": 500, + "lines_accepted": 200, + "active_users": 3 + } + ] + }, + { + "day": "2023-10-16", + "total_suggestions_count": 800, + "total_acceptances_count": 600, + "total_lines_suggested": 1100, + "total_lines_accepted": 700, + "total_active_users": 12, + "total_chat_acceptances": 57, + "total_chat_turns": 426, + "total_active_chat_users": 8, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 300, + "acceptances_count": 200, + "lines_suggested": 600, + "lines_accepted": 300, + "active_users": 2 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 300, + "acceptances_count": 150, + "lines_suggested": 300, + "lines_accepted": 250, + "active_users": 6 + }, + { + "language": "ruby", + "editor": "vscode", + "suggestions_count": 200, + "acceptances_count": 150, + "lines_suggested": 200, + "lines_accepted": 150, + "active_users": 3 + } + ] + } + ]`) + }) + + summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) + summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) + ctx := context.Background() + got, _, err := client.Copilot.GetOrganizationUsage(ctx, "o", &CopilotUsageSummaryListOptions{}) + if err != nil { + t.Errorf("Copilot.GetOrganizationUsage returned error: %v", err) + } + + want := []*CopilotUsageSummary{ + { + Day: summaryOne.Format("2006-01-02"), + TotalSuggestionsCount: 1000, + TotalAcceptancesCount: 800, + TotalLinesSuggested: 1800, + TotalLinesAccepted: 1200, + TotalActiveUsers: 10, + TotalChatAcceptances: 32, + TotalChatTurns: 200, + TotalActiveChatUsers: 4, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 300, + AcceptancesCount: 250, + LinesSuggested: 900, + LinesAccepted: 700, + ActiveUsers: 5, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 300, + AcceptancesCount: 200, + LinesSuggested: 400, + LinesAccepted: 300, + ActiveUsers: 2, + }, + { + Language: "ruby", + Editor: "vscode", + SuggestionsCount: 400, + AcceptancesCount: 350, + LinesSuggested: 500, + LinesAccepted: 200, + ActiveUsers: 3, + }, + }, + }, + { + Day: summaryTwoDate.Format("2006-01-02"), + TotalSuggestionsCount: 800, + TotalAcceptancesCount: 600, + TotalLinesSuggested: 1100, + TotalLinesAccepted: 700, + TotalActiveUsers: 12, + TotalChatAcceptances: 57, + TotalChatTurns: 426, + TotalActiveChatUsers: 8, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 300, + AcceptancesCount: 200, + LinesSuggested: 600, + LinesAccepted: 300, + ActiveUsers: 2, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 300, + AcceptancesCount: 150, + LinesSuggested: 300, + LinesAccepted: 250, + ActiveUsers: 6, + }, + { + Language: "ruby", + Editor: "vscode", + SuggestionsCount: 200, + AcceptancesCount: 150, + LinesSuggested: 200, + LinesAccepted: 150, + ActiveUsers: 3, + }, + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Copilot.GetOrganizationUsage returned %+v, want %+v", got, want) + } + + const methodName = "GetOrganizationUsage" + + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Copilot.GetOrganizationUsage(ctx, "\n", &CopilotUsageSummaryListOptions{}) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Copilot.GetOrganizationUsage(ctx, "o", &CopilotUsageSummaryListOptions{}) + if got != nil { + t.Errorf("Copilot.GetOrganizationUsage returned %+v, want nil", got) + } + return resp, err + }) +} + +func TestCopilotService_GetEnterpriseUsage(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[ + { + "day": "2023-10-15", + "total_suggestions_count": 5000, + "total_acceptances_count": 3000, + "total_lines_suggested": 7000, + "total_lines_accepted": 3500, + "total_active_users": 15, + "total_chat_acceptances": 45, + "total_chat_turns": 350, + "total_active_chat_users": 8, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 3000, + "acceptances_count": 2000, + "lines_suggested": 3000, + "lines_accepted": 1500, + "active_users": 5 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 1000, + "acceptances_count": 500, + "lines_suggested": 2000, + "lines_accepted": 1000, + "active_users": 5 + }, + { + "language": "javascript", + "editor": "vscode", + "suggestions_count": 1000, + "acceptances_count": 500, + "lines_suggested": 2000, + "lines_accepted": 1000, + "active_users": 5 + } + ] + }, + { + "day": "2023-10-16", + "total_suggestions_count": 5200, + "total_acceptances_count": 5100, + "total_lines_suggested": 5300, + "total_lines_accepted": 5000, + "total_active_users": 15, + "total_chat_acceptances": 57, + "total_chat_turns": 455, + "total_active_chat_users": 12, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 3100, + "acceptances_count": 3000, + "lines_suggested": 3200, + "lines_accepted": 3100, + "active_users": 5 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 1100, + "acceptances_count": 1000, + "lines_suggested": 1200, + "lines_accepted": 1100, + "active_users": 5 + }, + { + "language": "javascript", + "editor": "vscode", + "suggestions_count": 1000, + "acceptances_count": 900, + "lines_suggested": 1100, + "lines_accepted": 1000, + "active_users": 5 + } + ] + } + ]`) + }) + + summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) + summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) + ctx := context.Background() + got, _, err := client.Copilot.GetEnterpriseUsage(ctx, "e", &CopilotUsageSummaryListOptions{}) + if err != nil { + t.Errorf("Copilot.GetEnterpriseUsage returned error: %v", err) + } + + want := []*CopilotUsageSummary{ + { + Day: summaryOne.Format("2006-01-02"), + TotalSuggestionsCount: 5000, + TotalAcceptancesCount: 3000, + TotalLinesSuggested: 7000, + TotalLinesAccepted: 3500, + TotalActiveUsers: 15, + TotalChatAcceptances: 45, + TotalChatTurns: 350, + TotalActiveChatUsers: 8, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 3000, + AcceptancesCount: 2000, + LinesSuggested: 3000, + LinesAccepted: 1500, + ActiveUsers: 5, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 1000, + AcceptancesCount: 500, + LinesSuggested: 2000, + LinesAccepted: 1000, + ActiveUsers: 5, + }, + { + Language: "javascript", + Editor: "vscode", + SuggestionsCount: 1000, + AcceptancesCount: 500, + LinesSuggested: 2000, + LinesAccepted: 1000, + ActiveUsers: 5, + }, + }, + }, + { + Day: summaryTwoDate.Format("2006-01-02"), + TotalSuggestionsCount: 5200, + TotalAcceptancesCount: 5100, + TotalLinesSuggested: 5300, + TotalLinesAccepted: 5000, + TotalActiveUsers: 15, + TotalChatAcceptances: 57, + TotalChatTurns: 455, + TotalActiveChatUsers: 12, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 3100, + AcceptancesCount: 3000, + LinesSuggested: 3200, + LinesAccepted: 3100, + ActiveUsers: 5, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 1100, + AcceptancesCount: 1000, + LinesSuggested: 1200, + LinesAccepted: 1100, + ActiveUsers: 5, + }, + { + Language: "javascript", + Editor: "vscode", + SuggestionsCount: 1000, + AcceptancesCount: 900, + LinesSuggested: 1100, + LinesAccepted: 1000, + ActiveUsers: 5, + }, + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Copilot.GetEnterpriseUsage returned %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseUsage" + + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Copilot.GetEnterpriseUsage(ctx, "\n", &CopilotUsageSummaryListOptions{}) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Copilot.GetEnterpriseUsage(ctx, "e", &CopilotUsageSummaryListOptions{}) + if got != nil { + t.Errorf("Copilot.GetEnterpriseUsage returned %+v, want nil", got) + } + return resp, err + }) +} + +func TestCopilotService_GetEnterpriseTeamUsage(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/team/t/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[ + { + "day": "2023-10-15", + "total_suggestions_count": 1000, + "total_acceptances_count": 800, + "total_lines_suggested": 1800, + "total_lines_accepted": 1200, + "total_active_users": 10, + "total_chat_acceptances": 32, + "total_chat_turns": 200, + "total_active_chat_users": 4, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 300, + "acceptances_count": 250, + "lines_suggested": 900, + "lines_accepted": 700, + "active_users": 5 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 300, + "acceptances_count": 200, + "lines_suggested": 400, + "lines_accepted": 300, + "active_users": 2 + }, + { + "language": "ruby", + "editor": "vscode", + "suggestions_count": 400, + "acceptances_count": 350, + "lines_suggested": 500, + "lines_accepted": 200, + "active_users": 3 + } + ] + }, + { + "day": "2023-10-16", + "total_suggestions_count": 800, + "total_acceptances_count": 600, + "total_lines_suggested": 1100, + "total_lines_accepted": 700, + "total_active_users": 12, + "total_chat_acceptances": 57, + "total_chat_turns": 426, + "total_active_chat_users": 8, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 300, + "acceptances_count": 200, + "lines_suggested": 600, + "lines_accepted": 300, + "active_users": 2 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 300, + "acceptances_count": 150, + "lines_suggested": 300, + "lines_accepted": 250, + "active_users": 6 + }, + { + "language": "ruby", + "editor": "vscode", + "suggestions_count": 200, + "acceptances_count": 150, + "lines_suggested": 200, + "lines_accepted": 150, + "active_users": 3 + } + ] + } + ]`) + }) + + summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) + summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) + ctx := context.Background() + got, _, err := client.Copilot.GetEnterpriseTeamUsage(ctx, "e", "t", &CopilotUsageSummaryListOptions{}) + if err != nil { + t.Errorf("Copilot.GetEnterpriseTeamUsage returned error: %v", err) + } + + want := []*CopilotUsageSummary{ + { + Day: summaryOne.Format("2006-01-02"), + TotalSuggestionsCount: 1000, + TotalAcceptancesCount: 800, + TotalLinesSuggested: 1800, + TotalLinesAccepted: 1200, + TotalActiveUsers: 10, + TotalChatAcceptances: 32, + TotalChatTurns: 200, + TotalActiveChatUsers: 4, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 300, + AcceptancesCount: 250, + LinesSuggested: 900, + LinesAccepted: 700, + ActiveUsers: 5, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 300, + AcceptancesCount: 200, + LinesSuggested: 400, + LinesAccepted: 300, + ActiveUsers: 2, + }, + { + Language: "ruby", + Editor: "vscode", + SuggestionsCount: 400, + AcceptancesCount: 350, + LinesSuggested: 500, + LinesAccepted: 200, + ActiveUsers: 3, + }, + }, + }, + { + Day: summaryTwoDate.Format("2006-01-02"), + TotalSuggestionsCount: 800, + TotalAcceptancesCount: 600, + TotalLinesSuggested: 1100, + TotalLinesAccepted: 700, + TotalActiveUsers: 12, + TotalChatAcceptances: 57, + TotalChatTurns: 426, + TotalActiveChatUsers: 8, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 300, + AcceptancesCount: 200, + LinesSuggested: 600, + LinesAccepted: 300, + ActiveUsers: 2, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 300, + AcceptancesCount: 150, + LinesSuggested: 300, + LinesAccepted: 250, + ActiveUsers: 6, + }, + { + Language: "ruby", + Editor: "vscode", + SuggestionsCount: 200, + AcceptancesCount: 150, + LinesSuggested: 200, + LinesAccepted: 150, + ActiveUsers: 3, + }, + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Copilot.GetEnterpriseTeamUsage returned %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseTeamUsage" + + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Copilot.GetEnterpriseTeamUsage(ctx, "\n", "\n", &CopilotUsageSummaryListOptions{}) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Copilot.GetEnterpriseTeamUsage(ctx, "e", "t", &CopilotUsageSummaryListOptions{}) + if got != nil { + t.Errorf("Copilot.GetEnterpriseTeamUsage returned %+v, want nil", got) + } + return resp, err + }) +} + +func TestCopilotService_GetOrganizationTeamUsage(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/orgs/o/team/t/copilot/usage", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[ + { + "day": "2023-10-15", + "total_suggestions_count": 1000, + "total_acceptances_count": 800, + "total_lines_suggested": 1800, + "total_lines_accepted": 1200, + "total_active_users": 10, + "total_chat_acceptances": 32, + "total_chat_turns": 200, + "total_active_chat_users": 4, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 300, + "acceptances_count": 250, + "lines_suggested": 900, + "lines_accepted": 700, + "active_users": 5 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 300, + "acceptances_count": 200, + "lines_suggested": 400, + "lines_accepted": 300, + "active_users": 2 + }, + { + "language": "ruby", + "editor": "vscode", + "suggestions_count": 400, + "acceptances_count": 350, + "lines_suggested": 500, + "lines_accepted": 200, + "active_users": 3 + } + ] + }, + { + "day": "2023-10-16", + "total_suggestions_count": 800, + "total_acceptances_count": 600, + "total_lines_suggested": 1100, + "total_lines_accepted": 700, + "total_active_users": 12, + "total_chat_acceptances": 57, + "total_chat_turns": 426, + "total_active_chat_users": 8, + "breakdown": [ + { + "language": "python", + "editor": "vscode", + "suggestions_count": 300, + "acceptances_count": 200, + "lines_suggested": 600, + "lines_accepted": 300, + "active_users": 2 + }, + { + "language": "python", + "editor": "jetbrains", + "suggestions_count": 300, + "acceptances_count": 150, + "lines_suggested": 300, + "lines_accepted": 250, + "active_users": 6 + }, + { + "language": "ruby", + "editor": "vscode", + "suggestions_count": 200, + "acceptances_count": 150, + "lines_suggested": 200, + "lines_accepted": 150, + "active_users": 3 + } + ] + } + ]`) + }) + + summaryOne := time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC) + summaryTwoDate := time.Date(2023, time.October, 16, 0, 0, 0, 0, time.UTC) + ctx := context.Background() + got, _, err := client.Copilot.GetOrganizationTeamUsage(ctx, "o", "t", &CopilotUsageSummaryListOptions{}) + if err != nil { + t.Errorf("Copilot.GetOrganizationTeamUsage returned error: %v", err) + } + + want := []*CopilotUsageSummary{ + { + Day: summaryOne.Format("2006-01-02"), + TotalSuggestionsCount: 1000, + TotalAcceptancesCount: 800, + TotalLinesSuggested: 1800, + TotalLinesAccepted: 1200, + TotalActiveUsers: 10, + TotalChatAcceptances: 32, + TotalChatTurns: 200, + TotalActiveChatUsers: 4, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 300, + AcceptancesCount: 250, + LinesSuggested: 900, + LinesAccepted: 700, + ActiveUsers: 5, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 300, + AcceptancesCount: 200, + LinesSuggested: 400, + LinesAccepted: 300, + ActiveUsers: 2, + }, + { + Language: "ruby", + Editor: "vscode", + SuggestionsCount: 400, + AcceptancesCount: 350, + LinesSuggested: 500, + LinesAccepted: 200, + ActiveUsers: 3, + }, + }, + }, + { + Day: summaryTwoDate.Format("2006-01-02"), + TotalSuggestionsCount: 800, + TotalAcceptancesCount: 600, + TotalLinesSuggested: 1100, + TotalLinesAccepted: 700, + TotalActiveUsers: 12, + TotalChatAcceptances: 57, + TotalChatTurns: 426, + TotalActiveChatUsers: 8, + Breakdown: []*CopilotUsageBreakdown{ + { + Language: "python", + Editor: "vscode", + SuggestionsCount: 300, + AcceptancesCount: 200, + LinesSuggested: 600, + LinesAccepted: 300, + ActiveUsers: 2, + }, + { + Language: "python", + Editor: "jetbrains", + SuggestionsCount: 300, + AcceptancesCount: 150, + LinesSuggested: 300, + LinesAccepted: 250, + ActiveUsers: 6, + }, + { + Language: "ruby", + Editor: "vscode", + SuggestionsCount: 200, + AcceptancesCount: 150, + LinesSuggested: 200, + LinesAccepted: 150, + ActiveUsers: 3, + }, + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Copilot.GetOrganizationTeamUsage returned %+v, want %+v", got, want) + } + + const methodName = "GetOrganizationTeamUsage" + + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Copilot.GetOrganizationTeamUsage(ctx, "\n", "\n", &CopilotUsageSummaryListOptions{}) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Copilot.GetOrganizationTeamUsage(ctx, "o", "t", &CopilotUsageSummaryListOptions{}) + if got != nil { + t.Errorf("Copilot.GetOrganizationTeamUsage returned %+v, want nil", got) + } + return resp, err + }) +} + func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { t.Parallel() client, mux, _ := setup(t) diff --git a/github/github-accessors.go b/github/github-accessors.go index dbba7082b94..63f1f49890f 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4438,6 +4438,22 @@ func (c *CopilotSeatDetails) GetUpdatedAt() Timestamp { return *c.UpdatedAt } +// GetSince returns the Since field if it's non-nil, zero value otherwise. +func (c *CopilotUsageSummaryListOptions) GetSince() time.Time { + if c == nil || c.Since == nil { + return time.Time{} + } + return *c.Since +} + +// GetUntil returns the Until field if it's non-nil, zero value otherwise. +func (c *CopilotUsageSummaryListOptions) GetUntil() time.Time { + if c == nil || c.Until == nil { + return time.Time{} + } + return *c.Until +} + // GetCompletedAt returns the CompletedAt field if it's non-nil, zero value otherwise. func (c *CreateCheckRunOptions) GetCompletedAt() Timestamp { if c == nil || c.CompletedAt == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 1b0224422df..ac1fe221e5c 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -5744,6 +5744,28 @@ func TestCopilotSeatDetails_GetUpdatedAt(tt *testing.T) { c.GetUpdatedAt() } +func TestCopilotUsageSummaryListOptions_GetSince(tt *testing.T) { + tt.Parallel() + var zeroValue time.Time + c := &CopilotUsageSummaryListOptions{Since: &zeroValue} + c.GetSince() + c = &CopilotUsageSummaryListOptions{} + c.GetSince() + c = nil + c.GetSince() +} + +func TestCopilotUsageSummaryListOptions_GetUntil(tt *testing.T) { + tt.Parallel() + var zeroValue time.Time + c := &CopilotUsageSummaryListOptions{Until: &zeroValue} + c.GetUntil() + c = &CopilotUsageSummaryListOptions{} + c.GetUntil() + c = nil + c.GetUntil() +} + func TestCreateCheckRunOptions_GetCompletedAt(tt *testing.T) { tt.Parallel() var zeroValue Timestamp From 08b590e3c0bc5480f7085e8de558fc1705a27f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Mon, 18 Nov 2024 17:37:39 +0100 Subject: [PATCH 5/9] Make non-required fields nullable --- github/copilot.go | 12 ++++++------ github/copilot_test.go | 24 ++++++++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/github/copilot.go b/github/copilot.go index 3f0f051e2af..43ec147bac8 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -201,12 +201,12 @@ type CopilotDotcomPullRequests struct { // CopilotMetrics represents Copilot usage metrics for a given day. type CopilotMetrics struct { Date string `json:"date"` - TotalActiveUsers int `json:"total_active_users"` - TotalEngagedUsers int `json:"total_engaged_users"` - CopilotIdeCodeCompletions *CopilotIdeCodeCompletions `json:"copilot_ide_code_completions"` - CopilotIdeChat *CopilotIdeChat `json:"copilot_ide_chat"` - CopilotDotcomChat *CopilotDotcomChat `json:"copilot_dotcom_chat"` - CopilotDotcomPullRequests *CopilotDotcomPullRequests `json:"copilot_dotcom_pull_requests"` + TotalActiveUsers *int `json:"total_active_users,omitempty"` + TotalEngagedUsers *int `json:"total_engaged_users,omitempty"` + CopilotIdeCodeCompletions *CopilotIdeCodeCompletions `json:"copilot_ide_code_completions,omitempty"` + CopilotIdeChat *CopilotIdeChat `json:"copilot_ide_chat,omitempty"` + CopilotDotcomChat *CopilotDotcomChat `json:"copilot_dotcom_chat,omitempty"` + CopilotDotcomPullRequests *CopilotDotcomPullRequests `json:"copilot_dotcom_pull_requests,omitempty"` } func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { diff --git a/github/copilot_test.go b/github/copilot_test.go index 6e525f87c9e..b863d9a5fb0 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -2098,11 +2098,13 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { t.Errorf("Copilot.GetEnterpriseMetrics returned error: %v", err) } + totalActiveUsers := 24 + totalEngagedUsers := 20 want := []*CopilotMetrics{ { Date: "2024-06-24", - TotalActiveUsers: 24, - TotalEngagedUsers: 20, + TotalActiveUsers: &totalActiveUsers, + TotalEngagedUsers: &totalEngagedUsers, CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ TotalEngagedUsers: 20, Languages: []*CopilotIdeCodeCompletionsLanguage{ @@ -2439,11 +2441,13 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { t.Errorf("Copilot.GetEnterpriseTeamMetrics returned error: %v", err) } + totalActiveUsers := 24 + totalEngagedUsers := 20 want := []*CopilotMetrics{ { Date: "2024-06-24", - TotalActiveUsers: 24, - TotalEngagedUsers: 20, + TotalActiveUsers: &totalActiveUsers, + TotalEngagedUsers: &totalEngagedUsers, CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ TotalEngagedUsers: 20, Languages: []*CopilotIdeCodeCompletionsLanguage{ @@ -2780,11 +2784,13 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) { t.Errorf("Copilot.GetOrganizationMetrics returned error: %v", err) } + totalActiveUsers := 24 + totalEngagedUsers := 20 want := []*CopilotMetrics{ { Date: "2024-06-24", - TotalActiveUsers: 24, - TotalEngagedUsers: 20, + TotalActiveUsers: &totalActiveUsers, + TotalEngagedUsers: &totalEngagedUsers, CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ TotalEngagedUsers: 20, Languages: []*CopilotIdeCodeCompletionsLanguage{ @@ -3121,11 +3127,13 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { t.Errorf("Copilot.GetOrganizationTeamMetrics returned error: %v", err) } + totalActiveUsers := 24 + totalEngagedUsers := 20 want := []*CopilotMetrics{ { Date: "2024-06-24", - TotalActiveUsers: 24, - TotalEngagedUsers: 20, + TotalActiveUsers: &totalActiveUsers, + TotalEngagedUsers: &totalEngagedUsers, CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ TotalEngagedUsers: 20, Languages: []*CopilotIdeCodeCompletionsLanguage{ From e74fa5d35f2753be5e1a65aacd70488131575f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Mon, 18 Nov 2024 17:43:09 +0100 Subject: [PATCH 6/9] Add comments as descriptions to nested structs --- github/copilot.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/github/copilot.go b/github/copilot.go index 43ec147bac8..3e827614579 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -107,11 +107,13 @@ type CopilotMetricsListOptions struct { ListOptions } +// CopilotIdeCodeCompletionsLanguage represents Copilot usage metrics for completions in the IDE for a language. type CopilotIdeCodeCompletionsLanguage struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` } +// CopilotIdeCodeCompletionsModelLanguage represents Copilot usage metrics for completions in the IDE for a model and language. type CopilotIdeCodeCompletionsModelLanguage struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` @@ -121,6 +123,7 @@ type CopilotIdeCodeCompletionsModelLanguage struct { TotalCodeLinesAccepted int `json:"total_code_lines_accepted"` } +// CopilotIdeCodeCompletionsModel represents Copilot usage metrics for completions in the IDE for a model. type CopilotIdeCodeCompletionsModel struct { Name string `json:"name"` IsCustomModel bool `json:"is_custom_model"` @@ -129,6 +132,7 @@ type CopilotIdeCodeCompletionsModel struct { Languages []*CopilotIdeCodeCompletionsModelLanguage `json:"languages"` } +// CopilotIdeCodeCompletionsEditor represents Copilot usage metrics for completions in the IDE for an editor. type CopilotIdeCodeCompletionsEditor struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` @@ -142,6 +146,7 @@ type CopilotIdeCodeCompletions struct { Editors []*CopilotIdeCodeCompletionsEditor `json:"editors"` } +// CopilotIdeChatModel represents Copilot usage metrics for chatting with a model in the IDE. type CopilotIdeChatModel struct { Name string `json:"name"` IsCustomModel bool `json:"is_custom_model"` @@ -152,6 +157,7 @@ type CopilotIdeChatModel struct { TotalChatCopyEvents int `json:"total_chat_copy_events"` } +// CopilotIdeChatEditor represents Copilot usage metrics for chatting with a model in the IDE, categorized by editor and model. type CopilotIdeChatEditor struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` @@ -164,6 +170,7 @@ type CopilotIdeChat struct { Editors []*CopilotIdeChatEditor `json:"editors"` } +// CopilotDotcomChatModel represents Copilot usage metrics for chatting with a model in the webbrowser. type CopilotDotcomChatModel struct { Name string `json:"name"` IsCustomModel bool `json:"is_custom_model"` @@ -178,6 +185,7 @@ type CopilotDotcomChat struct { Models []*CopilotDotcomChatModel `json:"models"` } +// CopilotDotcomPullRequestsModel represents Copilot usage metrics for pull requests in the webbrowser, categorized by model. type CopilotDotcomPullRequestsModel struct { Name string `json:"name"` IsCustomModel bool `json:"is_custom_model"` @@ -186,6 +194,7 @@ type CopilotDotcomPullRequestsModel struct { TotalEngagedUsers int `json:"total_engaged_users"` } +// CopilotDotcomPullRequestsRepository represents Copilot usage metrics for pull requests in the webbrowser, categorized by repository. type CopilotDotcomPullRequestsRepository struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` From de163441612fb7e7d293a7627aa373ee3b972306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Tue, 19 Nov 2024 09:41:55 +0100 Subject: [PATCH 7/9] Apply suggestions for idiomatic naming from code review Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/copilot.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/github/copilot.go b/github/copilot.go index 3e827614579..f70bd6d5bf3 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -107,14 +107,14 @@ type CopilotMetricsListOptions struct { ListOptions } -// CopilotIdeCodeCompletionsLanguage represents Copilot usage metrics for completions in the IDE for a language. -type CopilotIdeCodeCompletionsLanguage struct { +// CopilotIDECodeCompletionsLanguage represents Copilot usage metrics for completions in the IDE for a language. +type CopilotIDECodeCompletionsLanguage struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` } -// CopilotIdeCodeCompletionsModelLanguage represents Copilot usage metrics for completions in the IDE for a model and language. -type CopilotIdeCodeCompletionsModelLanguage struct { +// CopilotIDECodeCompletionsModelLanguage represents Copilot usage metrics for completions in the IDE for a model and language. +type CopilotIDECodeCompletionsModelLanguage struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` TotalCodeSuggestions int `json:"total_code_suggestions"` @@ -123,8 +123,8 @@ type CopilotIdeCodeCompletionsModelLanguage struct { TotalCodeLinesAccepted int `json:"total_code_lines_accepted"` } -// CopilotIdeCodeCompletionsModel represents Copilot usage metrics for completions in the IDE for a model. -type CopilotIdeCodeCompletionsModel struct { +// CopilotIDECodeCompletionsModel represents Copilot usage metrics for completions in the IDE for a model. +type CopilotIDECodeCompletionsModel struct { Name string `json:"name"` IsCustomModel bool `json:"is_custom_model"` CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` @@ -132,22 +132,22 @@ type CopilotIdeCodeCompletionsModel struct { Languages []*CopilotIdeCodeCompletionsModelLanguage `json:"languages"` } -// CopilotIdeCodeCompletionsEditor represents Copilot usage metrics for completions in the IDE for an editor. -type CopilotIdeCodeCompletionsEditor struct { +// CopilotIDECodeCompletionsEditor represents Copilot usage metrics for completions in the IDE for an editor. +type CopilotIDECodeCompletionsEditor struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` Models []*CopilotIdeCodeCompletionsModel `json:"models"` } -// CopilotIdeCodeCompletions represents Copilot usage metrics for Copilot code completions in the IDE, categorized by editor, model and language. -type CopilotIdeCodeCompletions struct { +// CopilotIDECodeCompletions represents Copilot usage metrics for Copilot code completions in the IDE, categorized by editor, model and language. +type CopilotIDECodeCompletions struct { TotalEngagedUsers int `json:"total_engaged_users"` Languages []*CopilotIdeCodeCompletionsLanguage `json:"languages"` Editors []*CopilotIdeCodeCompletionsEditor `json:"editors"` } -// CopilotIdeChatModel represents Copilot usage metrics for chatting with a model in the IDE. -type CopilotIdeChatModel struct { +// CopilotIDEChatModel represents Copilot usage metrics for chatting with a model in the IDE. +type CopilotIDEChatModel struct { Name string `json:"name"` IsCustomModel bool `json:"is_custom_model"` CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` @@ -157,15 +157,15 @@ type CopilotIdeChatModel struct { TotalChatCopyEvents int `json:"total_chat_copy_events"` } -// CopilotIdeChatEditor represents Copilot usage metrics for chatting with a model in the IDE, categorized by editor and model. -type CopilotIdeChatEditor struct { +// CopilotIDEChatEditor represents Copilot usage metrics for chatting with a model in the IDE, categorized by editor and model. +type CopilotIDEChatEditor struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` Models []*CopilotIdeChatModel `json:"models"` } -// CopilotIdeChat represents Copilot usage metrics for Copilot Chat in the IDE, categorized by editor and model. -type CopilotIdeChat struct { +// CopilotIDEChat represents Copilot usage metrics for Copilot Chat in the IDE, categorized by editor and model. +type CopilotIDEChat struct { TotalEngagedUsers int `json:"total_engaged_users"` Editors []*CopilotIdeChatEditor `json:"editors"` } @@ -190,7 +190,7 @@ type CopilotDotcomPullRequestsModel struct { Name string `json:"name"` IsCustomModel bool `json:"is_custom_model"` CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` - TotalPrSummariesCreated int `json:"total_pr_summaries_created"` + TotalPRSummariesCreated int `json:"total_pr_summaries_created"` TotalEngagedUsers int `json:"total_engaged_users"` } @@ -212,8 +212,8 @@ type CopilotMetrics struct { Date string `json:"date"` TotalActiveUsers *int `json:"total_active_users,omitempty"` TotalEngagedUsers *int `json:"total_engaged_users,omitempty"` - CopilotIdeCodeCompletions *CopilotIdeCodeCompletions `json:"copilot_ide_code_completions,omitempty"` - CopilotIdeChat *CopilotIdeChat `json:"copilot_ide_chat,omitempty"` + CopilotIDECodeCompletions *CopilotIDECodeCompletions `json:"copilot_ide_code_completions,omitempty"` + CopilotIDEChat *CopilotIDEChat `json:"copilot_ide_chat,omitempty"` CopilotDotcomChat *CopilotDotcomChat `json:"copilot_dotcom_chat,omitempty"` CopilotDotcomPullRequests *CopilotDotcomPullRequests `json:"copilot_dotcom_pull_requests,omitempty"` } From 58b6ac2f6c1d7301628364cf0e713c31bcf6268d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Tue, 19 Nov 2024 09:44:33 +0100 Subject: [PATCH 8/9] Finish the renaming --- github/copilot.go | 12 +++--- github/copilot_test.go | 96 +++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/github/copilot.go b/github/copilot.go index f70bd6d5bf3..cf9527ac4cd 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -129,21 +129,21 @@ type CopilotIDECodeCompletionsModel struct { IsCustomModel bool `json:"is_custom_model"` CustomModelTrainingDate *string `json:"custom_model_training_date,omitempty"` TotalEngagedUsers int `json:"total_engaged_users"` - Languages []*CopilotIdeCodeCompletionsModelLanguage `json:"languages"` + Languages []*CopilotIDECodeCompletionsModelLanguage `json:"languages"` } // CopilotIDECodeCompletionsEditor represents Copilot usage metrics for completions in the IDE for an editor. type CopilotIDECodeCompletionsEditor struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` - Models []*CopilotIdeCodeCompletionsModel `json:"models"` + Models []*CopilotIDECodeCompletionsModel `json:"models"` } // CopilotIDECodeCompletions represents Copilot usage metrics for Copilot code completions in the IDE, categorized by editor, model and language. type CopilotIDECodeCompletions struct { TotalEngagedUsers int `json:"total_engaged_users"` - Languages []*CopilotIdeCodeCompletionsLanguage `json:"languages"` - Editors []*CopilotIdeCodeCompletionsEditor `json:"editors"` + Languages []*CopilotIDECodeCompletionsLanguage `json:"languages"` + Editors []*CopilotIDECodeCompletionsEditor `json:"editors"` } // CopilotIDEChatModel represents Copilot usage metrics for chatting with a model in the IDE. @@ -161,13 +161,13 @@ type CopilotIDEChatModel struct { type CopilotIDEChatEditor struct { Name string `json:"name"` TotalEngagedUsers int `json:"total_engaged_users"` - Models []*CopilotIdeChatModel `json:"models"` + Models []*CopilotIDEChatModel `json:"models"` } // CopilotIDEChat represents Copilot usage metrics for Copilot Chat in the IDE, categorized by editor and model. type CopilotIDEChat struct { TotalEngagedUsers int `json:"total_engaged_users"` - Editors []*CopilotIdeChatEditor `json:"editors"` + Editors []*CopilotIDEChatEditor `json:"editors"` } // CopilotDotcomChatModel represents Copilot usage metrics for chatting with a model in the webbrowser. diff --git a/github/copilot_test.go b/github/copilot_test.go index b863d9a5fb0..a299bf0735a 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -2105,9 +2105,9 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { Date: "2024-06-24", TotalActiveUsers: &totalActiveUsers, TotalEngagedUsers: &totalEngagedUsers, - CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + CopilotIDECodeCompletions: &CopilotIDECodeCompletions{ TotalEngagedUsers: 20, - Languages: []*CopilotIdeCodeCompletionsLanguage{ + Languages: []*CopilotIDECodeCompletionsLanguage{ { Name: "python", TotalEngagedUsers: 10, @@ -2117,17 +2117,17 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { TotalEngagedUsers: 10, }, }, - Editors: []*CopilotIdeCodeCompletionsEditor{ + Editors: []*CopilotIDECodeCompletionsEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, TotalEngagedUsers: 13, - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "python", TotalEngagedUsers: 6, @@ -2151,12 +2151,12 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { { Name: "neovim", TotalEngagedUsers: 7, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "typescript", TotalEngagedUsers: 3, @@ -2179,13 +2179,13 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { }, }, }, - CopilotIdeChat: &CopilotIdeChat{ + CopilotIDEChat: &CopilotIDEChat{ TotalEngagedUsers: 13, - Editors: []*CopilotIdeChatEditor{ + Editors: []*CopilotIDEChatEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeChatModel{ + Models: []*CopilotIDEChatModel{ { Name: "default", IsCustomModel: false, @@ -2231,7 +2231,7 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, - TotalPrSummariesCreated: 6, + TotalPRSummariesCreated: 6, TotalEngagedUsers: 8, }, }, @@ -2244,7 +2244,7 @@ func TestCopilotService_GetEnterpriseMetrics(t *testing.T) { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - TotalPrSummariesCreated: 10, + TotalPRSummariesCreated: 10, TotalEngagedUsers: 4, }, }, @@ -2448,9 +2448,9 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { Date: "2024-06-24", TotalActiveUsers: &totalActiveUsers, TotalEngagedUsers: &totalEngagedUsers, - CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + CopilotIDECodeCompletions: &CopilotIDECodeCompletions{ TotalEngagedUsers: 20, - Languages: []*CopilotIdeCodeCompletionsLanguage{ + Languages: []*CopilotIDECodeCompletionsLanguage{ { Name: "python", TotalEngagedUsers: 10, @@ -2460,17 +2460,17 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { TotalEngagedUsers: 10, }, }, - Editors: []*CopilotIdeCodeCompletionsEditor{ + Editors: []*CopilotIDECodeCompletionsEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, TotalEngagedUsers: 13, - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "python", TotalEngagedUsers: 6, @@ -2494,12 +2494,12 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { { Name: "neovim", TotalEngagedUsers: 7, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "typescript", TotalEngagedUsers: 3, @@ -2522,13 +2522,13 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { }, }, }, - CopilotIdeChat: &CopilotIdeChat{ + CopilotIDEChat: &CopilotIDEChat{ TotalEngagedUsers: 13, - Editors: []*CopilotIdeChatEditor{ + Editors: []*CopilotIDEChatEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeChatModel{ + Models: []*CopilotIDEChatModel{ { Name: "default", IsCustomModel: false, @@ -2574,7 +2574,7 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, - TotalPrSummariesCreated: 6, + TotalPRSummariesCreated: 6, TotalEngagedUsers: 8, }, }, @@ -2587,7 +2587,7 @@ func TestCopilotService_GetEnterpriseTeamMetrics(t *testing.T) { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - TotalPrSummariesCreated: 10, + TotalPRSummariesCreated: 10, TotalEngagedUsers: 4, }, }, @@ -2791,9 +2791,9 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) { Date: "2024-06-24", TotalActiveUsers: &totalActiveUsers, TotalEngagedUsers: &totalEngagedUsers, - CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + CopilotIDECodeCompletions: &CopilotIDECodeCompletions{ TotalEngagedUsers: 20, - Languages: []*CopilotIdeCodeCompletionsLanguage{ + Languages: []*CopilotIDECodeCompletionsLanguage{ { Name: "python", TotalEngagedUsers: 10, @@ -2803,17 +2803,17 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) { TotalEngagedUsers: 10, }, }, - Editors: []*CopilotIdeCodeCompletionsEditor{ + Editors: []*CopilotIDECodeCompletionsEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, TotalEngagedUsers: 13, - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "python", TotalEngagedUsers: 6, @@ -2837,12 +2837,12 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) { { Name: "neovim", TotalEngagedUsers: 7, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "typescript", TotalEngagedUsers: 3, @@ -2865,13 +2865,13 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) { }, }, }, - CopilotIdeChat: &CopilotIdeChat{ + CopilotIDEChat: &CopilotIDEChat{ TotalEngagedUsers: 13, - Editors: []*CopilotIdeChatEditor{ + Editors: []*CopilotIDEChatEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeChatModel{ + Models: []*CopilotIDEChatModel{ { Name: "default", IsCustomModel: false, @@ -2917,7 +2917,7 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, - TotalPrSummariesCreated: 6, + TotalPRSummariesCreated: 6, TotalEngagedUsers: 8, }, }, @@ -2930,7 +2930,7 @@ func TestCopilotService_GetOrganizationMetrics(t *testing.T) { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - TotalPrSummariesCreated: 10, + TotalPRSummariesCreated: 10, TotalEngagedUsers: 4, }, }, @@ -3134,9 +3134,9 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { Date: "2024-06-24", TotalActiveUsers: &totalActiveUsers, TotalEngagedUsers: &totalEngagedUsers, - CopilotIdeCodeCompletions: &CopilotIdeCodeCompletions{ + CopilotIDECodeCompletions: &CopilotIDECodeCompletions{ TotalEngagedUsers: 20, - Languages: []*CopilotIdeCodeCompletionsLanguage{ + Languages: []*CopilotIDECodeCompletionsLanguage{ { Name: "python", TotalEngagedUsers: 10, @@ -3146,17 +3146,17 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { TotalEngagedUsers: 10, }, }, - Editors: []*CopilotIdeCodeCompletionsEditor{ + Editors: []*CopilotIDECodeCompletionsEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, TotalEngagedUsers: 13, - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "python", TotalEngagedUsers: 6, @@ -3180,12 +3180,12 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { { Name: "neovim", TotalEngagedUsers: 7, - Models: []*CopilotIdeCodeCompletionsModel{ + Models: []*CopilotIDECodeCompletionsModel{ { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - Languages: []*CopilotIdeCodeCompletionsModelLanguage{ + Languages: []*CopilotIDECodeCompletionsModelLanguage{ { Name: "typescript", TotalEngagedUsers: 3, @@ -3208,13 +3208,13 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { }, }, }, - CopilotIdeChat: &CopilotIdeChat{ + CopilotIDEChat: &CopilotIDEChat{ TotalEngagedUsers: 13, - Editors: []*CopilotIdeChatEditor{ + Editors: []*CopilotIDEChatEditor{ { Name: "vscode", TotalEngagedUsers: 13, - Models: []*CopilotIdeChatModel{ + Models: []*CopilotIDEChatModel{ { Name: "default", IsCustomModel: false, @@ -3260,7 +3260,7 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { Name: "default", IsCustomModel: false, CustomModelTrainingDate: nil, - TotalPrSummariesCreated: 6, + TotalPRSummariesCreated: 6, TotalEngagedUsers: 8, }, }, @@ -3273,7 +3273,7 @@ func TestCopilotService_GetOrganizationTeamMetrics(t *testing.T) { Name: "a-custom-model", IsCustomModel: true, CustomModelTrainingDate: String("2024-02-01"), - TotalPrSummariesCreated: 10, + TotalPRSummariesCreated: 10, TotalEngagedUsers: 4, }, }, From 2b08dbb675ba1806e81f3cde2a86805f7c579536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Tue, 19 Nov 2024 15:55:08 +0100 Subject: [PATCH 9/9] Generate --- github/copilot.go | 8 +++--- github/github-accessors.go | 32 +++++++++++++++++------ github/github-accessors_test.go | 46 ++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/github/copilot.go b/github/copilot.go index cf9527ac4cd..19cfd977ceb 100644 --- a/github/copilot.go +++ b/github/copilot.go @@ -604,7 +604,7 @@ func (s *CopilotService) GetOrganizationTeamUsage(ctx context.Context, org, team // GetEnterpriseMetrics gets Copilot usage metrics for an enterprise. // -// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics#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) { @@ -630,7 +630,7 @@ func (s *CopilotService) GetEnterpriseMetrics(ctx context.Context, enterprise st // GetEnterpriseTeamMetrics gets Copilot usage metrics for an enterprise team. // -// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-enterprise-team +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics#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) { @@ -656,7 +656,7 @@ func (s *CopilotService) GetEnterpriseTeamMetrics(ctx context.Context, enterpris // GetOrganizationMetrics gets Copilot usage metrics for an organization. // -// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-an-organization +// GitHub API docs: https://docs.github.com/rest/copilot/copilot-metrics#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) { @@ -682,7 +682,7 @@ func (s *CopilotService) GetOrganizationMetrics(ctx context.Context, org string, // GetOrganizationTeamMetrics gets Copilot usage metrics for an organization team. // -// GitHub API docs: https://docs.github.com/en/rest/copilot/copilot-metrics#get-copilot-metrics-for-a-team +// 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 func (s *CopilotService) GetOrganizationTeamMetrics(ctx context.Context, org, team string, opts *CopilotMetricsListOptions) ([]*CopilotMetrics, *Response, error) { diff --git a/github/github-accessors.go b/github/github-accessors.go index 63f1f49890f..6cbf568d614 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4311,7 +4311,7 @@ func (c *CopilotDotcomPullRequestsModel) GetCustomModelTrainingDate() string { } // GetCustomModelTrainingDate returns the CustomModelTrainingDate field if it's non-nil, zero value otherwise. -func (c *CopilotIdeChatModel) GetCustomModelTrainingDate() string { +func (c *CopilotIDEChatModel) GetCustomModelTrainingDate() string { if c == nil || c.CustomModelTrainingDate == nil { return "" } @@ -4319,7 +4319,7 @@ func (c *CopilotIdeChatModel) GetCustomModelTrainingDate() string { } // GetCustomModelTrainingDate returns the CustomModelTrainingDate field if it's non-nil, zero value otherwise. -func (c *CopilotIdeCodeCompletionsModel) GetCustomModelTrainingDate() string { +func (c *CopilotIDECodeCompletionsModel) GetCustomModelTrainingDate() string { if c == nil || c.CustomModelTrainingDate == nil { return "" } @@ -4342,20 +4342,36 @@ func (c *CopilotMetrics) GetCopilotDotcomPullRequests() *CopilotDotcomPullReques return c.CopilotDotcomPullRequests } -// GetCopilotIdeChat returns the CopilotIdeChat field. -func (c *CopilotMetrics) GetCopilotIdeChat() *CopilotIdeChat { +// GetCopilotIDEChat returns the CopilotIDEChat field. +func (c *CopilotMetrics) GetCopilotIDEChat() *CopilotIDEChat { if c == nil { return nil } - return c.CopilotIdeChat + return c.CopilotIDEChat } -// GetCopilotIdeCodeCompletions returns the CopilotIdeCodeCompletions field. -func (c *CopilotMetrics) GetCopilotIdeCodeCompletions() *CopilotIdeCodeCompletions { +// GetCopilotIDECodeCompletions returns the CopilotIDECodeCompletions field. +func (c *CopilotMetrics) GetCopilotIDECodeCompletions() *CopilotIDECodeCompletions { if c == nil { return nil } - return c.CopilotIdeCodeCompletions + return c.CopilotIDECodeCompletions +} + +// GetTotalActiveUsers returns the TotalActiveUsers field if it's non-nil, zero value otherwise. +func (c *CopilotMetrics) GetTotalActiveUsers() int { + if c == nil || c.TotalActiveUsers == nil { + return 0 + } + return *c.TotalActiveUsers +} + +// GetTotalEngagedUsers returns the TotalEngagedUsers field if it's non-nil, zero value otherwise. +func (c *CopilotMetrics) GetTotalEngagedUsers() int { + if c == nil || c.TotalEngagedUsers == nil { + return 0 + } + return *c.TotalEngagedUsers } // GetSince returns the Since field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index ac1fe221e5c..3969da11c95 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -5586,23 +5586,23 @@ func TestCopilotDotcomPullRequestsModel_GetCustomModelTrainingDate(tt *testing.T c.GetCustomModelTrainingDate() } -func TestCopilotIdeChatModel_GetCustomModelTrainingDate(tt *testing.T) { +func TestCopilotIDEChatModel_GetCustomModelTrainingDate(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CopilotIdeChatModel{CustomModelTrainingDate: &zeroValue} + c := &CopilotIDEChatModel{CustomModelTrainingDate: &zeroValue} c.GetCustomModelTrainingDate() - c = &CopilotIdeChatModel{} + c = &CopilotIDEChatModel{} c.GetCustomModelTrainingDate() c = nil c.GetCustomModelTrainingDate() } -func TestCopilotIdeCodeCompletionsModel_GetCustomModelTrainingDate(tt *testing.T) { +func TestCopilotIDECodeCompletionsModel_GetCustomModelTrainingDate(tt *testing.T) { tt.Parallel() var zeroValue string - c := &CopilotIdeCodeCompletionsModel{CustomModelTrainingDate: &zeroValue} + c := &CopilotIDECodeCompletionsModel{CustomModelTrainingDate: &zeroValue} c.GetCustomModelTrainingDate() - c = &CopilotIdeCodeCompletionsModel{} + c = &CopilotIDECodeCompletionsModel{} c.GetCustomModelTrainingDate() c = nil c.GetCustomModelTrainingDate() @@ -5624,20 +5624,42 @@ func TestCopilotMetrics_GetCopilotDotcomPullRequests(tt *testing.T) { c.GetCopilotDotcomPullRequests() } -func TestCopilotMetrics_GetCopilotIdeChat(tt *testing.T) { +func TestCopilotMetrics_GetCopilotIDEChat(tt *testing.T) { tt.Parallel() c := &CopilotMetrics{} - c.GetCopilotIdeChat() + c.GetCopilotIDEChat() c = nil - c.GetCopilotIdeChat() + c.GetCopilotIDEChat() } -func TestCopilotMetrics_GetCopilotIdeCodeCompletions(tt *testing.T) { +func TestCopilotMetrics_GetCopilotIDECodeCompletions(tt *testing.T) { tt.Parallel() c := &CopilotMetrics{} - c.GetCopilotIdeCodeCompletions() + c.GetCopilotIDECodeCompletions() c = nil - c.GetCopilotIdeCodeCompletions() + c.GetCopilotIDECodeCompletions() +} + +func TestCopilotMetrics_GetTotalActiveUsers(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &CopilotMetrics{TotalActiveUsers: &zeroValue} + c.GetTotalActiveUsers() + c = &CopilotMetrics{} + c.GetTotalActiveUsers() + c = nil + c.GetTotalActiveUsers() +} + +func TestCopilotMetrics_GetTotalEngagedUsers(tt *testing.T) { + tt.Parallel() + var zeroValue int + c := &CopilotMetrics{TotalEngagedUsers: &zeroValue} + c.GetTotalEngagedUsers() + c = &CopilotMetrics{} + c.GetTotalEngagedUsers() + c = nil + c.GetTotalEngagedUsers() } func TestCopilotMetricsListOptions_GetSince(tt *testing.T) {