| 390 | } |
| 391 | |
| 392 | func getLicenseText(owner, repo string) string { |
| 393 | url := fmt.Sprintf("https://api.github.com/repos/%s/%s/license", owner, repo) |
| 394 | req, _ := http.NewRequest("GET", url, nil) |
| 395 | req.Header.Set("Accept", "application/vnd.github.v3+json") |
| 396 | |
| 397 | if token := os.Getenv("GITHUB_TOKEN"); token != "" { |
| 398 | req.Header.Set("Authorization", "Bearer "+token) |
| 399 | } |
| 400 | |
| 401 | resp, err := http.DefaultClient.Do(req) |
| 402 | if err != nil { |
| 403 | log.Fatal(err) |
| 404 | } |
| 405 | defer resp.Body.Close() |
| 406 | if resp.StatusCode == 404 { |
| 407 | return "" |
| 408 | } |
| 409 | var result struct { |
| 410 | Content string `json:"content"` |
| 411 | Encoding string `json:"encoding"` |
| 412 | } |
| 413 | body, _ := io.ReadAll(resp.Body) |
| 414 | err = json.Unmarshal(body, &result) |
| 415 | if err != nil { |
| 416 | log.Fatal(err) |
| 417 | } |
| 418 | |
| 419 | if result.Encoding != "base64" { |
| 420 | log.Fatal(fmt.Sprintf("unexpected encoding: %q", result.Encoding)) |
| 421 | } |
| 422 | |
| 423 | decoded, err := base64.StdEncoding.DecodeString(result.Content) |
| 424 | if err != nil { |
| 425 | log.Fatal(err) |
| 426 | } |
| 427 | |
| 428 | return string(decoded) |
| 429 | } |
| 430 | |
| 431 | func extractCopyrights(license string, notice CopyrightNotice) []string { |
| 432 | lines := strings.Split(license, "\n") |