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