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

charmbracelet / glow / 15971595192

30 Jun 2025 11:24AM UTC coverage: 3.417% (-0.3%) from 3.674%
15971595192

Pull #786

github

caarlos0
fix: use ctx

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

1 of 10 new or added lines in 2 files covered. (10.0%)

80 existing lines in 4 files now uncovered.

71 of 2078 relevant lines covered (3.42%)

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
        "encoding/json"
5
        "errors"
6
        "fmt"
7
        "io"
8
        "net/http"
9
        "net/url"
10
        "strings"
11
)
12

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

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

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

×
26
        //nolint:bodyclose
×
27
        // it is closed on the caller
×
28
        res, err := http.Get(apiURL) //nolint: gosec,noctx
×
29
        if err != nil {
×
30
                return nil, fmt.Errorf("unable to get url: %w", err)
×
31
        }
×
32

33
        body, err := io.ReadAll(res.Body)
×
34
        if err != nil {
×
35
                return nil, fmt.Errorf("unable to read http response body: %w", err)
×
36
        }
×
37

38
        var result readme
×
39
        if err := json.Unmarshal(body, &result); err != nil {
×
40
                return nil, fmt.Errorf("unable to parse json: %w", err)
×
UNCOV
41
        }
×
42

43
        if res.StatusCode == http.StatusOK {
×
44
                //nolint:bodyclose
×
45
                // it is closed on the caller
×
UNCOV
46
                resp, err := http.Get(result.DownloadURL) //nolint: noctx
×
47
                if err != nil {
×
48
                        return nil, fmt.Errorf("unable to get url: %w", err)
×
49
                }
×
50

51
                if resp.StatusCode == http.StatusOK {
×
52
                        return &source{resp.Body, result.DownloadURL}, nil
×
53
                }
×
54
        }
55

56
        return nil, errors.New("can't find README in GitHub repository")
×
57
}
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