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

AntonKosov / git-backups / 17028037918

18 Aug 2025 12:44AM UTC coverage: 84.649% (+34.6%) from 50.0%
17028037918

Pull #46

github

18fccd
web-flow
Merge 3f29d8802 into a3885294e
Pull Request #46: Added ability to communicate with Github

38 of 46 new or added lines in 1 file covered. (82.61%)

15 existing lines in 1 file now uncovered.

193 of 228 relevant lines covered (84.65%)

0.97 hits per line

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

82.61
/internal/github/reader.go
1
package github
2

3
import (
4
        "context"
5
        "encoding/json"
6
        "fmt"
7
        "io"
8
        "iter"
9
        "net/http"
10
)
11

12
const (
13
        pageSize = 100
14
)
15

16
type Repo struct {
17
        Name     string
18
        Owner    string
19
        CloneURL string
20
}
21

22
type jsonRepo struct {
23
        Name  string `json:"name"`
24
        Owner struct {
25
                Login string `json:"login"`
26
        } `json:"owner"`
27
        CloneURL string `json:"clone_url"`
28
}
29

30
func AllRepos(ctx context.Context, token, affiliation string) iter.Seq2[Repo, error] {
1✔
31
        return func(yield func(Repo, error) bool) {
2✔
32
                for page := 1; ; page++ {
2✔
33
                        repos, err := readPage(ctx, affiliation, token, page)
1✔
34

1✔
35
                        if err != nil {
2✔
36
                                yield(Repo{}, err)
1✔
37
                                return
1✔
38
                        }
1✔
39

40
                        for _, repo := range repos {
2✔
41
                                if !yield(Repo{Name: repo.Name, Owner: repo.Owner.Login, CloneURL: repo.CloneURL}, nil) {
1✔
NEW
42
                                        return
×
NEW
43
                                }
×
44
                        }
45

46
                        if len(repos) == 0 {
2✔
47
                                return
1✔
48
                        }
1✔
49
                }
50
        }
51
}
52

53
func readPage(ctx context.Context, affiliation string, token string, page int) ([]jsonRepo, error) {
1✔
54
        client := http.Client{}
1✔
55
        url := fmt.Sprintf("https://api.github.com/user/repos?affiliation=%v&per_page=%v&page=%v", affiliation, pageSize, page)
1✔
56
        req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
1✔
57
        if err != nil {
1✔
NEW
58
                return nil, err
×
NEW
59
        }
×
60

61
        req.Header.Add("Accept", "application/json")
1✔
62
        req.Header.Add("Authorization", fmt.Sprintf("Bearer %v", token))
1✔
63

1✔
64
        res, err := client.Do(req)
1✔
65
        if err != nil {
1✔
NEW
66
                return nil, err
×
NEW
67
        }
×
68
        defer res.Body.Close()
1✔
69

1✔
70
        return unmarshal(res)
1✔
71
}
72

73
func unmarshal(res *http.Response) ([]jsonRepo, error) {
1✔
74
        if res.StatusCode != http.StatusOK {
2✔
75
                return nil, fmt.Errorf("unexpected status code: %v (%v)", res.StatusCode, res.Status)
1✔
76
        }
1✔
77

78
        body, err := io.ReadAll(res.Body)
1✔
79
        if err != nil {
1✔
NEW
80
                return nil, err
×
NEW
81
        }
×
82

83
        readRepos := []jsonRepo{}
1✔
84
        if err = json.Unmarshal(body, &readRepos); err != nil {
2✔
85
                return nil, err
1✔
86
        }
1✔
87

88
        return readRepos, nil
1✔
89
}
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