MCPcopy
hub / github.com/cli/cli / PromptGists

Function PromptGists

pkg/cmd/gist/shared/shared.go:224–249  ·  view source on GitHub ↗
(prompter prompter.Prompter, client *http.Client, host string, cs *iostreams.ColorScheme)

Source from the content-addressed store, hash-verified

222}
223
224func PromptGists(prompter prompter.Prompter, client *http.Client, host string, cs *iostreams.ColorScheme) (gist *Gist, err error) {
225 gists, err := ListGists(client, host, 10, nil, false, "all")
226 if err != nil {
227 return &Gist{}, err
228 }
229
230 if len(gists) == 0 {
231 return &Gist{}, nil
232 }
233
234 var opts = make([]string, len(gists))
235
236 for i, gist := range gists {
237 gistTime := text.FuzzyAgo(time.Now(), gist.UpdatedAt)
238 // TODO: support dynamic maxWidth
239 opts[i] = fmt.Sprintf("%s %s %s", cs.Bold(gist.Filename()), gist.TruncDescription(), cs.Muted(gistTime))
240 }
241
242 result, err := prompter.Select("Select a gist", "", opts)
243
244 if err != nil {
245 return &Gist{}, err
246 }
247
248 return &gists[result], nil
249}
250
251func GetRawGistFile(httpClient *http.Client, rawURL string) (string, error) {
252 req, err := http.NewRequest("GET", rawURL, nil)

Callers 4

deleteRunFunction · 0.92
viewRunFunction · 0.92
editRunFunction · 0.92
TestPromptGistsFunction · 0.85

Calls 7

FuzzyAgoFunction · 0.92
ListGistsFunction · 0.85
BoldMethod · 0.80
FilenameMethod · 0.80
TruncDescriptionMethod · 0.80
MutedMethod · 0.80
SelectMethod · 0.65

Tested by 1

TestPromptGistsFunction · 0.68