MCPcopy
hub / github.com/cli/cli / previewRun

Function previewRun

pkg/cmd/skills/preview/preview.go:128–256  ·  view source on GitHub ↗
(opts *PreviewOptions)

Source from the content-addressed store, hash-verified

126}
127
128func previewRun(opts *PreviewOptions) error {
129 cs := opts.IO.ColorScheme()
130
131 repo := opts.repo
132 owner := repo.RepoOwner()
133 repoName := repo.RepoName()
134 hostname := repo.RepoHost()
135 if err := source.ValidateSupportedHost(hostname); err != nil {
136 return err
137 }
138
139 httpClient, err := opts.HttpClient()
140 if err != nil {
141 return err
142 }
143 apiClient := api.NewClientFromHTTP(httpClient)
144
145 // Kick off the visibility fetch in parallel with the preview work so
146 // the extra API roundtrip doesn't add latency on the critical path.
147 // The result is consumed when the telemetry event is emitted below.
148 type visResult struct {
149 vis discovery.RepoVisibility
150 err error
151 }
152 visCh := make(chan visResult, 1)
153 go func() {
154 vis, err := discovery.FetchRepoVisibility(apiClient, hostname, owner, repoName)
155 visCh <- visResult{vis: vis, err: err}
156 }()
157
158 opts.IO.StartProgressIndicatorWithLabel(fmt.Sprintf("Resolving %s/%s", owner, repoName))
159 resolved, err := discovery.ResolveRef(apiClient, hostname, owner, repoName, opts.Version)
160 opts.IO.StopProgressIndicator()
161 if err != nil {
162 return fmt.Errorf("could not resolve version: %w", err)
163 }
164
165 var skill discovery.Skill
166 if discovery.IsSkillPath(opts.SkillName) {
167 opts.IO.StartProgressIndicatorWithLabel("Looking up skill")
168 found, err := discovery.DiscoverSkillByPathWithOptions(apiClient, hostname, owner, repoName, resolved.SHA, opts.SkillName, discovery.DiscoverSkillByPathOptions{SkipDescription: true})
169 opts.IO.StopProgressIndicator()
170 if err != nil {
171 return err
172 }
173 skill = *found
174 } else {
175 opts.IO.StartProgressIndicatorWithLabel("Discovering skills")
176 allSkills, err := discovery.DiscoverSkillsWithOptions(apiClient, hostname, owner, repoName, resolved.SHA, discovery.DiscoverOptions{})
177 opts.IO.StopProgressIndicator()
178 if err != nil {
179 return err
180 }
181
182 skills, err := filterHiddenDirSkills(opts, allSkills)
183 if err != nil {
184 return err
185 }

Calls 15

DisplayNameMethod · 0.95
ValidateSupportedHostFunction · 0.92
NewClientFromHTTPFunction · 0.92
FetchRepoVisibilityFunction · 0.92
ResolveRefFunction · 0.92
IsSkillPathFunction · 0.92
ListSkillFilesFunction · 0.92
FetchBlobFunction · 0.92
CategorizeHostFunction · 0.92
selectSkillFunction · 0.85