MCPcopy Create free account
hub / github.com/cli/cli / getCommits

Function getCommits

pkg/cmd/repo/garden/http.go:17–79  ·  view source on GitHub ↗
(client *http.Client, repo ghrepo.Interface, maxCommits int)

Source from the content-addressed store, hash-verified

15)
16
17func getCommits(client *http.Client, repo ghrepo.Interface, maxCommits int) ([]*Commit, error) {
18 type Item struct {
19 Author struct {
20 Login string
21 }
22 Sha string
23 }
24
25 type Result []Item
26
27 commits := []*Commit{}
28
29 pathF := func(page int) (*safeurl.MutableSafeURL, error) {
30 u, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "commits")
31 if err != nil {
32 return nil, err
33 }
34 u.SetQuery("per_page", "100")
35 u.SetQuery("page", strconv.Itoa(page))
36 return u, nil
37 }
38
39 page := 1
40 paginating := true
41 for paginating {
42 if len(commits) >= maxCommits {
43 break
44 }
45 result := Result{}
46 path, err := pathF(page)
47 if err != nil {
48 return nil, err
49 }
50 links, err := getResponse(client, path, &result)
51 if err != nil {
52 return nil, err
53 }
54 for _, r := range result {
55 colorFunc := shaToColorFunc(r.Sha)
56 handle := r.Author.Login
57 if handle == "" {
58 handle = "a mysterious stranger"
59 }
60 commits = append(commits, &Commit{
61 Handle: handle,
62 Sha: r.Sha,
63 Char: colorFunc(string(handle[0])),
64 })
65 }
66 if len(links) == 0 || !strings.Contains(links[0], "last") {
67 paginating = false
68 }
69 page++
70 time.Sleep(500)
71 }
72
73 // reverse to get older commits first
74 for i, j := 0, len(commits)-1; i < j; i, j = i+1, j-1 {

Callers 1

gardenRunFunction · 0.85

Calls 10

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
getResponseFunction · 0.85
shaToColorFuncFunction · 0.85
colorFuncFuncType · 0.85
SetQueryMethod · 0.80
ContainsMethod · 0.80
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by

no test coverage detected