| 236 | } |
| 237 | |
| 238 | func 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 | } |