• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

charmbracelet / glow / 18684564545

21 Oct 2025 12:56PM UTC coverage: 3.387%. First build
18684564545

Pull #786

github

caarlos0
test: update

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Pull Request #786: feat: use fang

1 of 49 new or added lines in 5 files covered. (2.04%)

71 of 2096 relevant lines covered (3.39%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/github.go
1
package main
2

3
import (
4
        "context"
5
        "encoding/json"
6
        "errors"
7
        "fmt"
8
        "io"
9
        "net/http"
10
        "net/url"
11
        "strings"
12
)
13

14
// findGitHubREADME tries to find the correct README filename in a repository using GitHub API.
NEW
15
func findGitHubREADME(ctx context.Context, u *url.URL) (*source, error) {
×
16
        owner, repo, ok := strings.Cut(strings.TrimPrefix(u.Path, "/"), "/")
×
17
        if !ok {
×
18
                return nil, fmt.Errorf("invalid url: %s", u.String())
×
19
        }
×
20

21
        type readme struct {
×
22
                DownloadURL string `json:"download_url"`
×
23
        }
×
24

×
25
        apiURL := fmt.Sprintf("https://api.%s/repos/%s/%s/readme", u.Hostname(), owner, repo)
×
26

×
NEW
27
        req, err := http.NewRequestWithContext(ctx, http.MethodGet, apiURL, nil)
×
NEW
28
        if err != nil {
×
NEW
29
                return nil, fmt.Errorf("unable to create request: %w", err)
×
NEW
30
        }
×
NEW
31
        res, err := http.DefaultClient.Do(req)
×
32
        if err != nil {
×
33
                return nil, fmt.Errorf("unable to get url: %w", err)
×
34
        }
×
NEW
35
        defer res.Body.Close() //nolint:errcheck
×
36

×
37
        body, err := io.ReadAll(res.Body)
×
38
        if err != nil {
×
39
                return nil, fmt.Errorf("unable to read http response body: %w", err)
×
40
        }
×
41

42
        var result readme
×
43
        if err := json.Unmarshal(body, &result); err != nil {
×
44
                return nil, fmt.Errorf("unable to parse json: %w", err)
×
45
        }
×
46

47
        if res.StatusCode == http.StatusOK {
×
NEW
48
                // consumer of the source is responsible for closing the ReadCloser.
×
NEW
49
                req, err := http.NewRequestWithContext(ctx, http.MethodGet, result.DownloadURL, nil)
×
NEW
50
                if err != nil {
×
NEW
51
                        return nil, fmt.Errorf("unable to create request: %w", err)
×
NEW
52
                }
×
NEW
53
                resp, err := http.DefaultClient.Do(req) //nolint:bodyclose
×
54
                if err != nil {
×
55
                        return nil, fmt.Errorf("unable to get url: %w", err)
×
56
                }
×
57

58
                if resp.StatusCode == http.StatusOK {
×
59
                        return &source{resp.Body, result.DownloadURL}, nil
×
60
                }
×
61
        }
62

63
        return nil, errors.New("can't find README in GitHub repository")
×
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc