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

charmbracelet / glow / 3998633508

24 Jan 2023 05:09PM UTC coverage: 6.664% (+0.03%) from 6.633%
3998633508

Pull #450

github

Carlos A Becker
fix: url
Pull Request #450: fix: check other possible readme paths/branches

28 of 28 new or added lines in 2 files covered. (100.0%)

186 of 2791 relevant lines covered (6.66%)

3.22 hits per line

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

83.87
/github.go
1
package main
2

3
import (
4
        "errors"
5
        "fmt"
6
        "net/http"
7
        "net/url"
8
        "strings"
9
)
10

11
// isGitHubURL tests a string to determine if it is a well-structured GitHub URL.
12
func isGitHubURL(s string) (string, bool) {
4✔
13
        if strings.HasPrefix(s, "github.com/") {
5✔
14
                s = "https://" + s
1✔
15
        }
1✔
16

17
        u, err := url.ParseRequestURI(s)
4✔
18
        if err != nil {
6✔
19
                return "", false
2✔
20
        }
2✔
21

22
        return u.String(), strings.ToLower(u.Host) == "github.com"
2✔
23
}
24

25
// findGitHubREADME tries to find the correct README filename in a repository.
26
func findGitHubREADME(s string) (*source, error) {
2✔
27
        u, err := url.ParseRequestURI(s)
2✔
28
        if err != nil {
2✔
29
                return nil, err
×
30
        }
×
31
        u.Host = "raw.githubusercontent.com"
2✔
32

2✔
33
        for _, b := range readmeBranches {
6✔
34
                for _, r := range readmeNames {
14✔
35
                        v := *u
10✔
36
                        v.Path += fmt.Sprintf("/%s/%s", b, r)
10✔
37

10✔
38
                        // nolint:bodyclose
10✔
39
                        // it is closed on the caller
10✔
40
                        resp, err := http.Get(v.String())
10✔
41
                        if err != nil {
10✔
42
                                return nil, err
×
43
                        }
×
44

45
                        if resp.StatusCode == http.StatusOK {
12✔
46
                                return &source{resp.Body, v.String()}, nil
2✔
47
                        }
2✔
48
                }
49
        }
50

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