MCPcopy Index your code
hub / github.com/cli/cli / CapiClientFunc

Function CapiClientFunc

pkg/cmd/agent-task/shared/capi.go:21–45  ·  view source on GitHub ↗
(f *cmdutil.Factory)

Source from the content-addressed store, hash-verified

19var agentSessionURLRegexp = regexp.MustCompile(fmt.Sprintf("^/agent-sessions/(%s)$", uuidPattern))
20
21func CapiClientFunc(f *cmdutil.Factory) func() (capi.CapiClient, error) {
22 return func() (capi.CapiClient, error) {
23 cfg, err := f.Config()
24 if err != nil {
25 return nil, err
26 }
27
28 httpClient, err := f.HttpClient()
29 if err != nil {
30 return nil, err
31 }
32
33 authCfg := cfg.Authentication()
34 host, _ := authCfg.DefaultHost()
35 token, _ := authCfg.ActiveToken(host)
36
37 cachedClient := api.NewCachedHTTPClient(httpClient, time.Minute*10)
38 capiBaseURL, err := resolveCapiURL(cachedClient, host)
39 if err != nil {
40 return nil, fmt.Errorf("failed to resolve Copilot API URL: %w", err)
41 }
42
43 return capi.NewCAPIClient(httpClient, token, host, capiBaseURL), nil
44 }
45}
46
47// resolveCapiURL queries the GitHub API for the Copilot API endpoint URL.
48func resolveCapiURL(httpClient *http.Client, host string) (string, error) {

Callers 2

NewCmdCreateFunction · 0.92

Calls 8

NewCachedHTTPClientFunction · 0.92
NewCAPIClientFunction · 0.92
resolveCapiURLFunction · 0.85
ConfigMethod · 0.65
AuthenticationMethod · 0.65
DefaultHostMethod · 0.65
ActiveTokenMethod · 0.65
ErrorfMethod · 0.65

Tested by 1