fix: check other possible readme paths/branches (#450)

* fix: check other possible readme paths/branches

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: url

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: Readme.md

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-07-03 13:09:20 -03:00 committed by GitHub
commit 8e51396575
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 42 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"errors"
"fmt"
"net/http"
"net/url"
"strings"
@ -29,19 +30,21 @@ func findGitHubREADME(s string) (*source, error) {
}
u.Host = "raw.githubusercontent.com"
for _, r := range readmeNames {
v := u
v.Path += "/master/" + r
for _, b := range readmeBranches {
for _, r := range readmeNames {
v := *u
v.Path += fmt.Sprintf("/%s/%s", b, r)
// nolint:bodyclose
// it is closed on the caller
resp, err := http.Get(v.String())
if err != nil {
return nil, err
}
// nolint:bodyclose
// it is closed on the caller
resp, err := http.Get(v.String())
if err != nil {
return nil, err
}
if resp.StatusCode == http.StatusOK {
return &source{resp.Body, v.String()}, nil
if resp.StatusCode == http.StatusOK {
return &source{resp.Body, v.String()}, nil
}
}
}