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

Function GetWorkflowContent

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

Source from the content-addressed store, hash-verified

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

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