MCPcopy Create free account
hub / github.com/cli/cli / GetWorkflowContent

Function GetWorkflowContent

pkg/cmd/workflow/shared/shared.go:239–269  ·  view source on GitHub ↗
(client *api.Client, repo ghrepo.Interface, workflow Workflow, ref string)

Source from the content-addressed store, hash-verified

237}
238
239func GetWorkflowContent(client *api.Client, repo ghrepo.Interface, workflow Workflow, ref string) ([]byte, error) {
240 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "contents", workflow.Path)
241 if err != nil {
242 return nil, err
243 }
244 if ref != "" {
245 path.SetQuery("ref", ref)
246 }
247
248 type Result struct {
249 Content string
250 }
251
252 var result Result
253 err = client.REST(repo.RepoHost(), "GET", path.String(), nil, &result)
254 if err != nil {
255 return nil, err
256 }
257
258 decoded, err := base64.StdEncoding.DecodeString(result.Content)
259 if err != nil {
260 return nil, fmt.Errorf("failed to decode workflow file: %w", err)
261 }
262
263 sanitized, err := io.ReadAll(transform.NewReader(bytes.NewReader(decoded), &asciisanitizer.Sanitizer{}))
264 if err != nil {
265 return nil, err
266 }
267
268 return sanitized, nil
269}

Callers 2

viewWorkflowContentFunction · 0.92
runRunFunction · 0.92

Calls 8

JoinPathFunction · 0.92
SetQueryMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected