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

charmbracelet / glow / 12170723754

05 Dec 2024 12:18AM UTC coverage: 7.739% (-2.8%) from 10.556%
12170723754

Pull #661

github

bashbunni
wip: got errors?
Pull Request #661: test: skip networked tests if no connection

1 of 4 new or added lines in 2 files covered. (25.0%)

56 existing lines in 2 files now uncovered.

152 of 1964 relevant lines covered (7.74%)

1.48 hits per line

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

69.44
/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.
14
func findGitHubREADME(u *url.URL) (*source, error) {
3✔
15
        owner, repo, ok := strings.Cut(strings.TrimPrefix(u.Path, "/"), "/")
3✔
16
        if !ok {
3✔
17
                return nil, fmt.Errorf("invalid url: %s", u.String())
×
18
        }
×
19

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

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

3✔
26
        // nolint:bodyclose
3✔
27
        // it is closed on the caller
3✔
28
        res, err := http.Get(apiURL) // nolint: gosec
3✔
29
        if err != nil {
3✔
30
                return nil, err
×
31
        }
×
32

33
        body, err := io.ReadAll(res.Body)
3✔
34
        if err != nil {
3✔
35
                return nil, err
×
36
        }
×
37

38
        var result readme
3✔
39
        if err := json.Unmarshal(body, &result); err != nil {
3✔
40
                return nil, err
×
41
        }
×
42

43
        if res.StatusCode == http.StatusOK {
6✔
44
                // nolint:bodyclose
3✔
45
                // it is closed on the caller
3✔
46
                resp, err := http.Get(result.DownloadURL)
3✔
47
                if err != nil {
3✔
48
                        return nil, err
×
49
                }
×
50

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

NEW
56
        return nil, errors.New(fmt.Sprintf("status code %d - err %T - can't find README in GitHub repository", res.StatusCode, err))
×
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

© 2025 Coveralls, Inc