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

charmbracelet / glow / 9781289187

03 Jul 2024 04:09PM UTC coverage: 10.177% (+0.04%) from 10.134%
9781289187

push

github

web-flow
fix: check other possible readme paths/branches (#450)

* fix: check other possible readme paths/branches

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: url

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: Readme.md

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

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

190 of 1867 relevant lines covered (10.18%)

4.65 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 {
18✔
35
                        v := *u
14✔
36
                        v.Path += fmt.Sprintf("/%s/%s", b, r)
14✔
37

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

45
                        if resp.StatusCode == http.StatusOK {
16✔
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