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

Function GetWorkflowContent

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

Source from the content-addressed store, hash-verified

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

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