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

charmbracelet / glow / 12171251530

05 Dec 2024 01:06AM UTC coverage: 10.556%. Remained the same
12171251530

Pull #661

github

bashbunni
fix: return if a valid URL is generated
Pull Request #661: test: skip networked tests if no connection

3 of 5 new or added lines in 3 files covered. (60.0%)

207 of 1961 relevant lines covered (10.56%)

1.62 hits per line

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

0.0
/gitlab.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
// findGitLabREADME tries to find the correct README filename in a repository using GitLab API.
14
func findGitLabREADME(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

20
        projectPath := url.QueryEscape(owner + "/" + repo)
×
21

×
22
        type readme struct {
×
23
                ReadmeURL string `json:"readme_url"`
×
24
        }
×
25

×
26
        apiURL := fmt.Sprintf("https://%s/api/v4/projects/%s", u.Hostname(), projectPath)
×
27

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

35
        body, err := io.ReadAll(res.Body)
×
36
        if err != nil {
×
37
                return nil, err
×
38
        }
×
39

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

45
        readmeRawURL := strings.Replace(result.ReadmeURL, "blob", "raw", -1)
×
46

×
47
        if res.StatusCode == http.StatusOK {
×
48
                // nolint:bodyclose
×
49
                // it is closed on the caller
×
50
                resp, err := http.Get(readmeRawURL) // nolint: gosec
×
51
                if err != nil {
×
52
                        return nil, err
×
53
                }
×
54

55
                if resp.StatusCode == http.StatusOK {
×
56
                        return &source{resp.Body, readmeRawURL}, nil
×
57
                }
×
58
        }
59

NEW
60
        return nil, errors.New(fmt.Sprintf("Can't find README in GitLab repository. Response status: %d %s", res.StatusCode, res.Status))
×
61
}
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