ensure files in docs/ take precedence
This commit is contained in:
parent
f36f8b799d
commit
8bf7c62d79
1 changed files with 36 additions and 1 deletions
37
main.go
37
main.go
|
|
@ -85,8 +85,42 @@ func main() {
|
|||
|
||||
if len(path) == 0 {
|
||||
path = "docs/index.html"
|
||||
goto skip_override
|
||||
}
|
||||
|
||||
{
|
||||
body, status, err := ApiGet(FormatEndpoint("/repos/%s/%s/contents/docs", user, repo))
|
||||
if err != nil {
|
||||
log.Printf("failed to fetch docs directory in %s:%s", user, repo)
|
||||
goto skip_override
|
||||
}
|
||||
|
||||
if status != http.StatusOK {
|
||||
goto skip_override
|
||||
}
|
||||
|
||||
var ents []struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &ents); err != nil {
|
||||
log.Printf("failed to fetch contents of docs directory in %s:%s - %s", user, repo, err)
|
||||
}
|
||||
|
||||
for _, ent := range ents {
|
||||
if ent.Type != "file" {
|
||||
continue
|
||||
}
|
||||
|
||||
if ent.Name == path {
|
||||
path = ent.Path
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
skip_override:
|
||||
log.Printf("fetching file content %s:%s - %q", user, repo, path)
|
||||
|
||||
content, err := FetchFile(user, repo, path)
|
||||
|
|
@ -119,7 +153,7 @@ func FetchFile(user, repo, path string) ([]byte, error) {
|
|||
}
|
||||
|
||||
if status != http.StatusOK {
|
||||
return nil, fmt.Errorf("response had unexpected status %d - %s", status, string(body))
|
||||
return nil, fmt.Errorf("unexpected response %d - %s", status, string(body))
|
||||
}
|
||||
|
||||
var response struct {
|
||||
|
|
@ -155,6 +189,7 @@ func ApiGet(endpoint string) ([]byte, int, error) {
|
|||
|
||||
var client http.Client
|
||||
log.Printf("GET %q", endpoint)
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return nil, -1, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue