Skip to content

Commit 6176c3e

Browse files
Merge pull request #13362 from cli/wm-copilot-sampling-100
Bump `gh copilot` telemetry sampling to 100%
2 parents 3c162a7 + 1caa3b7 commit 6176c3e

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎pkg/cmd/copilot/copilot.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/MakeNowJust/heredoc"
2121
"github.com/cli/cli/v2/internal/ci"
2222
"github.com/cli/cli/v2/internal/config"
23+
"github.com/cli/cli/v2/internal/gh/ghtelemetry"
2324
"github.com/cli/cli/v2/internal/prompter"
2425
"github.com/cli/cli/v2/internal/safepaths"
2526
ghzip "github.com/cli/cli/v2/internal/zip"
@@ -37,7 +38,7 @@ type CopilotOptions struct {
3738
Remove bool
3839
}
3940

40-
func NewCmdCopilot(f *cmdutil.Factory, runF func(*CopilotOptions) error) *cobra.Command {
41+
func NewCmdCopilot(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, runF func(*CopilotOptions) error) *cobra.Command {
4142
opts := &CopilotOptions{
4243
IO: f.IOStreams,
4344
HttpClient: f.HttpClient,
@@ -80,6 +81,8 @@ func NewCmdCopilot(f *cmdutil.Factory, runF func(*CopilotOptions) error) *cobra.
8081
`),
8182
DisableFlagParsing: true,
8283
RunE: func(cmd *cobra.Command, args []string) error {
84+
telemetry.SetSampleRate(ghtelemetry.SAMPLE_ALL)
85+
8386
stopParsePos := -1
8487
for i, arg := range args {
8588
if arg == "--" {

‎pkg/cmd/copilot/copilot_test.go‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"runtime"
1515
"testing"
1616

17+
"github.com/cli/cli/v2/internal/gh/ghtelemetry"
18+
"github.com/cli/cli/v2/internal/telemetry"
1719
"github.com/cli/cli/v2/pkg/cmdutil"
1820
"github.com/cli/cli/v2/pkg/httpmock"
1921
"github.com/cli/cli/v2/pkg/iostreams"
@@ -110,7 +112,7 @@ func TestNewCmdCopilot(t *testing.T) {
110112
assert.NoError(t, err)
111113

112114
var gotOpts *CopilotOptions
113-
cmd := NewCmdCopilot(f, func(opts *CopilotOptions) error {
115+
cmd := NewCmdCopilot(f, &telemetry.CommandRecorderSpy{}, func(opts *CopilotOptions) error {
114116
gotOpts = opts
115117
return nil
116118
})
@@ -586,3 +588,19 @@ func TestDownloadCopilot(t *testing.T) {
586588
require.Equal(t, localPath, path, "downloadCopilot() path mismatch")
587589
})
588590
}
591+
592+
func TestCopilotCommandIsSampledAt100(t *testing.T) {
593+
spy := &telemetry.CommandRecorderSpy{}
594+
factory := &cmdutil.Factory{}
595+
cmd := NewCmdCopilot(factory, spy, func(opts *CopilotOptions) error {
596+
return nil
597+
})
598+
cmd.SetArgs([]string{})
599+
cmd.SetIn(&bytes.Buffer{})
600+
cmd.SetOut(&bytes.Buffer{})
601+
cmd.SetErr(&bytes.Buffer{})
602+
603+
_, err := cmd.ExecuteC()
604+
require.NoError(t, err)
605+
require.Equal(t, ghtelemetry.SAMPLE_ALL, spy.LastSampleRate)
606+
}

‎pkg/cmd/root/root.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func NewCmdRoot(f *cmdutil.Factory, telemetry ghtelemetry.CommandRecorder, versi
152152
cmd.AddCommand(skillsCmd.NewCmdSkills(f, telemetry))
153153

154154
// Root commands with standalone functionality and no subcommands
155-
cmd.AddCommand(copilotCmd.NewCmdCopilot(f, nil))
155+
cmd.AddCommand(copilotCmd.NewCmdCopilot(f, telemetry, nil))
156156
cmd.AddCommand(statusCmd.NewCmdStatus(f, nil))
157157
cmd.AddCommand(creditsCmd.NewCmdCredits(f, nil))
158158
cmd.AddCommand(licensesCmd.NewCmdLicenses(f))

0 commit comments

Comments
 (0)