| 349 | } |
| 350 | |
| 351 | func extractAttestationDetail(tenant, builderSignerURI string) (string, string, error) { |
| 352 | // If given a build signer URI like |
| 353 | // https://github.com/foo/bar/.github/workflows/release.yml@refs/heads/main |
| 354 | // We want to extract: |
| 355 | // * foo/bar |
| 356 | // * .github/workflows/release.yml@refs/heads/main |
| 357 | var orgAndRepoRegexp *regexp.Regexp |
| 358 | var workflowRegexp *regexp.Regexp |
| 359 | |
| 360 | if tenant == "" { |
| 361 | orgAndRepoRegexp = regexp.MustCompile(`https://github\.com/([^/]+/[^/]+)/`) |
| 362 | workflowRegexp = regexp.MustCompile(`https://github\.com/[^/]+/[^/]+/(.+)`) |
| 363 | } else { |
| 364 | var tr = regexp.QuoteMeta(tenant) |
| 365 | orgAndRepoRegexp = regexp.MustCompile(fmt.Sprintf( |
| 366 | `https://%s\.ghe\.com/([^/]+/[^/]+)/`, |
| 367 | tr)) |
| 368 | workflowRegexp = regexp.MustCompile(fmt.Sprintf( |
| 369 | `https://%s\.ghe\.com/[^/]+/[^/]+/(.+)`, |
| 370 | tr)) |
| 371 | } |
| 372 | |
| 373 | match := orgAndRepoRegexp.FindStringSubmatch(builderSignerURI) |
| 374 | if len(match) < 2 { |
| 375 | return "", "", fmt.Errorf("no match found for org and repo: %s", builderSignerURI) |
| 376 | } |
| 377 | orgAndRepo := match[1] |
| 378 | |
| 379 | match = workflowRegexp.FindStringSubmatch(builderSignerURI) |
| 380 | if len(match) < 2 { |
| 381 | return "", "", fmt.Errorf("no match found for workflow: %s", builderSignerURI) |
| 382 | } |
| 383 | workflow := match[1] |
| 384 | |
| 385 | return orgAndRepo, workflow, nil |
| 386 | } |