| 233 | } |
| 234 | |
| 235 | func GetWorkflowContent(client *api.Client, repo ghrepo.Interface, workflow Workflow, ref string) ([]byte, error) { |
| 236 | path := fmt.Sprintf("repos/%s/contents/%s", ghrepo.FullName(repo), workflow.Path) |
| 237 | if ref != "" { |
| 238 | q := fmt.Sprintf("?ref=%s", url.QueryEscape(ref)) |
| 239 | path = path + q |
| 240 | } |
| 241 | |
| 242 | type Result struct { |
| 243 | Content string |
| 244 | } |
| 245 | |
| 246 | var result Result |
| 247 | err := client.REST(repo.RepoHost(), "GET", path, nil, &result) |
| 248 | if err != nil { |
| 249 | return nil, err |
| 250 | } |
| 251 | |
| 252 | decoded, err := base64.StdEncoding.DecodeString(result.Content) |
| 253 | if err != nil { |
| 254 | return nil, fmt.Errorf("failed to decode workflow file: %w", err) |
| 255 | } |
| 256 | |
| 257 | sanitized, err := io.ReadAll(transform.NewReader(bytes.NewReader(decoded), &asciisanitizer.Sanitizer{})) |
| 258 | if err != nil { |
| 259 | return nil, err |
| 260 | } |
| 261 | |
| 262 | return sanitized, nil |
| 263 | } |