Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.5k
Add Copilot Usage Summary for Organization#3318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,6 +9,7 @@ import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "time" | ||
| ) | ||
| // CopilotService provides access to the Copilot-related functions | ||
| @@ -63,6 +64,36 @@ type SeatCancellations struct { | ||
| SeatsCancelled int `json:"seats_cancelled"` | ||
| } | ||
| type CopilotUsageSummaryListOptions struct { | ||
| Since time.Time `url:"since,omitempty"` | ||
| Until time.Time `url:"until,omitempty"` | ||
claystation marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ListOptions | ||
| } | ||
| type CopilotUsageBreakdown struct { | ||
| Language string `json:"language"` | ||
| Editor string `json:"editor"` | ||
| SuggestionsCount int `json:"suggestions_count"` | ||
| AcceptancesCount int `json:"acceptances_count"` | ||
| LinesSuggested int `json:"lines_suggested"` | ||
| LinesAccepted int `json:"lines_accepted"` | ||
| ActiveUsers int `json:"active_users"` | ||
| } | ||
| type CopilotUsageSummary struct { | ||
| Day string `json:"day"` | ||
| TotalSuggestionsCount int `json:"total_suggestions_count"` | ||
| TotalAcceptancesCount int `json:"total_acceptances_count"` | ||
| TotalLinesSuggested int `json:"total_lines_suggested"` | ||
| TotalLinesAccepted int `json:"total_lines_accepted"` | ||
| TotalActiveUsers int `json:"total_active_users"` | ||
| TotalChatAcceptances int `json:"total_chat_acceptances"` | ||
| TotalChatTurns int `json:"total_chat_turns"` | ||
| TotalActiveChatUsers int `json:"total_active_chat_users"` | ||
| Breakdown []*CopilotUsageBreakdown `json:"breakdown"` | ||
| } | ||
| func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error { | ||
| // Using an alias to avoid infinite recursion when calling json.Unmarshal | ||
| type alias CopilotSeatDetails | ||
| @@ -313,3 +344,29 @@ 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 | ||
claystation marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // | ||
| // GitHub API docs: https://docs.github.com/en/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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -896,3 +896,203 @@ func TestCopilotService_GetSeatDetails(t *testing.T) { | ||
| return resp, err | ||
| }) | ||
| } | ||
| func TestCopilotService_GetOrganisationUsage(t *testing.T) { | ||
| client, mux, _ := setup(t) | ||
claystation marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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 | ||
| }) | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.