MCPcopy
hub / github.com/cli/cli / newCmdSendTelemetry

Function newCmdSendTelemetry

pkg/cmd/send-telemetry/send_telemetry.go:33–74  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*SendTelemetryOptions) error)

Source from the content-addressed store, hash-verified

31}
32
33func newCmdSendTelemetry(f *cmdutil.Factory, runF func(*SendTelemetryOptions) error) *cobra.Command {
34 cmd := &cobra.Command{
35 Use: "send-telemetry",
36 Short: "Send telemetry event to GitHub",
37 Hidden: true,
38 Args: cobra.NoArgs,
39 RunE: func(cmd *cobra.Command, args []string) error {
40 cfg, err := f.Config()
41 if err != nil {
42 return err
43 }
44
45 payloadJSON, err := io.ReadAll(cmd.InOrStdin())
46 if err != nil {
47 return fmt.Errorf("reading payload from stdin: %w", err)
48 }
49 if len(payloadJSON) == 0 {
50 return fmt.Errorf("no payload provided on stdin")
51 }
52
53 opts := &SendTelemetryOptions{
54 TelemetryEndpointURL: cmp.Or(os.Getenv("GH_TELEMETRY_ENDPOINT_URL"), defaultTelemetryEndpointURL),
55 PayloadJSON: string(payloadJSON),
56 // This is a best effort to use a Unix Socket if configured. In most cases, if there is one configured
57 // it will be at the global level. However, since the telemetry service is not related to a specific host, we can't
58 // know that the socket we choose will work.
59 HTTPUnixSocket: cfg.HTTPUnixSocket("").Value,
60 }
61
62 if runF != nil {
63 return runF(opts)
64 }
65
66 return runSendTelemetry(cmd.Context(), opts)
67 },
68 }
69
70 cmdutil.DisableAuthCheck(cmd)
71 cmdutil.DisableTelemetry(cmd)
72
73 return cmd
74}
75
76func runSendTelemetry(ctx context.Context, opts *SendTelemetryOptions) error {
77 httpClient := &http.Client{

Callers 2

NewCmdSendTelemetryFunction · 0.85
TestNewCmdSendTelemetryFunction · 0.85

Calls 6

DisableAuthCheckFunction · 0.92
DisableTelemetryFunction · 0.92
runSendTelemetryFunction · 0.85
ConfigMethod · 0.65
ErrorfMethod · 0.65
HTTPUnixSocketMethod · 0.65

Tested by 1

TestNewCmdSendTelemetryFunction · 0.68